desy-html 6.4.1 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/index.html +25 -3
- package/gulpfile.js +3 -2
- package/package.json +7 -3
- package/src/templates/components/header-advanced/_examples.header-advanced.njk +101 -14
- package/src/templates/components/header-advanced/_template.header-advanced.njk +2 -2
- package/test/backstop_config/backstop.config.js +35 -0
- package/test/backstop_config/scenarios/components_a.js +31 -0
- package/test/backstop_config/scenarios/components_b.js +31 -0
- package/test/backstop_config/scenarios/components_c.js +31 -0
- package/test/backstop_config/scenarios/components_d.js +49 -0
- package/test/backstop_config/scenarios/components_e.js +22 -0
- package/test/backstop_config/scenarios/components_f.js +31 -0
- package/test/backstop_config/scenarios/components_h.js +40 -0
- package/test/backstop_config/scenarios/components_i.js +40 -0
- package/test/backstop_config/scenarios/components_l.js +22 -0
- package/test/backstop_config/scenarios/components_m.js +58 -0
- package/test/backstop_config/scenarios/components_n.js +22 -0
- package/test/backstop_config/scenarios/components_p.js +22 -0
- package/test/backstop_config/scenarios/components_r.js +13 -0
- package/test/backstop_config/scenarios/components_s.js +58 -0
- package/test/backstop_config/scenarios/components_t.js +67 -0
- package/test/backstop_config/scenarios/home.js +12 -0
- package/test/backstop_config/scenarios/styles.js +13 -0
- package/test/backstop_config/scenarios.js +39 -0
- package/test/backstop_data/bitmaps_reference/Desy_Accordion_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Accordion_history_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Alert_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Breadcrumbs_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Button_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Button_loader_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Character_count_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Checkboxes_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Collapsible_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Date_input_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Description_list_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Details_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Dialog_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Dropdown_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Error_message_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Error_summary_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Fieldset_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_File_upload_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Footer_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Header_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Header_advanced_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Header_mini_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Hint_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Home_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Input_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Input_group_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Item_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Label_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Listbox_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Media_object_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Menu_horizontal_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Menu_navigation_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Menu_vertical_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Menubar_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Modal_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Nav_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Notification_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Pagination_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Pill_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Searchbar_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Select_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Skip_link_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Spinner_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Status_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Status_item_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Styles_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Table_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Table_advanced_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Tabs_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Textarea_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Toggle_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Tooltip_0_document_0_desktop.png +0 -0
- package/test/backstop_data/bitmaps_reference/Desy_Tree_0_document_0_desktop.png +0 -0
- package/test/backstop_data/engine_scripts/cookies.json +14 -0
- package/test/backstop_data/engine_scripts/imageStub.jpg +0 -0
- package/test/backstop_data/engine_scripts/playwright/clickAndHoverHelper.js +43 -0
- package/test/backstop_data/engine_scripts/playwright/interceptImages.js +31 -0
- package/test/backstop_data/engine_scripts/playwright/loadCookies.js +16 -0
- package/test/backstop_data/engine_scripts/playwright/onBefore.js +5 -0
- package/test/backstop_data/engine_scripts/playwright/onReady.js +6 -0
- package/test/backstop_data/engine_scripts/playwright/overrideCSS.js +27 -0
- package/test/backstop_data/engine_scripts/puppet/clickAndHoverHelper.js +39 -0
- package/test/backstop_data/engine_scripts/puppet/ignoreCSP.js +65 -0
- package/test/backstop_data/engine_scripts/puppet/interceptImages.js +37 -0
- package/test/backstop_data/engine_scripts/puppet/loadCookies.js +33 -0
- package/test/backstop_data/engine_scripts/puppet/onBefore.js +3 -0
- package/test/backstop_data/engine_scripts/puppet/onReady.js +6 -0
- package/test/backstop_data/engine_scripts/puppet/overrideCSS.js +15 -0
- package/test/backstop_data/html_report/a96f14595379b7c348d66e115ec65a93.png +0 -0
- package/test/backstop_data/html_report/assets/fonts/Lato-Bold.ttf +0 -0
- package/test/backstop_data/html_report/assets/fonts/Lato-Regular.ttf +0 -0
- package/test/backstop_data/html_report/assets/fonts/lato-bold-webfont.woff +0 -0
- package/test/backstop_data/html_report/assets/fonts/lato-bold-webfont.woff2 +0 -0
- package/test/backstop_data/html_report/assets/fonts/lato-regular-webfont.woff +0 -0
- package/test/backstop_data/html_report/assets/fonts/lato-regular-webfont.woff2 +0 -0
- package/test/backstop_data/html_report/b815e28b1e230cff6e9d7b749edcd562.png +0 -0
- package/test/backstop_data/html_report/config.js +1335 -0
- package/test/backstop_data/html_report/diff.js +1843 -0
- package/test/backstop_data/html_report/diverged.js +340 -0
- package/test/backstop_data/html_report/divergedWorker.js +6 -0
- package/test/backstop_data/html_report/index.html +49 -0
- package/test/backstop_data/html_report/index_bundle.js +2 -0
- package/docs/examples-header-advanced-2.html +0 -5
- package/src/templates/components/header-advanced/_examples.header-advanced-2.njk +0 -911
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const home = require('./scenarios/home');
|
|
2
|
+
const components_a = require('./scenarios/components_a');
|
|
3
|
+
const components_b = require('./scenarios/components_b');
|
|
4
|
+
const components_c = require('./scenarios/components_c');
|
|
5
|
+
const components_d = require('./scenarios/components_d');
|
|
6
|
+
const components_e = require('./scenarios/components_e');
|
|
7
|
+
const components_f = require('./scenarios/components_f');
|
|
8
|
+
const components_h = require('./scenarios/components_h');
|
|
9
|
+
const components_i = require('./scenarios/components_i');
|
|
10
|
+
const components_l = require('./scenarios/components_l');
|
|
11
|
+
const components_m = require('./scenarios/components_m');
|
|
12
|
+
const components_n = require('./scenarios/components_n');
|
|
13
|
+
const components_p = require('./scenarios/components_p');
|
|
14
|
+
const components_r = require('./scenarios/components_r');
|
|
15
|
+
const components_s = require('./scenarios/components_s');
|
|
16
|
+
const components_t = require('./scenarios/components_t');
|
|
17
|
+
const styles = require('./scenarios/styles');
|
|
18
|
+
|
|
19
|
+
const scenarios = [
|
|
20
|
+
...home,
|
|
21
|
+
...components_a,
|
|
22
|
+
...components_b,
|
|
23
|
+
...components_c,
|
|
24
|
+
...components_d,
|
|
25
|
+
...components_e,
|
|
26
|
+
...components_f,
|
|
27
|
+
...components_h,
|
|
28
|
+
...components_i,
|
|
29
|
+
...components_l,
|
|
30
|
+
...components_m,
|
|
31
|
+
...components_n,
|
|
32
|
+
...components_p,
|
|
33
|
+
...components_r,
|
|
34
|
+
...components_s,
|
|
35
|
+
...components_t,
|
|
36
|
+
...styles,
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
module.exports = scenarios;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"domain": ".www.yourdomain.com",
|
|
4
|
+
"path": "/",
|
|
5
|
+
"name": "yourCookieName",
|
|
6
|
+
"value": "yourCookieValue",
|
|
7
|
+
"expirationDate": 1798790400,
|
|
8
|
+
"hostOnly": false,
|
|
9
|
+
"httpOnly": false,
|
|
10
|
+
"secure": false,
|
|
11
|
+
"session": false,
|
|
12
|
+
"sameSite": "Lax"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module.exports = async (page, scenario) => {
|
|
2
|
+
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector;
|
|
3
|
+
const clickSelector = scenario.clickSelectors || scenario.clickSelector;
|
|
4
|
+
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector;
|
|
5
|
+
const scrollToSelector = scenario.scrollToSelector;
|
|
6
|
+
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]
|
|
7
|
+
|
|
8
|
+
if (keyPressSelector) {
|
|
9
|
+
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
|
|
10
|
+
await page.waitForSelector(keyPressSelectorItem.selector);
|
|
11
|
+
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (hoverSelector) {
|
|
16
|
+
for (const hoverSelectorIndex of [].concat(hoverSelector)) {
|
|
17
|
+
await page.waitForSelector(hoverSelectorIndex);
|
|
18
|
+
await page.hover(hoverSelectorIndex);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (clickSelector) {
|
|
23
|
+
for (const clickSelectorIndex of [].concat(clickSelector)) {
|
|
24
|
+
await page.waitForSelector(clickSelectorIndex);
|
|
25
|
+
await page.click(clickSelectorIndex);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (postInteractionWait) {
|
|
30
|
+
if (parseInt(postInteractionWait) > 0) {
|
|
31
|
+
await page.waitForTimeout(postInteractionWait);
|
|
32
|
+
} else {
|
|
33
|
+
await page.waitForSelector(postInteractionWait);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (scrollToSelector) {
|
|
38
|
+
await page.waitForSelector(scrollToSelector);
|
|
39
|
+
await page.evaluate(scrollToSelector => {
|
|
40
|
+
document.querySelector(scrollToSelector).scrollIntoView();
|
|
41
|
+
}, scrollToSelector);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* INTERCEPT IMAGES
|
|
3
|
+
* Listen to all requests. If a request matches IMAGE_URL_RE
|
|
4
|
+
* then stub the image with data from IMAGE_STUB_URL
|
|
5
|
+
*
|
|
6
|
+
* Use this in an onBefore script E.G.
|
|
7
|
+
```
|
|
8
|
+
module.exports = async function(page, scenario) {
|
|
9
|
+
require('./interceptImages')(page, scenario);
|
|
10
|
+
}
|
|
11
|
+
```
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const IMAGE_URL_RE = /\.gif|\.jpg|\.png/i;
|
|
19
|
+
const IMAGE_STUB_URL = path.resolve(__dirname, '../../imageStub.jpg');
|
|
20
|
+
const IMAGE_DATA_BUFFER = fs.readFileSync(IMAGE_STUB_URL);
|
|
21
|
+
const HEADERS_STUB = {};
|
|
22
|
+
|
|
23
|
+
module.exports = async function (page, scenario) {
|
|
24
|
+
page.route(IMAGE_URL_RE, route => {
|
|
25
|
+
route.fulfill({
|
|
26
|
+
body: IMAGE_DATA_BUFFER,
|
|
27
|
+
headers: HEADERS_STUB,
|
|
28
|
+
status: 200
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
module.exports = async (browserContext, scenario) => {
|
|
4
|
+
let cookies = [];
|
|
5
|
+
const cookiePath = scenario.cookiePath;
|
|
6
|
+
|
|
7
|
+
// Read Cookies from File, if exists
|
|
8
|
+
if (fs.existsSync(cookiePath)) {
|
|
9
|
+
cookies = JSON.parse(fs.readFileSync(cookiePath));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Add cookies to browser
|
|
13
|
+
browserContext.addCookies(cookies);
|
|
14
|
+
|
|
15
|
+
console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2));
|
|
16
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OVERRIDE CSS
|
|
3
|
+
* Apply this CSS to the loaded page, as a way to override styles.
|
|
4
|
+
*
|
|
5
|
+
* Use this in an onReady script E.G.
|
|
6
|
+
```
|
|
7
|
+
module.exports = async function(page, scenario) {
|
|
8
|
+
await require('./overrideCSS')(page, scenario);
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const BACKSTOP_TEST_CSS_OVERRIDE = `
|
|
15
|
+
html {
|
|
16
|
+
background-image: none;
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
module.exports = async (page, scenario) => {
|
|
21
|
+
// inject arbitrary css to override styles
|
|
22
|
+
await page.addStyleTag({
|
|
23
|
+
content: BACKSTOP_TEST_CSS_OVERRIDE
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log('BACKSTOP_TEST_CSS_OVERRIDE injected for: ' + scenario.label);
|
|
27
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = async (page, scenario) => {
|
|
2
|
+
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector;
|
|
3
|
+
const clickSelector = scenario.clickSelectors || scenario.clickSelector;
|
|
4
|
+
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector;
|
|
5
|
+
const scrollToSelector = scenario.scrollToSelector;
|
|
6
|
+
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]
|
|
7
|
+
|
|
8
|
+
if (keyPressSelector) {
|
|
9
|
+
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
|
|
10
|
+
await page.waitFor(keyPressSelectorItem.selector);
|
|
11
|
+
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (hoverSelector) {
|
|
16
|
+
for (const hoverSelectorIndex of [].concat(hoverSelector)) {
|
|
17
|
+
await page.waitFor(hoverSelectorIndex);
|
|
18
|
+
await page.hover(hoverSelectorIndex);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (clickSelector) {
|
|
23
|
+
for (const clickSelectorIndex of [].concat(clickSelector)) {
|
|
24
|
+
await page.waitFor(clickSelectorIndex);
|
|
25
|
+
await page.click(clickSelectorIndex);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (postInteractionWait) {
|
|
30
|
+
await page.waitFor(postInteractionWait);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (scrollToSelector) {
|
|
34
|
+
await page.waitFor(scrollToSelector);
|
|
35
|
+
await page.evaluate(scrollToSelector => {
|
|
36
|
+
document.querySelector(scrollToSelector).scrollIntoView();
|
|
37
|
+
}, scrollToSelector);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IGNORE CSP HEADERS
|
|
3
|
+
* Listen to all requests. If a request matches scenario.url
|
|
4
|
+
* then fetch the request again manually, strip out CSP headers
|
|
5
|
+
* and respond to the original request without CSP headers.
|
|
6
|
+
* Allows `ignoreHTTPSErrors: true` BUT... requires `debugWindow: true`
|
|
7
|
+
*
|
|
8
|
+
* see https://github.com/GoogleChrome/puppeteer/issues/1229#issuecomment-380133332
|
|
9
|
+
* this is the workaround until Page.setBypassCSP lands... https://github.com/GoogleChrome/puppeteer/pull/2324
|
|
10
|
+
*
|
|
11
|
+
* @param {REQUEST} request
|
|
12
|
+
* @return {VOID}
|
|
13
|
+
*
|
|
14
|
+
* Use this in an onBefore script E.G.
|
|
15
|
+
```
|
|
16
|
+
module.exports = async function(page, scenario) {
|
|
17
|
+
require('./removeCSP')(page, scenario);
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const fetch = require('node-fetch');
|
|
24
|
+
const https = require('https');
|
|
25
|
+
const agent = new https.Agent({
|
|
26
|
+
rejectUnauthorized: false
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
module.exports = async function (page, scenario) {
|
|
30
|
+
const intercept = async (request, targetUrl) => {
|
|
31
|
+
const requestUrl = request.url();
|
|
32
|
+
|
|
33
|
+
// FIND TARGET URL REQUEST
|
|
34
|
+
if (requestUrl === targetUrl) {
|
|
35
|
+
const cookiesList = await page.cookies(requestUrl);
|
|
36
|
+
const cookies = cookiesList.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
|
|
37
|
+
const headers = Object.assign(request.headers(), { cookie: cookies });
|
|
38
|
+
const options = {
|
|
39
|
+
headers,
|
|
40
|
+
body: request.postData(),
|
|
41
|
+
method: request.method(),
|
|
42
|
+
follow: 20,
|
|
43
|
+
agent
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const result = await fetch(requestUrl, options);
|
|
47
|
+
|
|
48
|
+
const buffer = await result.buffer();
|
|
49
|
+
const cleanedHeaders = result.headers._headers || {};
|
|
50
|
+
cleanedHeaders['content-security-policy'] = '';
|
|
51
|
+
await request.respond({
|
|
52
|
+
body: buffer,
|
|
53
|
+
headers: cleanedHeaders,
|
|
54
|
+
status: result.status
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
request.continue();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
await page.setRequestInterception(true);
|
|
62
|
+
page.on('request', req => {
|
|
63
|
+
intercept(req, scenario.url);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* INTERCEPT IMAGES
|
|
3
|
+
* Listen to all requests. If a request matches IMAGE_URL_RE
|
|
4
|
+
* then stub the image with data from IMAGE_STUB_URL
|
|
5
|
+
*
|
|
6
|
+
* Use this in an onBefore script E.G.
|
|
7
|
+
```
|
|
8
|
+
module.exports = async function(page, scenario) {
|
|
9
|
+
require('./interceptImages')(page, scenario);
|
|
10
|
+
}
|
|
11
|
+
```
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const IMAGE_URL_RE = /\.gif|\.jpg|\.png/i;
|
|
19
|
+
const IMAGE_STUB_URL = path.resolve(__dirname, '../imageStub.jpg');
|
|
20
|
+
const IMAGE_DATA_BUFFER = fs.readFileSync(IMAGE_STUB_URL);
|
|
21
|
+
const HEADERS_STUB = {};
|
|
22
|
+
|
|
23
|
+
module.exports = async function (page, scenario) {
|
|
24
|
+
const intercept = async (request, targetUrl) => {
|
|
25
|
+
if (IMAGE_URL_RE.test(request.url())) {
|
|
26
|
+
await request.respond({
|
|
27
|
+
body: IMAGE_DATA_BUFFER,
|
|
28
|
+
headers: HEADERS_STUB,
|
|
29
|
+
status: 200
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
request.continue();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
await page.setRequestInterception(true);
|
|
36
|
+
page.on('request', intercept);
|
|
37
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
module.exports = async (page, scenario) => {
|
|
4
|
+
let cookies = [];
|
|
5
|
+
const cookiePath = scenario.cookiePath;
|
|
6
|
+
|
|
7
|
+
// READ COOKIES FROM FILE IF EXISTS
|
|
8
|
+
if (fs.existsSync(cookiePath)) {
|
|
9
|
+
cookies = JSON.parse(fs.readFileSync(cookiePath));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// MUNGE COOKIE DOMAIN
|
|
13
|
+
cookies = cookies.map(cookie => {
|
|
14
|
+
if (cookie.domain.startsWith('http://') || cookie.domain.startsWith('https://')) {
|
|
15
|
+
cookie.url = cookie.domain;
|
|
16
|
+
} else {
|
|
17
|
+
cookie.url = 'https://' + cookie.domain;
|
|
18
|
+
}
|
|
19
|
+
delete cookie.domain;
|
|
20
|
+
return cookie;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// SET COOKIES
|
|
24
|
+
const setCookies = async () => {
|
|
25
|
+
return Promise.all(
|
|
26
|
+
cookies.map(async (cookie) => {
|
|
27
|
+
await page.setCookie(cookie);
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
await setCookies();
|
|
32
|
+
console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2));
|
|
33
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const BACKSTOP_TEST_CSS_OVERRIDE = 'html {background-image: none;}';
|
|
2
|
+
|
|
3
|
+
module.exports = async (page, scenario) => {
|
|
4
|
+
// inject arbitrary css to override styles
|
|
5
|
+
await page.evaluate(`window._styleData = '${BACKSTOP_TEST_CSS_OVERRIDE}'`);
|
|
6
|
+
await page.evaluate(() => {
|
|
7
|
+
const style = document.createElement('style');
|
|
8
|
+
style.type = 'text/css';
|
|
9
|
+
const styleNode = document.createTextNode(window._styleData);
|
|
10
|
+
style.appendChild(styleNode);
|
|
11
|
+
document.head.appendChild(style);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
console.log('BACKSTOP_TEST_CSS_OVERRIDE injected for: ' + scenario.label);
|
|
15
|
+
};
|
|
Binary file
|
|
Binary file
|