Golem: Premení JSON scenáre na spustiteľné Playwright testy
Golem: Premení JSON scenáre na spustiteľné Playwright testy
Máte vygenerované testovacie scenáre v JSON formáte. A teraz čo? Niekto ich musí prepísať do Playwright. Alebo Cypress. Alebo Robot Framework. Manuálne.
{
"action": "fill",
"selector": "[data-testid=\"input-email\"]",
"value": "john@example.com"
}Toto treba prepísať na:
page.locator("[data-testid=\"input-email\"]").fill("john@example.com")Pre 100 scenárov s 500 krokmi? To sú hodiny nudnej práce.
Golem tento problém rieši: automaticky generuje spustiteľný testovací kód z JSON scenárov.
Problém: Od scenára k testu
Scout a Sentinel generujú scenáre v JSON formáte:
{
"name": "Successful login",
"steps": [
{"action": "fill", "selector": "[data-testid='input-email']", "value": "user@test.com"},
{"action": "fill", "selector": "[data-testid='input-password']", "value": "secret123"},
{"action": "click", "selector": "[data-testid='btn-login']"},
{"action": "verify_visible", "selector": "[data-testid='dashboard']"}
]
}Ale JSON nie je test. Potrebujete:
- Playwright Python test
- Alebo Cypress TypeScript test
- Alebo Robot Framework test
- Alebo Selenium test
Každý framework má inú syntax:
# Playwright
page.locator("[data-testid='btn-login']").click()
# Selenium
driver.find_element(By.CSS_SELECTOR, "[data-testid='btn-login']").click()
# Robot Framework
Click Element css:[data-testid='btn-login']// Cypress
cy.get("[data-testid='btn-login']").click()Manuálne prepisovanie = strata času.
Riešenie: Golem - Intelligent Test Code Generator
Golem je konvertor scenárov na spustiteľný kód:
JSON Scenáre (Scout/Sentinel)
↓
GOLEM
↓
┌────────┬────────┬────────┬──────────┐
│Playwright│ Cypress │ Robot │ Selenium │
│ Python │ TS │Framework│ Python │
└────────┴────────┴────────┴──────────┘Jeden príkaz = hotové testy
# Vygeneruj Playwright testy z JSON scenárov
python main.py generate scenarios.json -f playwright --base-url http://localhost:4200
# Výstup:
# ✅ Generated 47 test files
# ✅ 156 test cases
# ✅ Saved to: result/tests/A môžete ich ihneď spustiť:
pytest result/tests/ --headedAko Golem funguje?
1. Parsuje scenáre
Golem rozpoznáva dva formáty:
Scout formát (component-based):
{
"components": [
{
"file": "src/app/login/login.component.html",
"url": "/login",
"scenarios": [...]
}
]
}Sentinel formát (URL-based):
{
"pages": [
{
"url": "http://localhost:4200/login",
"scenarios": [...]
}
]
}Golem automaticky detekuje formát - nemusíte nič konfigurovať.
2. Generuje kód
Golem používa Jinja2 templates pre každý framework:
# Interná logika (zjednodušene)
def translate_step(step, framework):
if framework == "playwright":
if step.action == "click":
return f'page.locator("{step.selector}").click()'
elif step.action == "fill":
return f'page.locator("{step.selector}").fill("{step.value}")'
elif framework == "cypress":
if step.action == "click":
return f'cy.get("{step.selector}").click()'
# ...3. Ukladá testy
result/
├── tests/
│ ├── test_login.py
│ ├── test_contact.py
│ ├── test_dashboard.py
│ └── conftest.py
└── pytest.iniPodporované akcie
Golem prekladá 6 typov akcií:
| Akcia | Popis | Playwright | Cypress |
|---|---|---|---|
click | Kliknutie | .click() | .click() |
fill | Vyplnenie inputu | .fill(value) | .type(value) |
submit | Odoslanie formulára | .click() | .submit() |
verify_visible | Overenie viditeľnosti | expect().to_be_visible() | .should('be.visible') |
verify_text | Overenie textu | expect().to_contain_text() | .should('contain') |
navigate | Navigácia | page.goto() | cy.visit() |
Praktický príklad
Vstup: JSON scenár
{
"name": "Successful contact form submission",
"description": "User fills and submits contact form",
"page_url": "/contact",
"steps": [
{
"action": "fill",
"selector": "[data-testid='input-name']",
"value": "John Doe",
"description": "Fill name field"
},
{
"action": "fill",
"selector": "[data-testid='input-email']",
"value": "john@example.com",
"description": "Fill email field"
},
{
"action": "fill",
"selector": "[data-testid='textarea-message']",
"value": "Hello, this is a test message.",
"description": "Fill message field"
},
{
"action": "click",
"selector": "[data-testid='btn-submit']",
"description": "Click submit button"
},
{
"action": "verify_visible",
"selector": "[data-testid='success-toast']",
"description": "Verify success message"
}
]
}Výstup: Playwright Python test
import pytest
from playwright.sync_api import Page, expect
def test_successful_contact_form_submission(page: Page, base_url: str):
"""User fills and submits contact form"""
# Navigate to contact page
page.goto(f"{base_url}/contact")
# Fill name field
page.locator("[data-testid='input-name']").fill("John Doe")
# Fill email field
page.locator("[data-testid='input-email']").fill("john@example.com")
# Fill message field
page.locator("[data-testid='textarea-message']").fill("Hello, this is a test message.")
# Click submit button
page.locator("[data-testid='btn-submit']").click()
# Verify success message
expect(page.locator("[data-testid='success-toast']")).to_be_visible()Alternatíva: Cypress TypeScript test
describe('Contact Form', () => {
it('Successful contact form submission', () => {
// User fills and submits contact form
cy.visit('/contact');
// Fill name field
cy.get("[data-testid='input-name']").type('John Doe');
// Fill email field
cy.get("[data-testid='input-email']").type('john@example.com');
// Fill message field
cy.get("[data-testid='textarea-message']").type('Hello, this is a test message.');
// Click submit button
cy.get("[data-testid='btn-submit']").click();
// Verify success message
cy.get("[data-testid='success-toast']").should('be.visible');
});
});Rovnaký scenár = rôzne frameworky = jeden Golem príkaz.
4 podporované frameworky
1. Playwright (Python)
python main.py generate scenarios.json -f playwright -l python- ✅ Najpopulárnejší moderný framework
- ✅ pytest integrácia
- ✅ Auto-wait, screenshot on failure
- ✅ Multi-browser support
2. Playwright (TypeScript)
python main.py generate scenarios.json -f playwright -l typescript- ✅ Pre TypeScript projekty
- ✅ Native async/await
3. Cypress (TypeScript)
python main.py generate scenarios.json -f cypress- ✅ Populárny v JS ekosystéme
- ✅ BDD-style syntax
- ✅ Real-time browser preview
4. Robot Framework
python main.py generate scenarios.json -f robot- ✅ Keyword-driven testing
- ✅ Readable aj pre ne-programátorov
- ✅ Reporting out of the box
5. Selenium (Python)
python main.py generate scenarios.json -f selenium- ✅ Klasika, funguje všade
- ✅ Najširšia podpora browserov
CLI príkazy
# Generovanie testov
python main.py generate scenarios.json \
--framework playwright \
--language python \
--base-url http://localhost:4200 \
--output ./tests
# Analýza scenárov
python main.py parse scenarios.json -v
# Výstup:
# Total pages: 12
# Total scenarios: 47
# Total steps: 234
# Source format: Scout
# Preview testu (bez uloženia)
python main.py preview scenarios.json --page contact-form
# Spustenie testov
python main.py run ./tests \
--headed \
--browser firefox \
--base-url http://staging.app.comIntegrácie
1. CLI (základné použitie)
python main.py generate scenarios.json -f playwright2. Python Library
from scenario_parser import ScenarioParser
from test_generator import TestGenerator
from test_runner import TestRunner
# Parse
parser = ScenarioParser()
parsed = parser.parse_file("scenarios.json")
print(f"Found {parsed.total_scenarios} scenarios")
# Generate
generator = TestGenerator(framework="playwright", language="python")
generator.generate_from_parsed(parsed, base_url="http://localhost:4200")
generator.save_tests("tests/")
# Run
runner = TestRunner(framework="playwright")
results = runner.run("tests/", headed=True)
print(f"Passed: {results.passed}, Failed: {results.failed}")3. gRPC Server
# Spustite server
python main.py grpc-server --port 50053
# Volania:
# - GenerateTests(scenarios_file, framework, base_url)
# - ParseScenarios(scenarios_file)
# - GetStatus()4. MCP Server (Claude integrácia)
{
"mcpServers": {
"golem": {
"command": "python",
"args": ["main.py", "mcp-server"]
}
}
}V Claude:
"Vygeneruj Playwright testy z mojich Scout scenárov"
→ Claude zavolá golem_generate_testsKompletný QA Toolchain
Golem je posledný kúsok puzzle:
┌─────────────────────────────────────────────────────┐
│ MARKER │
│ Pridá data-testid do komponentov │
└──────────────────────┬──────────────────────────────┘
↓
┌──────────────────────┴──────────────────────────────┐
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ SCOUT │ │ SENTINEL │ │
│ │ (z kódu) │ │ (z UI) │ │
│ │ │ │ │ │
│ │ Statická │ │ Dynamická │ │
│ │ analýza │ │ analýza │ │
│ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │
│ └──────────┬─────────────────┘ │
│ ↓ │
│ JSON Scenáre │
│ │
└────────────────────┬────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────┐
│ GOLEM │
│ JSON → Playwright/Cypress/Robot/Selenium │
└──────────────────────┬──────────────────────────────┘
↓
┌─────────────────────────────────────────────────────┐
│ SPUSTITEĽNÉ TESTY │
│ pytest / cypress run / robot │
└─────────────────────────────────────────────────────┘Praktický end-to-end workflow:
# 1. Marker: Pridaj data-testid
python marker/main.py add --project ./frontend
# 2. Scout: Vygeneruj scenáre z kódu
python scout/main.py generate ./frontend -o scenarios.json
# ALEBO Sentinel: Vygeneruj scenáre z bežiacej app
python sentinel/main.py --url http://localhost:4200 -o scenarios.json
# 3. Golem: Vygeneruj Playwright testy
python golem/main.py generate scenarios.json -f playwright
# 4. Spusti testy
pytest result/tests/ --base-url http://localhost:4200Od zdrojového kódu po spustené testy = 4 príkazy.
Prečo Golem?
1. Framework-agnostické scenáre
Jeden JSON scenár
↓
GOLEM
↓
├── Playwright testy (CI/CD)
├── Cypress testy (FE tím)
├── Robot testy (QA tím)
└── Selenium testy (legacy)Nepíšete testy viackrát - len generujete pre rôzne frameworky.
2. Konzistentná syntax
# Všetky testy majú rovnakú štruktúru
def test_scenario_name(page: Page, base_url: str):
"""Description from scenario"""
page.goto(f"{base_url}/page")
# Steps...
expect(...).to_be_visible()3. Okamžité spustenie
# Generuj a spusti v jednom kroku
python main.py generate scenarios.json -f playwright && \
pytest result/tests/ --headed4. CI/CD ready
# .github/workflows/tests.yml
- name: Generate tests from scenarios
run: python golem/main.py generate scenarios.json -f playwright
- name: Run tests
run: pytest result/tests/ --base-url ${{ env.STAGING_URL }}Konfigurácia
# .env
SCENARIOS_FILE=scenarios.json
OUTPUT_DIR=result
TEST_FRAMEWORK=playwright
TEST_LANGUAGE=python
TEST_BROWSER=chromium
HEADLESS=true
BASE_URL=http://localhost:4200
# Server
GRPC_PORT=50053
# Optional LLM (pre budúce AI vylepšenia)
OLLAMA_HOST=http://localhost:11434
LLM_MODEL=qwen3-coder:30bQuick Start
# 1. Nainštalujte dependencies
pip install playwright pytest pytest-playwright
playwright install chromium
# 2. Máte scenáre? (zo Scout alebo Sentinel)
# Ak nie:
python scout/main.py generate ./frontend -o scenarios.json
# 3. Vygenerujte testy
python main.py generate scenarios.json \
--framework playwright \
--base-url http://localhost:4200
# 4. Spustite testy
pytest result/tests/ --headed
# 5. (Voliteľne) V headless pre CI/CD
pytest result/tests/ --browser chromiumUse Cases
1. Multi-framework organizácia
# QA tím preferuje Robot Framework
python main.py generate scenarios.json -f robot -o qa-tests/
# Developeri preferujú Playwright
python main.py generate scenarios.json -f playwright -o dev-tests/
# Legacy systém používa Selenium
python main.py generate scenarios.json -f selenium -o legacy-tests/2. CI/CD Pipeline
jobs:
test:
steps:
- name: Generate from latest scenarios
run: |
python scout/main.py generate ./src -o scenarios.json
python golem/main.py generate scenarios.json -f playwright
- name: Run tests
run: pytest result/tests/3. Migrácia frameworku
# Staré Selenium testy → nové Playwright testy
# 1. Exportujte scenáre z existujúcich testov (manuálne/scripted)
# 2. Golem vygeneruje nové testy
python main.py generate legacy-scenarios.json -f playwrightZáver
Golem uzatvára QA automation loop:
| Bez Golem | S Golem |
|---|---|
| JSON scenáre → manuálne písanie testov | JSON scenáre → automaticky generované testy |
| Jeden framework = jedna implementácia | Jeden scenár = všetky frameworky |
| Hodiny copy-paste práce | Sekundy generovania |
Kedy použiť Golem:
- ✅ Máte Scout/Sentinel scenáre a potrebujete testy
- ✅ Tím používa rôzne test frameworky
- ✅ CI/CD pipeline potrebuje automatické testy
- ✅ Migrácia medzi test frameworkami
Golem je most medzi scenármi a spustiteľnými testami. Scenáre píše AI (Scout/Sentinel), testy generuje Golem, vy len kontrolujete výsledky.
Golem je súčasť QA automation toolchain: Marker → Scout/Sentinel → Golem → Testy. Všetky nástroje spolupracujú na automatizácii celého QA procesu.