forked from testcontainers/testcontainers-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium-container.test.ts
More file actions
65 lines (51 loc) · 2.62 KB
/
Copy pathselenium-container.test.ts
File metadata and controls
65 lines (51 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import path from "path";
import { Browser, Builder } from "selenium-webdriver";
import { GenericContainer, Network } from "testcontainers";
import tmp from "tmp";
import { getImage } from "../../../testcontainers/src/utils/test-helper";
import { SELENIUM_VIDEO_IMAGE, SeleniumContainer } from "./selenium-container";
const browsers = [
["CHROME", process.arch === "arm64" ? getImage(__dirname, 1) : getImage(__dirname, 0)],
["FIREFOX", process.arch === "arm64" ? getImage(__dirname, 3) : getImage(__dirname, 2)],
] as const;
describe.for(browsers)("SeleniumContainer", { timeout: 240_000 }, ([browser, image]) => {
it(`should work for ${browser}`, async () => {
// seleniumExample {
await using container = await new SeleniumContainer(image).start();
const driver = await new Builder().forBrowser(Browser[browser]).usingServer(container.getServerUrl()).build();
await driver.get("https://testcontainers.com");
expect(await driver.getTitle()).toEqual("Testcontainers");
await driver.quit();
// }
});
it(`should record video and save to disk for ${browser}`, async () => {
// seleniumVideoExample {
const container = await new SeleniumContainer(image).withRecording().start();
const driver = await new Builder().forBrowser(Browser[browser]).usingServer(container.getServerUrl()).build();
await driver.get("https://testcontainers.com");
await driver.quit();
const stoppedContainer = await container.stop();
const videoFilePath = tmp.fileSync({ keep: false, prefix: `video-${browser}`, postfix: ".mp4" }).name;
const videoFileName = path.basename(videoFilePath);
await stoppedContainer.saveRecording(videoFilePath);
await using ffmpegContainer = await new GenericContainer(SELENIUM_VIDEO_IMAGE)
.withCommand(["sleep", "infinity"])
.start();
await ffmpegContainer.copyFilesToContainer([{ source: videoFilePath, target: `/tmp/${videoFileName}` }]);
const { exitCode } = await ffmpegContainer.exec(["ffprobe", `/tmp/${videoFileName}`]);
expect(exitCode).toBe(0);
// }
});
it(`should use provided network when recording for ${browser}`, async () => {
await using network = await new Network().start();
await using _webServer = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
.withNetwork(network)
.withNetworkAliases("webserver")
.withExposedPorts(8080)
.start();
const container = await new SeleniumContainer(image).withRecording().withNetwork(network).start();
const { exitCode } = await container.exec(["getent", "hosts", "webserver"]);
expect(exitCode).toBe(0);
await container.stop();
});
});