### HTML Setup for waitUntil Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/waitUntil.mdx
Example HTML structure used to demonstrate text change detection.
```javascript
I am some text
```
--------------------------------
### HTML Setup for waitUntil Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/waitUntil.mdx
HTML structure used to demonstrate the text change condition.
```html
I am some text
```
--------------------------------
### Implement dev server startup in INIT
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/testplane-events.mdx
Example of starting a dev server within the INIT event handler, ensuring it only runs in the master process.
```javascript
const http = require("http");
const parseConfig = require("./config");
module.exports = (testplane, opts) => {
const pluginConfig = parseConfig(opts);
if (!pluginConfig.enabled || testplane.isWorker()) {
// either the plugin is disabled, or we are in the worker context – exit
return;
}
// ...
testplane.on(testplane.events.INIT, () => {
// content served by the dev-server
const content = "
Hello, World!
";
// create a server and start listening on port 3000
http.createServer((req, res) => res.end(content)).listen(3000);
// at http://localhost:3000/index.html it will serve:
Hello, World!
});
};
```
--------------------------------
### HTML Setup for Selection Testing
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/isSelected.mdx
Example HTML structure containing a select element with pre-selected options.
```html
```
--------------------------------
### Example System Configuration
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/config/system.mdx
This is an example of how to configure the 'system' section in Testplane.
```javascript
{
system: {
debug: true,
mochaOpts: {
timeout: 60000,
},
ctx: {
user: 'test',
},
patternsOnReject: [
/some pattern/,
],
workers: 4,
testsPerWorker: 10,
diffColor: '#ff00ff',
parallelLimit: 5,
fileExtensions: [
'.js',
'.mjs',
],
testRunEnv: ['nodejs', 'browser'],
},
}
```
--------------------------------
### Example: Saving a Screen Recording
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/saveRecordingScreen.mdx
Demonstrates the workflow of starting a recording, performing an action, and saving the resulting video file.
```javascript
it("should save a video", async ({ browser }) => {
await browser.startRecordingScreen();
await browser.$("~BUTTON").click();
await browser.saveRecordingScreen("./some/path/video.mp4");
});
```
--------------------------------
### HTML Setup for Visibility Testing
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/isDisplayed.mdx
Example HTML elements with various CSS properties that affect visibility.
```html
```
--------------------------------
### Install Testplane and Plugin
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/visual-testing-with-storybook.mdx
Commands to initialize Testplane and install the Storybook integration plugin.
```bash
npm init testplane@latest
```
```bash
npm install @testplane/storybook --save-dev
```
--------------------------------
### Install Testplane CLI
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/quickstart/index.mdx
Use this command to install the Testplane CLI and initialize your project. Specify your project path as an argument.
```bash
npm init testplane@latest YOUR_PROJECT_PATH
```
--------------------------------
### Run Testplane Tests
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/quickstart/index.mdx
Execute this command to run the tests in your project after installation and setup.
```bash
npx testplane
```
--------------------------------
### Install Testplane Skill
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/ai/toolkit/testplane-skill.mdx
Use this command to install Testplane Skill via the skills.sh setup wizard. This command is compatible with various AI agent harnesses.
```shell
npx skills add gemini-testing/testplane-skill
```
--------------------------------
### HTML setup for doubleClick test
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/doubleClick.mdx
Example HTML structure containing a button with an ondblclick event handler.
```html
I was not clicked
```
--------------------------------
### Throttle network usage examples
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/throttle.mdx
Examples demonstrating how to apply a network preset and how to manually configure specific network parameters.
```javascript
it("should throttle the network", async ({ browser }) => {
// use a preset
await browser.throttle("Regular 3G");
// configure the network settings manually
await browser.throttle({
offline: false,
downloadThroughput: (200 * 1024) / 8,
uploadThroughput: (200 * 1024) / 8,
latency: 20,
});
});
```
--------------------------------
### Complete Testplane CI Workflow
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/guides/how-to-run-on-github.mdx
A full example workflow integrating installation, test execution, report deployment, and PR notification.
```yml
name: Testplane CI
on: # Workflow trigger rules
push:
branches: [master]
pull_request:
branches: [master]
jobs:
testplane_test:
runs-on: ubuntu-latest
permissions:
contents: write # Required to deploy reports to gh-pages
pull-requests: write # Required to post report links in PR comments
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install npm deps
run: npm install
- name: Run Testplane
id: testplane
uses: gemini-testing/gh-actions-testplane@v1
with:
html-report-prefix: testplane-reports # Report directory path
- name: Deploy report # Deploys report to gh-pages
if: always() && steps.testplane.outputs.html-report-path
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ steps.testplane.outputs.html-report-path }}
destination_dir: ${{ steps.testplane.outputs.html-report-path }}
keep_files: true
- name: Comment PR with link to Testplane HTML report
if: always() && steps.testplane.outputs.html-report-path
uses: thollander/actions-comment-pull-request@v3
with:
message: |
### Testplane run finished
Testplane HTML report is available at https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.testplane.outputs.html-report-path }}
comment-tag: testplane_html_report_link
```
--------------------------------
### Installation
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/hermione-browser-version-changer.mdx
Install the browser-version-changer plugin as a development dependency.
```APIDOC
## Install
```bash
npm install -D @testplane/browser-version-changer
```
```
--------------------------------
### Usage Examples
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/reactDollar.mdx
Illustrative examples demonstrating how to use the react$ command in various scenarios, such as interacting with calculator components.
```APIDOC
## Usage Examples
```javascript
it("should calculate 7 * 6", async ({ browser }) => {
await browser.url("https://ahfarmer.github.io/calculator/");
const appWrapper = await browser.$("div#root");
await appWrapper
.react$("t", {
props: { name: "7" },
})
.click();
await appWrapper
.react$("t", {
props: { name: "x" },
})
.click();
await appWrapper
.react$("t", {
props: { name: "6" },
})
.click();
await appWrapper
.react$("t", {
props: { name: "=" },
})
.click();
console.log(await browser.$(".component-display").getText()); // outputs: "42"
});
```
```
--------------------------------
### Install @testplane/testing-library
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/guides/how-to-add-testing-library.mdx
Install the adapter package as a development dependency using npm.
```bash
npm i -D @testplane/testing-library
```
--------------------------------
### Install stat-reporter
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/stat-reporter.mdx
Command to install the plugin as a development dependency.
```bash
npm install -D stat-reporter
```
--------------------------------
### Example: Using getMeta with setMeta
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/getMeta.mdx
This example demonstrates setting metadata using setMeta and then retrieving it with getMeta, both for a specific key and for all metadata. It also shows retrieving the URL metadata.
```javascript
it("should get meta info of test", async ({ browser }) => {
await browser.setMeta("foo", "bar");
await browser.url("/foo/bar?baz=qux");
const val = await browser.getMeta("foo");
console.log(val); // outputs: bar
const url = await browser.getMeta("url");
console.log(url); // outputs: /foo/bar?baz=qux
const meta = await browser.getMeta();
console.log(meta); // outputs: {foo: 'bar', url: '/foo/bar?baz=qux'}
});
```
--------------------------------
### Install @testplane/storybook
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/testplane-storybook.mdx
Install the plugin as a development dependency.
```bash
npm install @testplane/storybook --save-dev
```
--------------------------------
### Basic Navigation and Snapshot
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/ai/toolkit/testplane-cli.mdx
Start a simple browser session by navigating to a URL and taking a snapshot of the page. The CLI automatically starts a browser if one is not already running.
```shell
npx @testplane/cli navigate https://example.com
npx @testplane/cli snapshot
```
--------------------------------
### Install @testplane/url-decorator
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/url-decorator.mdx
Install the plugin as a development dependency.
```bash
npm install -D @testplane/url-decorator
```
--------------------------------
### Install Testplane via Command Panel
Source: https://github.com/gemini-testing/testplane-docs/blob/master/i18n/en/docusaurus-plugin-content-blog/vscode-extension.mdx
Execute this command in the VS Code command palette after installing the extension to initialize Testplane in an empty project.
```text
Install Testplane
```
--------------------------------
### Element Selection Examples
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/$$.mdx
Examples showing how to retrieve elements using standard selectors and JS functions.
```javascript
it("should get text of a menu link", async ({ browser }) => {
const text = await browser.$("#menu");
console.log(await text.$$("li")[2].$("a").getText()); // outputs: "API"
});
it("should get text of a menu link - JS Function", async ({ browser }) => {
const text = await browser.$("#menu");
console.log(
await text
.$$(function () {
// Arrow function cannot be used here.
// This is Element – https://developer.mozilla.org/en-US/docs/Web/API/Element
// in this specific example – this is HTMLUListElement
//
// TypeScript users can do something like:
// return (this as Element).querySelector('li')
return this.querySelectorAll("li"); // Element[]
})[2]
.$("a")
.getText(),
); // outputs: "API"
});
```
--------------------------------
### Install @testplane/test-repeater
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/testplane-test-repeater.mdx
Install the plugin as a development dependency using npm.
```bash
npm install -D @testplane/test-repeater
```
--------------------------------
### Install @testplane/retry-command
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/testplane-retry-command.mdx
Install the plugin as a development dependency using npm.
```bash
npm install -D @testplane/retry-command
```
--------------------------------
### Install Testplane and Dependencies
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/component-testing.mdx
Installs Testplane and necessary development dependencies including Vite, React plugin for Vite, and @testing-library/react. Also installs React as a regular dependency.
```bash
npm init testplane@latest
npm i vite @vitejs/plugin-react @testing-library/react --save-dev
npm i react --save
```
--------------------------------
### Install @testplane/retry-progressive
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/testplane-retry-progressive.mdx
Install the plugin as a development dependency using npm.
```bash
npm install -D @testplane/retry-progressive
```
--------------------------------
### Install html-reporter
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/html-reporter/overview.mdx
Install the html-reporter package as a development dependency using npm.
```shell
npm i -D html-reporter
```
--------------------------------
### Install All Browser Dependencies
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/browsers-overview.mdx
Use `npx testplane install-deps` to download all browsers and drivers specified in your Testplane configuration that support automatic installation.
```bash
npx testplane install-deps
```
--------------------------------
### Install @testplane/browser-version-changer
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/hermione-browser-version-changer.mdx
Install the browser version changer plugin as a development dependency.
```bash
npm install -D @testplane/browser-version-changer
```
--------------------------------
### Comprehensive Testplane CI Configuration Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/guides/how-to-run-on-github.mdx
An advanced example showcasing the use of all available parameters for the Testplane GitHub Action, allowing for fine-grained control over test execution.
```APIDOC
## Comprehensive Testplane CI Configuration Example
### Description
This example demonstrates how to utilize all the configurable parameters of the `gemini-testing/gh-actions-testplane@v1` action to customize your Testplane test runs. It covers specifying the working directory, package manager, report prefix, custom configuration path, Storybook plugin usage, test sets, browsers, and grep expressions.
### Method
N/A (This is a workflow configuration, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Action Parameters
- **cwd** (string) - Optional - Relative directory to run Testplane from (useful for monorepos). Example: `"projects/my-project-name"`
- **package-manager** (string) - Optional - Package manager used in the project (one of: `npm`, `pnpm`, `yarn`). Example: `"yarn"`
- **html-report-prefix** (string) - Optional - Path prefix for HTML reporter reports. Example: `"reports/testplane"`
- **config-path** (string) - Optional - Path to custom Testplane config. Example: `"configs/testplane.conf.js"`
- **storybook** (string) - Optional - Enable to use @testplane/storybook plugin tests. Example: `"true"`
- **set** (string) - Optional - List of test sets (comma-separated). Example: `"smoke,regression"`
- **browser** (string) - Optional - List of browsers for testing (comma-separated). Example: `"linux-chrome,linux-firefox"`
- **grep** (string) - Optional - Grep expression to select specific tests. Example: `"Login"`
### Request Example
```yaml
- name: Run Comprehensive Testplane Suite
id: testplane
uses: gemini-testing/gh-actions-testplane@v1
with:
cwd: "projects/my-project-name"
package-manager: "yarn"
html-report-prefix: "reports/testplane"
config-path: "configs/testplane.conf.js"
storybook: "true"
set: "smoke,regression"
browser: "linux-chrome,linux-firefox"
grep: "Login"
```
### Response
N/A (This is a workflow configuration)
```
--------------------------------
### Install Specific Browser Versions
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/browsers-overview.mdx
Specify exact versions when installing browser and driver dependencies.
```bash
npx testplane install-deps chrome@130 firefox@104
```
--------------------------------
### Testplane CLI Navigation Output Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/i18n/en/docusaurus-plugin-content-blog/cli-and-skill.mdx
Example output from a Testplane CLI navigation command, showing the navigated URL and browser tab information.
```text
Successfully navigated to https://example.com
## Testplane Code
await browser.openAndWait("https://example.com");
## Browser Tabs
1. Title: Example Domain; URL: https://example.com/ (current)
## Current Tab Snapshot
The snapshot was saved to: /tmp/.testplane/snapshots/2026-05-14T21-24-40-811Z.yml
```
--------------------------------
### Testplane CLI Snapshot Output Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/i18n/en/docusaurus-plugin-content-blog/cli-and-skill.mdx
Example output from a Testplane CLI snapshot command, displaying the captured page structure in a text-first format.
```text
Page snapshot captured successfully
## Current Tab Snapshot
- body:
- div:
- h1 "Example Domain"
- p "This domain is for use in documentation examples without needing permission. Avoid use in operations..."
- p:
- a[href=https://iana.org/domains/example] "Learn more"
```
--------------------------------
### Start Selenoid Docker Container
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/browsers-overview.mdx
This command starts the Selenoid Docker container, mounting the necessary Docker socket and configuration directory. The `--network=host` option is often used for simpler network configurations.
```bash
docker run --rm -d \
--name selenoid \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/selenoid-config:/etc/selenoid/:ro \
--network=host \
aerokube/selenoid:latest
```
--------------------------------
### Install html-reporter Plugin
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/configuration.mdx
Install the html-reporter plugin using npm. This is the first step to enable HTML test report generation.
```bash
npm install html-reporter --save-dev
```
--------------------------------
### React Component Interaction Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/reactDollar.mdx
Example demonstrating how to locate and interact with React components on a calculator application.
```javascript
it("should calculate 7 * 6", async ({ browser }) => {
await browser.url("https://ahfarmer.github.io/calculator/");
const appWrapper = await browser.$("div#root");
await appWrapper
.react$("t", {
props: { name: "7" },
})
.click();
await appWrapper
.react$("t", {
props: { name: "x" },
})
.click();
await appWrapper
.react$("t", {
props: { name: "6" },
})
.click();
await appWrapper
.react$("t", {
props: { name: "=" },
})
.click();
console.log(await browser.$(".component-display").getText()); // outputs: "42"
});
```
--------------------------------
### Get Parent Element
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/parentElement.mdx
Use the `parentElement` command to get the parent element of the selected DOM element. This example demonstrates retrieving the class attribute of the parent element.
```javascript
await browser.$(selector).parentElement();
```
```html
Sibling One
Sibling Two
Sibling Three
```
```javascript
it("should get class from parent element", async ({ browser }) => {
const elem = await browser.$$("p");
const parent = await elem[2].parentElement();
console.log(await parent.getAttribute("class")); // outputs: "parent"
});
```
--------------------------------
### Install Testplane and HTML Reporter
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/time-travel.mdx
Install the required versions of Testplane and the HTML reporter to enable Time Travel functionality.
```shell
npm i -D testplane@latest html-reporter@latest
```
--------------------------------
### Example Test Suite Structure
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/parallelism.mdx
An example of a project structure with multiple test files, each containing a large number of tests.
```text
project/
├── .testplane.conf.js
├── package.json
└── tests/
├── registration.testplane.js # 500 tests
├── payment.testplane.js # 500 tests
└── auth.testplane.js # 500 tests
```
--------------------------------
### Install Latest Testplane and html-reporter
Source: https://github.com/gemini-testing/testplane-docs/blob/master/i18n/en/docusaurus-plugin-content-blog/time-travel-release.mdx
Install the latest versions of Testplane and html-reporter to access new features. This command is used for development dependencies.
```shell
npm i -D testplane@8.29.2 html-reporter@10.18.0
```
--------------------------------
### Display Testplane Help
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/cli.mdx
View the full list of available CLI options and usage instructions.
```bash
> testplane --help
Usage: testplane [options] [command] [paths...]
Run tests
Options:
-V, --version output the version number
-c, --config path to configuration file
-b, --browser run tests only in specified browser
-s, --set run tests only in the specified set
-r, --require require module
--grep run only tests matching the pattern
--tag run only tests with specified tags
--reporter test reporters
--update-refs update screenshot references or gather them if they do not exist ("assertView" command)
--inspect [inspect] nodejs inspector on [=[host:]port]
--inspect-brk [inspect-brk] nodejs inspector with break at the start
--repl [type] run one test, call `browser.switchToRepl` in test code to open repl interface (default: false)
--repl-before-test [type] open repl interface before test run (default: false)
--repl-on-fail [type] open repl interface on test fail only (default: false)
--devtools switches the browser to the devtools mode with using CDP protocol
--local use automatically downloaded browsers and drivers, provided by Testplane
--keep-browser do not close browser session after test completion
--keep-browser-on-fail do not close browser session when test fails
-h, --help output usage information
```
--------------------------------
### Implement GitHub App installation token authentication in TypeScript
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/html-reporter/static-accepter.mdx
Uses Octokit and simple-git to clone a repository, update files, and push changes using an installation access token. Ensure the App has 'Contents: Read & Write' and 'Pull requests: Read' permissions.
```ts
// server.ts
import express from "express";
import multer from "multer";
import path from "path";
import os from "os";
import fs from "fs/promises";
import { randomUUID } from "crypto";
import simpleGit from "simple-git";
import { Octokit } from "octokit";
import { createAppAuth } from "@octokit/auth-app";
const upload = multer({ storage: multer.memoryStorage() });
const appId = process.env.GITHUB_APP_ID!;
const privateKey = process.env.GITHUB_APP_PRIVATE_KEY!; // PEM string
const app = express();
app.post("/static-accepter", upload.any(), async (req, res) => {
const repositoryUrl = req.body.repositoryUrl as string;
const pullRequestUrl = req.body.pullRequestUrl as string;
const message = (req.body.message as string) || "chore: update baselines";
if (!repositoryUrl || !pullRequestUrl) {
res.status(400).send("Missing repositoryUrl or pullRequestUrl");
return;
}
if (!req.files?.length) {
res.status(400).send("No images provided");
return;
}
const { owner, repo } = parseRepository(repositoryUrl);
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: { appId, privateKey },
});
const installation = await appOctokit.rest.apps.getRepoInstallation({ owner, repo });
const installationOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId,
privateKey,
installationId: installation.data.id,
},
});
const prNumber = extractPullNumber(pullRequestUrl);
const { data: pull } = await installationOctokit.rest.pulls.get({
owner,
repo,
pull_number: prNumber,
});
const branch = pull.head.ref;
const tokenResponse = await installationOctokit.rest.apps.createInstallationAccessToken({
installation_id: installation.data.id,
});
const remote = `https://x-access-token:${tokenResponse.data.token}@github.com/${owner}/${repo}.git`;
const worktree = await fs.mkdtemp(path.join(os.tmpdir(), `accepter-${randomUUID()}-`));
const git = simpleGit();
try {
await git.clone(remote, worktree, ["--single-branch", "--branch", branch]);
const branchGit = simpleGit(worktree);
for (const file of req.files as Express.Multer.File[]) {
const destination = path.join(worktree, file.originalname);
await fs.mkdir(path.dirname(destination), { recursive: true });
await fs.writeFile(destination, file.buffer);
}
await branchGit.add(".");
await branchGit.commit(message);
await branchGit.push("origin", branch);
res.status(204).end();
} catch (err) {
console.error(err);
res.status(500).send("Failed to update pull request");
} finally {
await fs.rm(worktree, { recursive: true, force: true });
}
});
function parseRepository(repositoryUrl: string) {
const match = repositoryUrl.match(/github\.com\/(.+?)\/(.+?)(\.git)?$/);
if (!match) {
throw new Error(`Unsupported repository URL: ${repositoryUrl}`);
}
return { owner: match[1], repo: match[2] };
}
function extractPullNumber(pullRequestUrl: string) {
const match = pullRequestUrl.match(/pull\/(\d+)/);
if (!match) {
throw new Error(`Unsupported pull request URL: ${pullRequestUrl}`);
}
return Number(match[1]);
}
const port = process.env.PORT ?? 3000;
app.listen(port, () => {
console.log(`Static accepter listening on :${port}`);
});
```
--------------------------------
### Start Node.js with Inspector
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/debugging-tests.mdx
Enable V8 inspector integration by passing the --inspect option when starting a Node.js application. Use --inspect-brk to stop execution at the first line.
```bash
node --inspect index.js
```
```bash
node --inspect=9222 index.js
```
```bash
node --inspect-brk index.js
```
--------------------------------
### Run Local Development Server
Source: https://github.com/gemini-testing/testplane-docs/blob/master/README.md
Starts a local development server for live preview of changes. Changes are reflected without server restarts.
```shell
npm start
```
--------------------------------
### Get Text of a Menu Link using CSS Selector
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/$.mdx
This example shows how to retrieve the text of a menu link by chaining `$$` and `$` commands with a CSS selector.
```javascript
it("should get text of a menu link", async ({ browser }) => {
const text = await browser.$("#menu");
console.log(await text.$$("li")[2].$("a").getText()); // outputs: "API"
});
```
--------------------------------
### Basic newWindow Usage
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/newWindow.mdx
This example demonstrates the basic usage of the newWindow command to open a new tab with a specified URL, name, and features. It also shows how to switch back and close the new window.
```javascript
it("should open a new tab", async ({ browser }) => {
await browser.url("http://google.com");
console.log(await browser.getTitle());
// outputs: "Google"
await browser.newWindow(
"https://webdriver.io",
"WebdriverIO window",
"width=420,height=230,resizable,scrollbars=yes,status=1",
);
console.log(await browser.getTitle());
// outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
await browser.closeWindow();
console.log(await browser.getTitle());
// outputs: "Google"
});
```
--------------------------------
### Example browsers configuration
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/cli.mdx
A sample browsers section for the Testplane configuration file.
```json
{
"my-chrome": { "desiredCapabilities": { "browserName": "chrome", "browserVersion": "130.0" } },
"my-safari": { "desiredCapabilities": { "browserName": "safari" } }
}
```
--------------------------------
### Get Text of a Menu Link using $$
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/$$.mdx
This example demonstrates how to use the $$ command to select a specific menu item and retrieve the text of its anchor tag. It chains $$ and $ commands to navigate the DOM.
```html
```
```javascript
it("should get text of a menu link", async ({ browser }) => {
const text = await browser.$$("#menu")[0];
console.log(await text.$$("li")[2].$("a").getText()); // outputs: "API"
});
```
--------------------------------
### GitHub Actions CI Workflow
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/quickstart/usage-in-ci.mdx
Example GitHub Actions workflow file to run Testplane tests. It checks out code, sets up Node.js, installs dependencies, and uses the Testplane GitHub Action.
```yaml
name: Testplane Tests
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- run: npm ci
- uses: gemini-testing/gh-actions-testplane@v1
with:
browser: "chrome,firefox" # Optional: list of browsers
```
--------------------------------
### Switching windows in a test
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/switchWindow.mdx
Example demonstrating how to open a new window and switch back to a previous one using URL and title matching.
```javascript
it("should switch to another window", async ({ browser }) => {
// open URL
await browser.url("https://google.com");
// create a new window
await browser.newWindow("https://webdriver.io");
// switch back by matching the URL
await browser.switchWindow("google.com");
// switch again by matching the page title
await browser.switchWindow("Next-gen browser and mobile automation test framework for Node.js");
});
```
--------------------------------
### Check Testplane Version
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/cli.mdx
Print the currently installed version of Testplane.
```bash
testplane --version
```
--------------------------------
### Create Thunk Action for Requests
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/html-reporter/html-reporter-plugins.mdx
Use thunk actions for handling asynchronous operations like data fetching. This example dispatches loading and loaded actions, and makes an HTTP GET request.
```typescript
export const fetchData = (resultId: string) => async dispatch => {
dispatch({ type: actions.LOADING, payload: { resultId } });
const endpoint = `${pluginOptions.pluginServerEndpointPrefix}/data`;
const { data } = await axios.get(endpoint);
dispatch({ type: actions.LOADED, payload: { resultId, data } });
};
```
--------------------------------
### Get help for list-browsers
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/cli.mdx
Displays help information for the list-browsers command.
```bash
> npx testplane list-browsers --help
Usage: list-browsers [options]
Lists all browsers from the config
Options:
--type [type] return browsers in specified type ('tags': browserName and browserVersion, 'ids': browserId from config) (default: tags)
--format [format] return browsers in specified format ('json' / 'plain') (default: json)
-h, --help output usage information
```
--------------------------------
### Launch Testplane GUI
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/quickstart/index.mdx
Start a local server to view the interactive HTML report in your browser after tests have finished.
```bash
npx testplane gui
```
--------------------------------
### Get text content from a table cell
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/getText.mdx
This example demonstrates how to navigate through table rows and columns to extract text from a specific cell. It involves selecting rows and then columns within a specific row.
```javascript
it("get content from table cell", async ({ browser }) => {
await browser.url("http://the-internet.herokuapp.com/tables");
const rows = await browser.$$("#table1 tr");
const columns = await rows[1].$$("td"); // get columns of the 2nd row
console.log(await columns[2].getText()); // get text from the 3rd column
});
```
--------------------------------
### Launch Browser with Custom Viewport
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/ai/toolkit/testplane-cli.mdx
Use the `launch` command to start a visible browser with a specified window size. This is useful for testing responsive designs.
```shell
npx @testplane/cli launch --headless false --window-size '{"width":1280,"height":720}'
```
--------------------------------
### Get Text of a Menu Link using $$ with JS Function
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/$$.mdx
This example shows how to use a JavaScript function with the $$ command to select elements. Note that arrow functions cannot be used here; a traditional function expression is required.
```javascript
it("should get text of a menu link - JS Function", async ({ browser }) => {
const text = await browser.$$(function () {
// Arrow function cannot be used here.
// This is Window – https://developer.mozilla.org/en-US/docs/Web/API/Window
//
// TypeScript users can do something like:
// return (this as Window).document.querySelectorAll('#menu')
return this.document.querySelectorAll("#menu"); // Element[]
})[0];
console.log(await text.$$("li")[2].$("a").getText()); // outputs: "API"
});
```
--------------------------------
### Implement Testplane Plugin Logic
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/config/_partials/examples/_plugins-example.mdx
Implement the plugin's functionality by subscribing to Testplane events. This example shows how to access plugin options and use `RUNNER_START` and `RUNNER_END` events. Ensure `setUp` and `tearDown` functions are defined elsewhere.
```typescript
exports = function (testplane, opts) {
testplane.on(testplane.events.RUNNER_START, function (runner) {
console.info(opts.param); // some-value
return setUp(testplane.config, opts.param);
});
testplane.on(testplane.events.RUNNER_END, function () {
return tearDown();
});
};
```
--------------------------------
### Launch Testplane GUI
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/time-travel.mdx
Start the Testplane GUI to view the snapshot player and browser streaming during test runs.
```shell
npx html-reporter gui
```
--------------------------------
### Configure beforeAll Hook in Testplane
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/config/before-all.mdx
Use the beforeAll hook to perform setup actions before tests begin. This example demonstrates launching a browser, navigating to a URL, performing login actions, saving the browser state, and then closing the browser session.
```typescript
import { launchBrowser } from "testplane/unstable";
export default {
// ...
browsers: {
chrome: {
headless: true,
desiredCapabilities: {
webSocketUrl: true,
browserName: "chrome",
},
},
firefox: {
headless: true,
desiredCapabilities: {
webSocketUrl: true,
browserName: "firefox",
},
},
},
beforeAll: async () => {
// launch a new browser with existing config
const browser = await launchBrowser(this.config.browsers.chrome);
await browser.url("https://example.com");
// do login things, type username/password etc.
// save dump with state (cookies, localStorage) for using in tests
await browser.saveState({
path: "./dump.json",
});
await browser.deleteSession();
},
};
```
--------------------------------
### Get Text of a Menu Link using JS Function Selector
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/$.mdx
This example demonstrates selecting a menu item using a JavaScript function as a selector within chained `$$` and `$` commands. Ensure to use a traditional function expression, not an arrow function, for `this` context.
```javascript
it("should get text of a menu link - JS Function", async ({ browser }) => {
const text = await browser.$("#menu");
console.log(
await text
.$$("li")[2]
.$(function () {
// Arrow function cannot be used here.
// This is Element – https://developer.mozilla.org/en-US/docs/Web/API/Element
// in this specific example – this is HTMLLIElement
//
// TypeScript users can do something like:
// return (this as Element).querySelector('a')
return this.querySelector("a"); // Element
})
.getText()
); // outputs: "API"
});
```
--------------------------------
### Implement and use a custom command
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/addCommand.mdx
Example showing how to define a custom command that returns browser data and how to invoke it within a test.
```javascript
// add the getUrlAndTitle command
browser.addCommand("getUrlAndTitle", async function (customParam) {
return {
url: await this.getUrl(), // `this` here and below refers to the "browser" object
title: await this.getTitle(),
customParam: customParam,
};
});
// use the new getUrlAndTitle command
it("should use my add command", async ({ browser }) => {
await browser.url("https://testplane.io");
const result = await browser.getUrlAndTitle("foobar");
assert.strictEqual(result.url, "https://testplane.io");
assert.strictEqual(result.title, "Testplane Docs | Testplane Docs");
assert.strictEqual(result.customParam, "foobar");
});
```
--------------------------------
### Demonstrate respondOnce Sequential Mocking
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/mock/respondOnce.mdx
Example showing how to queue multiple responses for a network request using respondOnce.
```javascript
async function getToDos(browser) {
await browser.$("#todo-list li").waitForExist();
const todoElements = await browser.$$ ("#todo-list li");
return Promise.all(todoElements.map(el => el.getText()));
}
it("should demonstrate the respondOnce command", async ({ browser }) => {
const mock = await browser.mock("https://todo-backend-express-knex.herokuapp.com/", {
method: "get",
});
mock.respondOnce([
{
title: "3",
},
{
title: "2",
},
{
title: "1",
},
]);
mock.respondOnce([
{
title: "2",
},
{
title: "1",
},
]);
mock.respondOnce([
{
title: "1",
},
]);
await browser.url(
"https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/",
);
console.log(await getToDos(browser)); // outputs: [ '3', '2', '1' ]
await browser.url(
"https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/",
);
console.log(await getToDos(browser)); // outputs: [ '2', '1' ]
await browser.url(
"https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/",
);
console.log(await getToDos(browser)); // outputs: [ '1' ]
await browser.url(
"https://todobackend.com/client/index.html?https://todo-backend-express-knex.herokuapp.com/",
);
console.log(await getToDos(browser)); // outputs: the actual resource response
});
```
--------------------------------
### Example Test File: registration.testplane.js
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/parallelism.mdx
A sample test file demonstrating the structure for a large number of tests.
```javascript
// registration.testplane.js
describe("Registration", () => {
it("test 1 - empty email shows an error", async ({ browser }) => {});
it("test 2 - invalid email format", async ({ browser }) => {});
it("test 3 - empty password shows an error", async ({ browser }) => {});
// ...
// test 500
});
```
--------------------------------
### Display Testplane Configuration Help
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/cli.mdx
Use this command to view detailed help information for the 'config' command, including its usage and available options.
```bash
> npx testplane config --help
Usage: config [options]
Outputs Testplane config (including default and overriden by environment variables values)
Options:
-c, --config path to configuration file
--space white spaces count to insert into the JSON output (default: 0)
-h, --help output usage information
```
--------------------------------
### Basic openAndWait configuration
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/openAndWait.mdx
Demonstrates the structure of the openAndWait command with various waiting parameters.
```javascript
await browser.openAndWait("some/url", {
selector: [".some", ".selector"],
predicate: () => document.isReady,
ignoreNetworkErrorsPatterns: ["https://mc.yandex.ru", "https://avatars.mds.yandex.net/*"],
waitNetworkIdle: true,
waitNetworkIdleTimeout: 500,
failOnNetworkError: true,
timeout: 20000,
});
```
--------------------------------
### Run Tests with Custom Options
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/cli.mdx
Example of executing tests with a specific configuration, reporter, browser, and grep pattern.
```bash
npx testplane --config ./config.js --reporter flat --browser firefox --grep name
```
--------------------------------
### Launch Browser Instance
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/testplane-standalone-api.mdx
Use this to start a new browser instance with specified settings. Remember to terminate the session to prevent resource leaks.
```typescript
import { launchBrowser } from "testplane/unstable";
// Launch a new browser with the given settings
const browser = await launchBrowser({
desiredCapabilities: {
browserName: "chrome",
},
headless: false,
});
// Navigate to the URL and perform necessary actions
await browser.url("https://example.com");
// !Important: terminate the session to prevent resource leaks (zombie processes)
await browser.deleteSession();
```
--------------------------------
### Install @testplane/retry-limiter
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/retry-limiter.mdx
Install the retry limiter plugin using npm or yarn.
```APIDOC
## Install @testplane/retry-limiter
```bash
npm install -D @testplane/retry-limiter
```
```
--------------------------------
### Install @testplane/retry-limiter
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/retry-limiter.mdx
Install the retry-limiter plugin as a development dependency using npm.
```bash
npm install -D @testplane/retry-limiter
```
--------------------------------
### getSize Command Implementation Example
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/element/getSize.mdx
Demonstrates retrieving element dimensions using the getSize command with and without specific property arguments.
```javascript
it("should demonstrate the getSize command", async ({ browser }) => {
await browser.url("http://github.com");
const logo = await browser.$(".octicon-mark-github");
const size = await logo.getSize();
console.log(size); // outputs: { width: 32, height: 32 }
const width = await logo.getSize("width");
console.log(width); // outputs: 32
const height = await logo.getSize("height");
console.log(height); // outputs: 32
});
```
--------------------------------
### Manage SUITE_BEGIN event
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/testplane-events.mdx
Handles suite initialization events, supporting both standard subscription and event interception.
```javascript
testplane.on(testplane.events.SUITE_BEGIN, suite => {
console.info(`Processing SUITE_BEGIN event for "${suite.fullTitle()}"...`);
});
```
```javascript
testplane.intercept(testplane.events.SUITE_BEGIN, ({ event, data: suite }) => {
console.info(`Intercepting SUITE_BEGIN event for "${suite.fullTitle()}"...`);
});
```
--------------------------------
### Example Test Sets Configuration
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/config/sets.mdx
Illustrates how to define 'common' and 'desktop' test sets. The 'common' set runs in all browsers, while 'desktop' is limited to Chrome and Firefox.
```javascript
sets: {
common: {
files: "common"
},
desktop: {
files: ["common", "desktop"],
browsers: ["chrome", "firefox"]
}
}
```
--------------------------------
### HTML structure for examples
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/browser/$.mdx
The HTML structure used for the following JavaScript examples.
```html
```
--------------------------------
### Install Testplane CLI
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/ai/toolkit/testplane-cli.mdx
Install the Testplane CLI package as a development dependency in your project.
```shell
npm install --save-dev @testplane/cli
```
--------------------------------
### Install @testplane/chunks Plugin
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/plugins/testplane-chunks.mdx
Install the @testplane/chunks plugin as a development dependency using npm.
```bash
npm install -D @testplane/chunks
```
--------------------------------
### Install Hermione Migration Dependencies
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/migrations/how-to-upgrade-hermione-to-4.mdx
Installs hermione version 4 and necessary migration tools.
```shell
npm install -D hermione@4 hermione-wdio-migrator hermione-codemod --save-exact
```
--------------------------------
### Implement Testplane Dev Server Plugin
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/reference/testplane-events.mdx
Plugin logic using CLI and INIT events to conditionally start a local HTTP server.
```javascript
const http = require("http");
const parseConfig = require("./config");
module.exports = (testplane, opts) => {
const pluginConfig = parseConfig(opts);
if (!pluginConfig.enabled || testplane.isWorker()) {
// either the plugin is disabled, or we are in the worker context – exit
return;
}
let program;
testplane.on(testplane.events.CLI, cli => {
// need to save a reference to the commander instance (https://github.com/tj/commander.js),
// to later check for the option
program = cli;
// add the --dev-server option to testplane,
// so the user can explicitly specify when to start the dev server
cli.option("--dev-server", "run dev-server");
});
testplane.on(testplane.events.INIT, () => {
// the dev server can be started either by specifying the --dev-server option
// when launching testplane, or in the plugin settings
const devServer = (program && program.devServer) || pluginConfig.devServer;
if (!devServer) {
// if the dev server doesn't need to be started – exit
return;
}
// content served by the dev server
const content = "
Hello, World!
";
// create the server and start listening on port 3000
http.createServer((req, res) => res.end(content)).listen(3000);
// at http://localhost:3000/index.html, the content will be:
Hello, World!
});
};
```
--------------------------------
### Install Browser Dependencies
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/quickstart/index.mdx
Run this command to download the browsers specified in your configuration separately from Testplane execution.
```bash
npx testplane install-deps
```
--------------------------------
### Installing tsconfig-paths
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/typescript-esm.mdx
Install the tsconfig-paths package as a development dependency to enable runtime resolution of path aliases.
```bash
npm install --save-dev tsconfig-paths
```
--------------------------------
### Install Specific Browser Dependencies
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/basic-guides/browsers-overview.mdx
Install dependencies for selected browsers by their logical names defined in the configuration.
```bash
npx testplane install-deps chrome-dark
```
--------------------------------
### Demonstrate Restore Command
Source: https://github.com/gemini-testing/testplane-docs/blob/master/docs/commands/mock/restore.mdx
This example shows how to use `mock.restore()` to revert a mock response. Initially, a mock is set to respond with a specific image. After navigating to a URL, `mock.restore()` is called, and navigating to the same URL again shows the original content.
```javascript
it("should demonstrate the addValue command", async ({ browser }) => {
const mock = await browser.mock("**/googlelogo_color_272x92dp.png");
mock.respond("https://webdriver.io/img/webdriverio.png");
await browser.url("https://google.com"); // will show WebdriverIO logo instead of Google logo
mock.restore();
await browser.url("https://google.com"); // will show the native Google logo
});
```