-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbypass-captcha.config.example.ts
45 lines (39 loc) · 1.46 KB
/
bypass-captcha.config.example.ts
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
/**
* This file is used to set up the CAPTCHA bypass for your tests.
* It will set the global cookie to bypass CAPTCHA for Magento 2.
* See: https://github.com/elgentos/magento2-bypass-captcha-cookie
*
*/
import { FullConfig } from '@playwright/test';
import * as playwright from 'playwright';
import dotenv from 'dotenv';
dotenv.config();
async function globalSetup(config: FullConfig) {
const bypassCaptcha = process.env.CAPTCHA_BYPASS === 'true';
for (const project of config.projects) {
const { storageState, browserName = 'chromium' } = project.use || {};
if (storageState) {
const browserType = playwright[browserName];
const browser = await browserType.launch();
const context = await browser.newContext();
if (bypassCaptcha) {
// Set the global cookie to bypass CAPTCHA
await context.addCookies([{
name: 'disable_captcha', // this cookie will be read by 'magento2-bypass-captcha-cookie' module.
value: '', // Fill with generated token.
domain: 'hyva-demo.elgentos.io', // Replace with your domain
path: '/',
httpOnly: true,
secure: true,
sameSite: 'Lax',
}]);
console.log(`CAPTCHA bypass enabled for browser: ${project.name}`);
} else {
// Do nothing.
}
await context.storageState({ path: `./auth-storage/${project.name}-storage-state.json` });
await browser.close();
}
}
}
export default globalSetup;