Skip to content

Commit cf8c49b

Browse files
committed
test: ♻️ refactor web test to use testcontainer
Refactor the existing web test to use testcontainer for playwright. TODO: does not work yet.
1 parent c88069c commit cf8c49b

1 file changed

Lines changed: 43 additions & 10 deletions

File tree

tests/playwright/web.spec.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
1-
import { test, expect } from "@playwright/test";
1+
import { describe, beforeAll, afterAll, test, expect } from "@playwright/test";
2+
import path from "node:path";
3+
import { PlaywrightContainer } from "testcontainers-node-playwright";
4+
const PLAYWRIGHT_IMAGE = "mcr.microsoft.com/playwright:v1.50.1-jammy";
25

3-
test("site is up and running", async ({ page }) => {
4-
// ARRANGE
5-
// nothing to arrange
6+
describe("House of Test website", () => {
7+
const TESTS_PATH = path.resolve(__dirname, "testcontainers-nodejs-example");
8+
let container;
69

7-
// ACT
8-
const response = await page.goto("https://houseoftest.ch/", {
9-
waitUntil: "domcontentloaded",
10+
beforeAll(async () => {
11+
container = await new PlaywrightContainer(PLAYWRIGHT_IMAGE, TESTS_PATH)
12+
// .withExposedPorts(8080)
13+
.start();
14+
15+
// execute the test in the container and report the results in html format
16+
const { output, exitCode } = await container.exec([
17+
"npx", // install Playwright if not installed
18+
"playwright", // connect to Playwright
19+
"test", // run the test
20+
"--reporter=html", // output the test results in HTML
21+
]);
22+
});
23+
24+
afterAll(async () => {
25+
await container.stop();
1026
});
1127

12-
// ASSERT
13-
expect(response.status()).toBe(200);
14-
await expect(page.getByRole("heading", { name: "Explorers" })).toBeVisible();
28+
test("should verify houseoftest.ch is up and running", async ({}) => {
29+
// ARRANGE
30+
const browser = await container.getPlaywrightBrowser();
31+
const context = await browser.newContext();
32+
const page = await context.newPage();
33+
34+
// ACT
35+
const response = await page.goto("https://houseoftest.ch/", {
36+
waitUntil: "domcontentloaded",
37+
});
38+
39+
// ASSERT
40+
expect(response.status()).toBe(200);
41+
await expect(
42+
page.getByRole("heading", { name: "Explorers" })
43+
).toBeVisible();
44+
45+
await context.close();
46+
await browser.close();
47+
});
1548
});

0 commit comments

Comments
 (0)