Basic Example
Here's a simple example of how to use Chekov to automate a login flow:
1import { ai } from '@chekov/core';2import { chromium } from 'playwright';34async function testLoginFlow() {5const browser = await chromium.launch();6const page = await browser.newPage();78try {9await 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 });1617console.log('✅ Login test passed!');18} finally {19await browser.close();20}21}2223testLoginFlow().catch(console.error);
Breaking it Down
Let's look at what's happening in this example:
- We import the
aifunction from@chekov/coreand set up a Playwright browser. - We use natural language prompts to describe what we want to test.
- Chekov automatically:
- Finds the right elements on the page
- Performs the requested actions
- Verifies the results
- 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:
1export CHEKOV_API_KEY=your_api_key_here
Or create a .env file:
1CHEKOV_API_KEY=your_api_key_here
