-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixtures.browser.ts
More file actions
152 lines (138 loc) · 4.3 KB
/
Copy pathfixtures.browser.ts
File metadata and controls
152 lines (138 loc) · 4.3 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import path from "path";
import {
test as base,
chromium,
Page,
Worker,
type BrowserContext,
type BrowserContextOptions,
} from "@playwright/test";
import { configDotenv } from "dotenv";
import {
debugIsActive,
screenshotsOutput,
vaultEmail,
vaultPassword,
vaultHostURL,
} from "../constants";
import {
closeWelcomePage,
fetchFeatureFlags,
type FeatureFlags,
getBackgroundPage,
loginToVault,
prepareEnvironment,
readManifestVersion,
submitEnvironment,
} from "../fixtures/extension-setup";
configDotenv({ quiet: true });
const pathToExtension = path.join(
__dirname,
"../../",
process.env.CI ? "build" : process.env.EXTENSION_BUILD_PATH,
);
export const test = base.extend<{
background: Page | Worker;
context: BrowserContext;
extensionId: string;
extensionSetup: Page;
featureFlags: FeatureFlags;
manifestVersion: number;
recordVideoConfig: BrowserContextOptions["recordVideo"];
testOutputPath?: string;
}>({
context: async ({ browser, recordVideoConfig }, use) => {
console.log(
"\x1b[1m\x1b[36m%s\x1b[0m", // cyan foreground
"\tTesting with:",
);
console.log(
"\x1b[1m\x1b[36m%s\x1b[0m", // cyan foreground
`\t${browser.browserType().name()} version ${browser.version()}`,
);
const context = await chromium.launchPersistentContext("", {
acceptDownloads: false, // for safety, do not accept downloads
headless: false, // should always be `false`, even when testing headless Chrome
args: [
...(process.env.HEADLESS === "true"
? ["--headless=new"] // use for headless testing on Chrome
: []),
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
"--disable-dev-shm-usage",
"--disable-blink-features=AutomationControlled", // navigator.webdriver = false
"--enable-automation=false", // This flag disables the password manager
],
ignoreDefaultArgs: [
"--disable-component-extensions-with-background-pages",
],
// Help mitigate automation detection with a known-good userAgent
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
slowMo: 600,
viewport: {
width: 1200,
height: 1000,
},
recordVideo: recordVideoConfig,
});
await Promise.all([
context.setDefaultTimeout(20000),
context.setDefaultNavigationTimeout(120000),
]);
await use(context);
},
background: async ({ context, manifestVersion }, use) => {
await use(await getBackgroundPage(context, manifestVersion));
},
extensionId: async ({ background }, use) => {
const extensionId = background.url().split("/")[2];
await use(extensionId);
},
extensionSetup: async ({ context, extensionId, testOutputPath }, use) => {
let testPage: Page;
await test.step("Close the extension welcome page when it pops up", async () => {
testPage = await closeWelcomePage(
context,
!debugIsActive &&
process.env.HEADLESS !== "true" &&
process.env.CI === "true",
);
});
await test.step("Configure the environment", async () => {
if (vaultHostURL) {
await prepareEnvironment(testPage, extensionId, vaultHostURL);
await testPage.screenshot({
fullPage: true,
path: path.join(
screenshotsOutput,
testOutputPath,
"browser_client_environment_configured.png",
),
});
await submitEnvironment(testPage);
}
});
await test.step("Log in to the extension vault", async () => {
await loginToVault(testPage, extensionId, vaultEmail, vaultPassword);
});
await use(testPage);
},
featureFlags: async ({}, use) => {
await use(await fetchFeatureFlags(vaultHostURL));
},
manifestVersion: async ({}, use) => {
const manifestVersion = readManifestVersion(pathToExtension);
console.log(
"\x1b[1m\x1b[36m%s\x1b[0m", // cyan foreground
`\textension manifest version ${manifestVersion}`,
);
await use(manifestVersion);
},
recordVideoConfig:
process.env.DISABLE_VIDEO === "true"
? undefined
: { dir: "tests-out/videos" },
testOutputPath: "",
});
export const expect = test.expect;