Skip to main content

Keeping state

When e2e testing a platform, most of the tests will require some sort of authentication.

Lila integrates natively with Playwright session storage. This means you can:

  • Run Lila tests loading a Playwright browser state
  • Output a Playwright browser state from a Lila test.
tip

This feature allow Playwright and Lila to coexist in the same testing suite.

Setting browser state

lila run accepts a --browser-state parameter where you can point to a browser session JSON file

For example:

lila run user-tests/ --tags login-required --browser-state user.json

Outputting browser state

lila run login.yaml --output-dir lila-artifacts/

This will generate a file lila-artifacts/login.json you can use fow downstream tests.

important

The JSON file name will be the same as the test file name. It will also keep hierarchy. For example if the test is login.yaml, then the state will be <output-dir>/login.json. If the test is admin/login.yaml then the state will be <output-dir>/admin/login.json

Real example

Lets assume I have the following tests:

tests
├─── user
│ └─── search.yaml
│ └─── article-creation.yaml
│ └─── dashboard.yaml
└─── login.yaml

All tests under user/ requires an authenticated session, which can be obtained by running the login test and reusing its state.

Then,

# 1. We run the login state only and save its output
lila run login.yaml --output-dir artifacts/

# 2. We set the browser state to run the auth tests
lila run user/ --browser-state artifacts/login.json