Obsah článku / Contents
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.

json
{
  "action": "fill",
  "selector": "[data-testid=\"input-email\"]",
  "value": "john@example.com"
}

Toto treba prepísať na:

python
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:

json
{
  "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:

python
# 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']
typescript
// 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

bash
# 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ť:

bash
pytest result/tests/ --headed

Ako Golem funguje?

1. Parsuje scenáre

Golem rozpoznáva dva formáty:

Scout formát (component-based):

json
{
  "components": [
    {
      "file": "src/app/login/login.component.html",
      "url": "/login",
      "scenarios": [...]
    }
  ]
}

Sentinel formát (URL-based):

json
{
  "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:

python
# 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.ini

Podporované akcie

Golem prekladá 6 typov akcií:

AkciaPopisPlaywrightCypress
clickKliknutie.click().click()
fillVyplnenie inputu.fill(value).type(value)
submitOdoslanie formulára.click().submit()
verify_visibleOverenie viditeľnostiexpect().to_be_visible().should('be.visible')
verify_textOverenie textuexpect().to_contain_text().should('contain')
navigateNavigáciapage.goto()cy.visit()

Praktický príklad

Vstup: JSON scenár

json
{
  "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

python
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

typescript
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)

bash
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)

bash
python main.py generate scenarios.json -f playwright -l typescript
  • ✅ Pre TypeScript projekty
  • ✅ Native async/await

3. Cypress (TypeScript)

bash
python main.py generate scenarios.json -f cypress
  • ✅ Populárny v JS ekosystéme
  • ✅ BDD-style syntax
  • ✅ Real-time browser preview

4. Robot Framework

bash
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)

bash
python main.py generate scenarios.json -f selenium
  • ✅ Klasika, funguje všade
  • ✅ Najširšia podpora browserov

CLI príkazy

bash
# 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.com

Integrácie

1. CLI (základné použitie)

bash
python main.py generate scenarios.json -f playwright

2. Python Library

python
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

bash
# 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)

json
{
  "mcpServers": {
    "golem": {
      "command": "python",
      "args": ["main.py", "mcp-server"]
    }
  }
}

V Claude:

"Vygeneruj Playwright testy z mojich Scout scenárov"
→ Claude zavolá golem_generate_tests

Kompletný 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:

bash
# 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:4200

Od 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

python
# 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

bash
# Generuj a spusti v jednom kroku
python main.py generate scenarios.json -f playwright && \
pytest result/tests/ --headed

4. CI/CD ready

yaml
# .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
# .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:30b

Quick Start

bash
# 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 chromium

Use Cases

1. Multi-framework organizácia

bash
# 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

yaml
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

bash
# 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 playwright

Záver

Golem uzatvára QA automation loop:

Bez GolemS Golem
JSON scenáre → manuálne písanie testovJSON scenáre → automaticky generované testy
Jeden framework = jedna implementáciaJeden scenár = všetky frameworky
Hodiny copy-paste práceSekundy 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.

Všetky články