topilot v0.2.0
topilot
Topilot CLI tools
Topilot is a platform for E2E testing at large scale.
Table of Contents
Installation
To install the package, run the following command:
npm install --save-dev topilotGet Started
To use Topilot, follow these steps:
- Register on topilot.dev.
- Create a project.
- Copy the token from the project settings.
- Set the
TOPILOT_TOKENenvironment variable with the copied value. Do this in both:- A local project folder with a
.envfile. - The CI environment.
- A local project folder with a
Features
- automate and reuse fixture by play playwright fixtures
- focus on waht really matters by select key test cases to run in CI/CD pipeline
Usage
Use topilot play to run Playwright fixtures
Fixtures are a core concept in Playwright that provide an encapsulated, reusable, lazy-loaded, and composable way of establishing an environment.
However, fixtures are not runnable on their own, so it can be inconvenient to focus on writing and testing them.
To solve this problem, you can define your fixture in an ES module with setup, teardown, and name exported. Topilot will:
- extend playwright
testobject with the fixture, which combines thesetupandteardownfunction - generate tests for the fixture
setupandteardown
Details:
Create fixtures as ES modules with the extension
.fixture.ts.To create a fixture, create an ES module that exports the following named members:
name: the fixture name used in destructuring params of tests.setup: a function to set up the fixture values.teardown: a function to tear down the fixture values.
For example:
// project.fixture.ts export const name = "project"; export const setup = async ({ page }) => { // create project here // ... const project = { // project info used by other tests }; return { project }; }; export const teardown = async ({ page, project }) => { // teardown for the project // ... return {project: null}; };Both setup and teardown should return the new fixture value, which will be uploaded to Topilot so that this fixture is used in other Playwright tests or manual tests.
Run
topilot playin a terminal, then choose which fixture to play.
Replace Playwright
testwithtopilot.import topilot from 'topilot' topilot('should add an item', async ({ todoPage }) => { await todoPage.addToDo('my item'); // ... });topilotis the Playwright test object with fixtures extended, so you can use any fixtures defined in.fixture.tsfiles.
Select Key Test Cases to Run in CI/CD Pipeline
Here are the steps to follow:
- Use
topilot pushto upload tests within the current branch to Topilot. - Select the key cases in Topilot.
When your Playwright tests are triggered in a CI/CD environment, only the selected key cases will be run. Other cases will be skipped to save time and focus on what really changed and matters.
Typescript
To get typescript not yelling at you with the unknown fixture error, we should extend topilot with module merging.
// my-fixture.fixture.ts
declare module "topilot" {
interface Fixtures {
"myFixture": string
}
}
export const setup = () => {}
export const teardown = () => {}
export const name = "myFixture"License
This package is licensed under the MIT license. See LICENSE for more information.