|
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"; |
2 | 5 |
|
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; |
6 | 9 |
|
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(); |
10 | 26 | }); |
11 | 27 |
|
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 | + }); |
15 | 48 | }); |
0 commit comments