AutomateBrowserPlaywright
First test in JavaScript
A complete Playwright test in Node.js you can copy, run, and watch on a real browser.
One file. Copy it, put your access key in, run it, and watch it happen in your dashboard.
What you need
Node 18 or newer, and Playwright itself:
npm install playwrightNothing of ours to install. This is the ordinary Playwright library.
The whole test
// first-test.js
const { chromium } = require("playwright");
const { randomUUID } = require("crypto");
const ACCESS_KEY = "xyz_your_access_key_here";
const TEST_NAME = "example.com opens";
const capabilities = {
browserName: "chrome",
browserVersion: "latest",
"testkase:options": {
accessKey: ACCESS_KEY,
platformName: "windows 11",
name: TEST_NAME,
build: "first-test",
runId: randomUUID(),
recording: true,
},
};
(async () => {
const browser = await chromium.connect(
`wss://hub.testkase.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`,
);
const page = await browser.newPage();
await page.goto("https://example.com");
const title = await page.title();
if (!title.includes("Example Domain")) {
throw new Error(`wrong title: ${title}`);
}
console.log(" title:", title);
await browser.close();
console.log("PASS ", TEST_NAME);
})();What each part does
Six things carry the whole file. Read down the middle column and you have its shape.
| The part | What it does | |
|---|---|---|
| 1 | wss://hub.testkase.com/playwright?capabilities=… | Where everything goes. Playwright has no capability argument, so the whole object is URL-encoded onto the connect address. |
| 2 | accessKey | Signs you in. Copy it from the Access key page. There is no username here — the key is the only credential. |
| 3 | platformName | Which operating system. Set it. Leave it out and Chrome, Edge and Firefox fall back to linux, which no machine of ours runs, so the session is refused. |
| 4 | recording: true | Says what to keep. name is how you will recognise the session in a list; recording is the video, and you get none unless you ask. Every option. |
| 5 | chromium.connect(...) | Ordinary Playwright from here on. Every command behaves exactly as it does locally — we only carry it to the browser and back. You call chromium.connect whichever brand you asked for; the address decides what you get. |
| 6 | browser.close() | Ends the session and frees the machine. Forget it and the session runs until a timeout stops it — which you are paying for. |
Run it
node first-test.jsThe browser opens on our machines, not yours. Open your dashboard while it runs and the session is there live; when it ends, the video is on it.
