Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TestingBot for e2e

CI License

Run your e2e tests on TestingBot: hosted Chrome and Edge for web targets, and real iOS and Android devices, iOS simulators and Android emulators for mobile targets. You don't need a local browser, a Mac, Xcode or the Android SDK.

Your tests stay the same. Only the target's browser or device changes:

engine: web({ browser: testingbotBrowsers() })                                          // web
engine: mobile({ platform: 'android', device: testingbot({ device: 'Pixel 8', osVersion: '14', app: './app.apk' }) }) // mobile
Export From What it is
testingbotBrowsers() @testingbot/e2e/web A browser provider: one TestingBot Chrome or Edge session per worker, attached over CDP.
testingbot() @testingbot/e2e A device provider: one TestingBot device per worker, driven through TestingBot's Appium hub.

Requires Node.js 22.22.3 or newer on 22.x, or 24.8.0 or newer (the same as e2e).

Contents

Authenticate

Set TESTINGBOT_KEY and TESTINGBOT_SECRET in the environment e2e run starts in, for example as CI secrets. Copy them from your TestingBot account. TB_KEY and TB_SECRET work too. With neither pair set, the providers read ~/.testingbot (key:secret, the file TestingBot's tunnel and CLI write).

export TESTINGBOT_KEY=...
export TESTINGBOT_SECRET=...

Without credentials, the lease fails before any test starts, and the error names the variables that are missing. Credentials never appear in a log line or an error message.

Web tests in Chrome and Edge

Each worker slot gets its own Chrome or Edge session for the whole run. Every attempt gets a new browser context in that session, so a test never sees another test's cookies, storage or permissions.

npm install --save-dev e2e @e2e-dev/web @testingbot/e2e
import type { E2EConfig } from 'e2e';
import { web } from '@e2e-dev/web';
import { testingbotBrowsers } from '@testingbot/e2e/web';

export default {
  targets: [
    {
      name: 'chrome',
      engine: web({ browser: testingbotBrowsers(), viewport: null }),
      app: { url: 'https://staging.example.com' },
    },
    {
      name: 'edge',
      engine: web({
        browser: testingbotBrowsers({ browserName: 'edge', capabilities: { platform: 'WIN10' } }),
        viewport: null,
      }),
      app: { url: 'https://staging.example.com' },
    },
  ],
} satisfies E2EConfig;
import { test, expect } from 'e2e';

test('home page loads', async ({ app, screen }) => {
  await app.open('/');
  await expect(screen.getByRole('link', { name: 'Learn more' })).toBeVisible();
});
npx e2e run

Browser options

Option Default Meaning
browserName 'chrome' 'chrome' or 'edge'. The web engine attaches over CDP, so Firefox and Safari fail the config.
capabilities none browserVersion and platform, sent next to browserName, plus any tb:options field: screen-resolution, timeZone, geoCountryCode, tunnelIdentifier, screenrecorder, public, extra, ...

Unless capabilities sets them, the provider sends:

  • browserVersion: 'latest' and platform: 'WIN11';
  • build: the run id;
  • an idle timeout of 600 seconds and a maxduration of 7200 seconds.

A worker's session stays open for the whole run, so TestingBot's defaults (90 seconds idle, 300 seconds in all) would end it during a longer suite.

The provider sets key, secret and name itself, so capabilities that set any of them fail the config with INVALID_CONFIG. So do:

  • a nested tb:options;
  • a browserName (use the option instead);
  • a value JSON can't carry;
  • a misspelled option.

Any other key goes to TestingBot unchecked.

testingbotBrowsers({
  browserName: 'edge',
  capabilities: {
    browserVersion: 'latest-1',
    platform: 'WIN10',
    build: `checkout ${process.env.GITHUB_SHA}`,
    tunnelIdentifier: 'ci',
  },
})

Mobile tests on devices

Each worker slot leases one device when the run starts and releases it when the run ends.

npm install --save-dev e2e @e2e-dev/mobile @testingbot/e2e
import type { E2EConfig } from 'e2e';
import { mobile } from '@e2e-dev/mobile';
import { testingbot } from '@testingbot/e2e';

export default {
  targets: [
    {
      name: 'android-emulator',
      engine: mobile({
        platform: 'android',
        device: testingbot({ device: 'Pixel 8', osVersion: '14', app: './builds/app.apk' }),
      }),
      app: { bundleId: 'com.example.app' },
    },
    {
      name: 'ios-real',
      engine: mobile({
        platform: 'ios',
        device: testingbot({ device: 'iPhone 16', osVersion: '26.5', app: 'tb://your-app-id', deviceType: 'real' }),
      }),
      app: { bundleId: 'com.example.app' },
    },
  ],
  workers: 1,
} satisfies E2EConfig;
import { test } from '@e2e-dev/mobile';
import { expect } from 'e2e';

test('adds two numbers', async ({ app, screen }) => {
  await app.open();
  await screen.getByRole('textbox', { name: 'inputA' }).fill('10');
  await screen.getByRole('textbox', { name: 'inputB' }).fill('5');
  await expect(screen.getByRole('textbox', { name: 'sum' })).toHaveValue('15');
});

app is the build TestingBot installs on every session. It can be one of three things:

  • a tb:// app URL from TestingBot Storage;
  • a public https URL;
  • a local path, resolved against the directory of e2e.config.ts. It is uploaded to TestingBot Storage once per run, and every slot and target that uses the same file shares the upload.

Use an .apk or .aab on Android, a zipped .app on an iOS simulator, and a signed .ipa on a real iOS device. Leave the target's app.appPath out, and keep app.bundleId for app.open().

Device options

Option Default Meaning
device required Device name as TestingBot lists it ('iPhone 16', 'Galaxy S24'), or a pattern ('Pixel.*').
osVersion required OS version as TestingBot lists it for that device ('14', '26.5').
app required A tb:// app URL, an https URL, or a local path.
deviceType 'virtual' 'virtual' for a simulator or emulator, 'real' for a real device.
build the run id Dashboard build the sessions are grouped under.
sessionName e2e-<run id>-<target>-<slot> Session name on the dashboard. With more than one worker slot, -<slot> is appended.
orientation the device's 'portrait' or 'landscape'.
geoLocation none Country code the device's traffic geolocates to ('US', 'DE', '*' for random).
timezone the device's Time zone name ('Europe/Brussels').
language the device's Language code ('fr').
locale the device's Locale ('fr_CA').
appiumVersion TestingBot's Appium version for the session ('latest').

An unknown option or an invalid value fails the config load with INVALID_CONFIG. The device list shows which devices and OS versions exist.

Every device session also gets an idle timeout of 900 seconds and a maxduration of 7200 seconds. A device stays leased while other targets lease theirs and between test files, and TestingBot's defaults (120 seconds idle, 30 minutes in all) would end it there.

Find sessions on the dashboard

Each session is named e2e-<run id>-<target>-<slot> and grouped in a build named after the run id. Open the build on the TestingBot dashboard to watch its video and read its logs and commands. The attempt videos in the e2e report are the engine's own recordings: the page screencast in a browser, and agent-device's screen recording on a device.

Limits

  • Parallel sessions. A run holds every browser and device it leased until it ends. Keep workers × the number of TestingBot targets in one run within your plan's parallel sessions. If a run leases more, the extra session waits in TestingBot's queue for a slot only the same run can free. On a device target, it fails after agent-device's 5-minute lease window with a hint that names the parallel limit. On a two-session plan, run targets in pairs: npx e2e run --target android-emulator --target android-real.
  • Busy devices. A real device that another user or the previous session's cleanup holds for more than 5 minutes fails the lease the same way. Pick another device or OS version, or a pattern.
  • Device sessions run while leased. A device session starts when its slot is leased and ends when the run releases it, even when no test runs on it.
  • Stopped runner. If the runner is killed before it releases a session, TestingBot's idle timeout (900 seconds on devices, 600 in browsers) ends it.
  • Unconfirmed release fails the run. If agent-device can't confirm it ended a device session, the run fails, even when every test passed.
  • Real-device latency. Real devices answer some WebDriver calls slowly enough to miss agent-device's budget for a single step now and then (ENGINE_FAILURE ... timed out). Set retries: 1 on suites that run on real devices.
  • No pass/fail status on the dashboard. Sessions are not marked passed or failed, since one session serves every test of its worker. The e2e run output and report have the results.
  • Tunnels and port reverse. agent-device port reverse is not available on devices. Browser targets reach private hosts through TestingBot Tunnel with capabilities: { tunnelIdentifier }.
  • 60-second browser connect. The web engine waits at most 60 seconds for a browser session to accept the CDP connection. A session still queued after that fails with LAUNCH_TIMEOUT.
  • Dropped browser connections. A browser session can't be resumed, so a dropped connection fails the attempt.
  • Browser downloads. Downloads stay on TestingBot's machines, so browser.waitForDownload fails with ENGINE_FAILURE. Assert on the download link or the request instead.

How it works

  • Web. testingbotBrowsers() hands the web engine a CDP endpoint, wss://cloud.testingbot.com/puppeteer?capabilities=…. The engine attaches with Playwright's connectOverCDP. Connecting starts the TestingBot session, and closing the connection ends it.

  • Mobile. testingbot() starts one agent-device daemon per lease, with the TestingBot plugin in agent-device-plugin/ registered in the daemon's home. The plugin points agent-device at TestingBot's Appium hub (https://hub.testingbot.com/wd/hub). It builds the W3C capabilities: appium:* for the device and app, and tb:options for name, build, realDevice and the timeouts. agent-device creates the session and drives the device over WebDriver.

  • Plugin version. The plugin's version must equal the agent-device version that @e2e-dev/mobile pins. Bump it with every @e2e-dev/mobile upgrade; a unit test fails until you do. The plugin also works with agent-device on its own:

    agent-device connect testingbot --session demo --platform android \
      --device "Pixel 8" --provider-os-version 14 --provider-app tb://your-app-id

Develop

npm install
npm test            # unit tests
npm run typecheck
npm run build       # dist/

Live tests against TestingBot

examples/web and examples/mobile are working suites:

  • examples/web runs against example.com in Chrome and Edge.
  • examples/mobile runs TestingBot's sample calculator app on four devices: an Android emulator, an Android phone, an iOS simulator and an iPhone.

The live harness runs them against production. It groups targets to fit the plan's parallel sessions, then checks through the TestingBot API that each target ran in its own completed session, with the documented name and build:

npm run build
npm run test:live              # web, then mobile
npm run test:live -- --web     # browsers only
npm run test:live -- --mobile  # devices only

TESTINGBOT_PARALLEL (default 2) sets how many targets one run holds at once. The traces of each run are kept in e2e-results/.

CI runs the unit tests on every push and pull request. When the repository has the TESTINGBOT_KEY and TESTINGBOT_SECRET secrets, it also runs the live harness on main, nightly, and on demand.

Release

Releases publish to npm from GitHub Actions (release.yml) through trusted publishing: npm accepts the workflow's OIDC token, so no npm token is stored anywhere, and every version carries a provenance statement linking it to the commit it was built from.

npm version 0.2.0 --no-git-tag-version   # or patch / minor / major
git commit -am "Release 0.2.0" && git push
gh release create v0.2.0 --generate-notes

The workflow checks that the tag is v plus the package.json version, runs the build and the unit tests, and publishes. A release marked as a prerelease (--prerelease, for a version such as 0.2.0-beta.1) goes to the next dist-tag.

License

Apache-2.0

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages