Skip to content

Scenarios

Vanya tests are organized into scenarios, each representing an independent test case. This is the recommended way to write tests as it keeps related test cases together with shared setup.

Multi-Scenario Files

Group related tests in a single file using Scenario: blocks. A shared Setup for each Scenario: block runs before each scenario.

Vanya test scenario (vanya-lang.org/v0.1)
Script title: "login_suite"
Setup for each Scenario:
Within the Browser (plugin: playwright-python, type: browser, url: 'http://localhost:3000')
go to "/login"
Scenario: "successful login"
type "user@example.com" into input (testid: 'email')
type "password123" into input (testid: 'password')
click button (testid: 'submit')
see any heading (text: 'Welcome')
Scenario: "invalid password"
type "user@example.com" into input (testid: 'email')
type "wrongpassword" into input (testid: 'password')
click button (testid: 'submit')
see any text (text: 'Invalid credentials')
Scenario: "empty form"
click button (testid: 'submit')
see any text (text: 'Email is required')

Generated Output

Each scenario generates a separate test function. The setup is included in each:

def test_login_suite_successful_login(page):
ctx = page
ctx.goto("/login")
ctx.locator("[data-testid='email']").fill("user@example.com")
ctx.locator("[data-testid='password']").fill("password123")
ctx.locator("[data-testid='submit']").click()
expect(ctx.get_by_role("heading", name="Welcome")).to_be_visible()
def test_login_suite_invalid_password(page):
ctx = page
ctx.goto("/login")
ctx.locator("[data-testid='email']").fill("user@example.com")
ctx.locator("[data-testid='password']").fill("wrongpassword")
ctx.locator("[data-testid='submit']").click()
expect(ctx.locator("text", has_text="Invalid credentials")).to_be_visible()
def test_login_suite_empty_form(page):
ctx = page
ctx.goto("/login")
ctx.locator("[data-testid='submit']").click()
expect(ctx.locator("text", has_text="Email is required")).to_be_visible()

Structure

Setup for each Scenario

The setup block is optional but recommended. It contains statements that run before each scenario:

Setup for each Scenario:
Within the Browser (plugin: playwright-python, type: browser, url: 'http://example.com')
go to "/app"
# login, navigate, or set up test state

The setup block must contain a Within block that establishes the plugin context. Scenario actions inherit this context.

Scenario blocks

Each scenario has a name (in quotes) and contains actions:

Scenario: "descriptive test name"
action one
action two
assertion

Scenario names are converted to snake_case and combined with the script title to form the test function name:

  • Script title: "login_suite" + Scenario: "successful login"test_login_suite_successful_login

When to Use Single-Scenario Syntax

Use single-scenario syntax when:

  • Tests are independent with completely different setups
  • You have a one-off utility script
  • You prefer one test per file for clarity

Single-Scenario Syntax

Both formats are supported for backward compatibility.

Single-scenario syntax:

Script title: "simple_test"
Within the Browser (plugin: playwright-python, type: browser)
go to "/home"
click button

Multi-scenario:

Script title: "test_suite"
Setup for each Scenario:
Within the Browser (plugin: playwright-python, type: browser)
go to "/home"
Scenario: "test one"
click button
Scenario: "test two"
click link

Best Practices

  1. Use descriptive scenario names - They become part of the test function name and appear in test reports
  2. Keep setup focused - Only include steps that genuinely need to run before every scenario
  3. One assertion focus per scenario - When possible, keep scenarios focused on testing one behavior
  4. Group related scenarios - Put tests for the same feature in one file (e.g., login_tests.vanya, checkout_flow.vanya)