Your First Test
Quick start with init
The fastest way to get started is using vanya init:
# Create a browser test templatevanya init todo_app.vanya --template browser
# Or create an API test templatevanya init api_test.vanya --template apiThis generates a working example file you can modify for your tests. Or create one manually:
Create a test file
Create a file called todo_app.vanya:
Vanya test scenario (vanya-lang.org/v0.1)
Script title: "todo_app"
Setup for each Scenario: Within the Browser (plugin: playwright-python, type: browser) go to "https://demo.playwright.dev/todomvc/" Define new-todo (class: 'new-todo')
Scenario: "user can add a todo" type "Learn Vanya" into new-todo press Enter see a li (text: 'Learn Vanya')
Scenario: "user can add multiple todos" type "First task" into new-todo press Enter type "Second task" into new-todo press Enter see a li (text: 'First task') see a li (text: 'Second task')Check the syntax
Run the checker to validate your test:
vanya check todo_app.vanyaIf everything is correct, you’ll see:
todo_app.vanya: OKBuild the test
Transpile to Python:
vanya build todo_app.vanya -o out/ --format pytest-functionThis creates out/test_todo_app.py (and out/test_todo_app.py.vanyamap for source mapping) ready to run with pytest. The --format pytest-function flag wraps your test in a proper def test_...() function and adds the test_ prefix for pytest discovery. Each Scenario: block becomes a separate test function.
Output formats
| Format | Description | Use Case |
|---|---|---|
raw | Plain Python code | Custom test runners |
pytest-function | Wrapped in def test_...() | pytest integration |
Run the generated test
Step 1: Install test dependencies
pip install pytest playwright pytest-playwrightStep 2: Install Chromium system libraries
On Linux and macOS, Chromium requires system libraries (libnspr4, libnss3, etc.). This step is required for the test to run:
# Linux/macOS - installs system dependencies for Chromiumsudo playwright install-deps chromiumStep 3: Download browser binaries
playwright install chromiumStep 4: Run the test
pytest out/test_todo_app.py -vExpected output:
============================= test session starts ==============================collected 2 items
out/test_todo_app.py::test_todo_app_user_can_add_a_todo PASSED [ 50%]out/test_todo_app.py::test_todo_app_user_can_add_multiple_todos PASSED [100%]
============================= 2 passed in 4.12s ================================Next steps
- Learn about Scenarios for organizing multiple test cases
- Learn more about vanya syntax
- Explore available plugins
- Read the CLI reference
- Set up CI/CD integration
- See Recipes for patterns like dynamic IDs, URL assertions, and role-based selectors