Skip to content

Your First Test

Quick start with init

The fastest way to get started is using vanya init:

Terminal window
# Create a browser test template
vanya init todo_app.vanya --template browser
# Or create an API test template
vanya init api_test.vanya --template api

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

Terminal window
vanya check todo_app.vanya

If everything is correct, you’ll see:

todo_app.vanya: OK

Build the test

Transpile to Python:

Terminal window
vanya build todo_app.vanya -o out/ --format pytest-function

This 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

FormatDescriptionUse Case
rawPlain Python codeCustom test runners
pytest-functionWrapped in def test_...()pytest integration

Run the generated test

Step 1: Install test dependencies

Terminal window
pip install pytest playwright pytest-playwright

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

Terminal window
# Linux/macOS - installs system dependencies for Chromium
sudo playwright install-deps chromium

Step 3: Download browser binaries

Terminal window
playwright install chromium

Step 4: Run the test

Terminal window
pytest out/test_todo_app.py -v

Expected 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