Skip to content

Commit 91f1c8e

Browse files
authored
[ENG-2280] test: add giftaid playwright tests (#380)
* test: add giftaid playwright tests * test: add postcode lookup tests * add test for international postcode and address * remove ERP test * add giftaid update valid submission test * add giftaid update tests * add nightly-sanity tag to all tests to run nightly * use the same sanity tests to run nightly * remove email env vars from .env.example file
1 parent 4425b5c commit 91f1c8e

2,344 files changed

Lines changed: 309376 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"start": "node scripts/start.js",
4040
"build": "node scripts/build.js",
4141
"lint": "eslint --color src tests",
42+
"test:sanity": "playwright test --grep '@sanity'",
4243
"sanity-test": "export NODE_ENV=development; node_modules/.bin/nightwatch --tag sanity -e chrome --retries 2",
4344
"cy:run": "export NODE_ENV=development; cypress run",
4445
"cy:open": "export NODE_ENV=development; cypress open",

playwright/.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Browserstack
2+
BASE_URL=https://giftaid-staging.comicrelief.com/
3+
BROWSERSTACK_USERNAME=krupapammi1
4+
BROWSERSTACK_ACCESS_KEY=
5+
6+
# Contact service reporting staging
7+
CONTACT_SERVICE_REPORTING_BASE_URL=https://contact-staging.data.comicrelief.com/reporting
8+
CONTACT_SERVICE_REPORTING_API_KEY=
9+
10+
#ERP Next
11+
ERP_HOST=https://erp-staging.comicrelief.com
12+
ERP_CLIENT=
13+
ERP_SECRET=

playwright/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test-results
2+
/node_modules

playwright/browserstack.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
require('dotenv').config();
2+
3+
const base = require('@playwright/test');
4+
const cp = require('child_process');
5+
const clientPlaywrightVersion = cp
6+
.execSync('npx playwright --version')
7+
.toString()
8+
.trim()
9+
.split(' ')[1];
10+
11+
// BrowserStack Specific Capabilities.
12+
const caps = {
13+
project: 'Giftaid',
14+
// build: 'Your specified build name goes here',
15+
name: 'e2e tests',
16+
browser: 'chrome',
17+
resolution: '1024x768',
18+
os: 'osx',
19+
os_version: 'catalina',
20+
'browserstack.username': process.env.BROWSERSTACK_USERNAME,
21+
'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY,
22+
'client.playwrightVersion': clientPlaywrightVersion,
23+
};
24+
25+
// Patching the capabilities dynamically according to the project name.
26+
const patchCaps = (name, title) => {
27+
let combination = name.split(/@browserstack/)[0];
28+
let [browerCaps, osCaps] = combination.split(/:/);
29+
let [browser, browser_version] = browerCaps.split(/@/);
30+
let osCapsSplit = osCaps.split(/ /);
31+
let os = osCapsSplit.shift();
32+
let os_version = osCapsSplit.join(' ');
33+
caps.browser = browser ? browser : 'chrome';
34+
caps.browser_version = browser_version ? browser_version : 'latest';
35+
caps.os = os ? os : 'osx';
36+
caps.os_version = os_version ? os_version : 'catalina';
37+
caps.name = title;
38+
};
39+
40+
const isHash = (entity) => Boolean(entity && typeof(entity) === "object" && !Array.isArray(entity));
41+
const nestedKeyValue = (hash, keys) => keys.reduce((hash, key) => (isHash(hash) ? hash[key] : undefined), hash);
42+
const isUndefined = val => (val === undefined || val === null || val === '');
43+
const evaluateSessionStatus = (status) => {
44+
if (!isUndefined(status)) {
45+
status = status.toLowerCase();
46+
}
47+
if (status === "passed") {
48+
return "passed";
49+
} else if (status === "failed" || status === "timedout") {
50+
return "failed";
51+
} else {
52+
return "";
53+
}
54+
}
55+
56+
exports.test = base.test.extend({
57+
page: async ({ page, playwright }, use, testInfo) => {
58+
// Use BrowserStack Launched Browser according to capabilities for cross-browser testing.
59+
if (testInfo.project.name.match(/browserstack/)) {
60+
patchCaps(testInfo.project.name,`${testInfo.title}`);
61+
const vBrowser = await playwright.chromium.connect({
62+
wsEndpoint:
63+
`wss://cdp.browserstack.com/playwright?caps=` +
64+
`${encodeURIComponent(JSON.stringify(caps))}`,
65+
});
66+
const vContext = await vBrowser.newContext(testInfo.project.use);
67+
const vPage = await vContext.newPage();
68+
await use(vPage);
69+
const testResult = {
70+
action: 'setSessionStatus',
71+
arguments: {
72+
status: evaluateSessionStatus(testInfo.status),
73+
reason: nestedKeyValue(testInfo, ['error', 'message'])
74+
},
75+
};
76+
await vPage.evaluate(() => {},
77+
`browserstack_executor: ${JSON.stringify(testResult)}`);
78+
await vPage.close();
79+
await vBrowser.close();
80+
} else {
81+
use(page);
82+
}
83+
},
84+
});

playwright/node_modules/@comicrelief/data-models/enums.d.ts

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)