Basic Example

Here's a simple example of how to use Chekov to automate a login flow:

1
import { ai } from '@chekov/core';
2
import { chromium } from 'playwright';
3
4
async function testLoginFlow() {
5
const browser = await chromium.launch();
6
const page = await browser.newPage();
7
8
try {
9
await ai([
10
'Navigate to http://example.com/login',
11
'Type "testuser" into the username field',
12
'Type "password123" into the password field',
13
'Click the Login button',
14
'Verify that we are redirected to the dashboard'
15
], { page });
16
17
console.log('✅ Login test passed!');
18
} finally {
19
await browser.close();
20
}
21
}
22
23
testLoginFlow().catch(console.error);

Breaking it Down

Let's look at what's happening in this example:

  1. We import the ai function from @chekov/core and set up a Playwright browser.
  2. We use natural language prompts to describe what we want to test.
  3. Chekov automatically:
    • Finds the right elements on the page
    • Performs the requested actions
    • Verifies the results
  4. If any step fails, Chekov will throw an error with a helpful message.

Using Environment Variables

You'll need to set up your API key before running the tests:

1
export CHEKOV_API_KEY=your_api_key_here

Or create a .env file:

1
CHEKOV_API_KEY=your_api_key_here