-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Integrate WDIO #1342
Open
conradkirschner
wants to merge
19
commits into
garris:master
Choose a base branch
from
conradkirschner:wdio_integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[WIP] Integrate WDIO #1342
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b921b44
init wdio integration
4bcb9b1
added try catch to cookie
03b7f31
converting engine scripts
c3bd779
converting engine scripts
45a076e
converting engine scripts
74d564f
converting engine scripts
ec81abe
- provide sample backstop.json
4f5f65c
- added wdio service usage to wdio
e2736ac
- added wdio service usage to wdio
c52b6b4
- added waiter for service loading
76dca57
- added todo
f438d70
- added possibility to stay with json but also use
d7f61e3
- added documentation
40e5534
- added idea how to handle image mocking
eb516cf
Merge branch 'master' into wdio_integration
conradkirschner 55f0f18
- added feature for waiting readystate
56db845
- removed feature
cf799e8
#WebdriverIO Integration
07645c9
removed text from readme to keep it short and simple
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"id": "backstop_default", | ||
"viewports": [ | ||
{ | ||
"label": "phone", | ||
"width": 320, | ||
"height": 1768 | ||
} | ||
], | ||
"onBeforeScript": "wdio/onBefore.js", | ||
"onReadyScript": "wdio/onReady.js", | ||
"scenarios": [ | ||
{ | ||
"label": "BackstopJS Homepage", | ||
"cookiePath": "backstop_data/engine_scripts/cookies.json", | ||
"url": "https://garris.github.io/BackstopJS/", | ||
"referenceUrl": "", | ||
"readyEvent": "", | ||
"readySelector": "", | ||
"delay": 0, | ||
"hideSelectors": [], | ||
"removeSelectors": [], | ||
"hoverSelector": "", | ||
"clickSelector": "", | ||
"postInteractionWait": 0, | ||
"selectors": [], | ||
"selectorExpansion": true, | ||
"expect": 0, | ||
"misMatchThreshold": 0.1, | ||
"requireSameDimensions": true | ||
} | ||
], | ||
"paths": { | ||
"bitmaps_reference": "backstop_data/bitmaps_reference", | ||
"bitmaps_test": "backstop_data/bitmaps_test", | ||
"engine_scripts": "backstop_data/engine_scripts", | ||
"html_report": "backstop_data/html_report", | ||
"ci_report": "backstop_data/ci_report" | ||
}, | ||
"report": [ | ||
"browser" | ||
], | ||
"engine": "wdio", | ||
"engineOptions": { | ||
"wdio": { | ||
"logLevel": "trace", | ||
"protocol": "http", | ||
"hostname": "hub.browserstack.com", | ||
"capabilities": { | ||
"browserName": "chrome" | ||
}, | ||
"user": "process.env.BROWSERSTACK_ACCESS_USER", | ||
"key": "process.env.BROWSERSTACK_ACCESS_KEY", | ||
"services": [ | ||
[ | ||
"browserstack", { | ||
"browserstackLocal": true | ||
}] | ||
] | ||
}, | ||
"puppeteer": { | ||
"args": [ | ||
"--no-sandbox" | ||
] | ||
} | ||
}, | ||
"asyncCaptureLimit": 5, | ||
"asyncCompareLimit": 50, | ||
"debug": false, | ||
"debugWindow": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"domain": ".www.yourdomain.com", | ||
"path": "/", | ||
"name": "yourCookieName", | ||
"value": "yourCookieValue", | ||
"expirationDate": 1798790400, | ||
"hostOnly": false, | ||
"httpOnly": false, | ||
"secure": false, | ||
"session": false, | ||
"sameSite": "no_restriction" | ||
} | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions
39
backstop_data/engine_scripts/puppet/clickAndHoverHelper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = async (page, scenario) => { | ||
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector; | ||
const clickSelector = scenario.clickSelectors || scenario.clickSelector; | ||
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector; | ||
const scrollToSelector = scenario.scrollToSelector; | ||
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int] | ||
|
||
if (keyPressSelector) { | ||
for (const keyPressSelectorItem of [].concat(keyPressSelector)) { | ||
await page.waitFor(keyPressSelectorItem.selector); | ||
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress); | ||
} | ||
} | ||
|
||
if (hoverSelector) { | ||
for (const hoverSelectorIndex of [].concat(hoverSelector)) { | ||
await page.waitFor(hoverSelectorIndex); | ||
await page.hover(hoverSelectorIndex); | ||
} | ||
} | ||
|
||
if (clickSelector) { | ||
for (const clickSelectorIndex of [].concat(clickSelector)) { | ||
await page.waitFor(clickSelectorIndex); | ||
await page.click(clickSelectorIndex); | ||
} | ||
} | ||
|
||
if (postInteractionWait) { | ||
await page.waitFor(postInteractionWait); | ||
} | ||
|
||
if (scrollToSelector) { | ||
await page.waitFor(scrollToSelector); | ||
await page.evaluate(scrollToSelector => { | ||
document.querySelector(scrollToSelector).scrollIntoView(); | ||
}, scrollToSelector); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* IGNORE CSP HEADERS | ||
* Listen to all requests. If a request matches scenario.url | ||
* then fetch the request again manually, strip out CSP headers | ||
* and respond to the original request without CSP headers. | ||
* Allows `ignoreHTTPSErrors: true` BUT... requires `debugWindow: true` | ||
* | ||
* see https://github.com/GoogleChrome/puppeteer/issues/1229#issuecomment-380133332 | ||
* this is the workaround until Page.setBypassCSP lands... https://github.com/GoogleChrome/puppeteer/pull/2324 | ||
* | ||
* @param {REQUEST} request | ||
* @return {VOID} | ||
* | ||
* Use this in an onBefore script E.G. | ||
``` | ||
module.exports = async function(page, scenario) { | ||
require('./removeCSP')(page, scenario); | ||
} | ||
``` | ||
* | ||
*/ | ||
|
||
const fetch = require('node-fetch'); | ||
const https = require('https'); | ||
const agent = new https.Agent({ | ||
rejectUnauthorized: false | ||
}); | ||
|
||
module.exports = async function (page, scenario) { | ||
const intercept = async (request, targetUrl) => { | ||
const requestUrl = request.url(); | ||
|
||
// FIND TARGET URL REQUEST | ||
if (requestUrl === targetUrl) { | ||
const cookiesList = await page.cookies(requestUrl); | ||
const cookies = cookiesList.map(cookie => `${cookie.name}=${cookie.value}`).join('; '); | ||
const headers = Object.assign(request.headers(), { cookie: cookies }); | ||
const options = { | ||
headers: headers, | ||
body: request.postData(), | ||
method: request.method(), | ||
follow: 20, | ||
agent | ||
}; | ||
|
||
const result = await fetch(requestUrl, options); | ||
|
||
const buffer = await result.buffer(); | ||
let cleanedHeaders = result.headers._headers || {}; | ||
cleanedHeaders['content-security-policy'] = ''; | ||
await request.respond({ | ||
body: buffer, | ||
headers: cleanedHeaders, | ||
status: result.status | ||
}); | ||
} else { | ||
request.continue(); | ||
} | ||
}; | ||
|
||
await page.setRequestInterception(true); | ||
page.on('request', req => { | ||
intercept(req, scenario.url); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* INTERCEPT IMAGES | ||
* Listen to all requests. If a request matches IMAGE_URL_RE | ||
* then stub the image with data from IMAGE_STUB_URL | ||
* | ||
* Use this in an onBefore script E.G. | ||
``` | ||
module.exports = async function(page, scenario) { | ||
require('./interceptImages')(page, scenario); | ||
} | ||
``` | ||
* | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const IMAGE_URL_RE = /\.gif|\.jpg|\.png/i; | ||
const IMAGE_STUB_URL = path.resolve(__dirname, '../../imageStub.jpg'); | ||
const IMAGE_DATA_BUFFER = fs.readFileSync(IMAGE_STUB_URL); | ||
const HEADERS_STUB = {}; | ||
|
||
module.exports = async function (page, scenario) { | ||
const intercept = async (request, targetUrl) => { | ||
if (IMAGE_URL_RE.test(request.url())) { | ||
await request.respond({ | ||
body: IMAGE_DATA_BUFFER, | ||
headers: HEADERS_STUB, | ||
status: 200 | ||
}); | ||
} else { | ||
request.continue(); | ||
} | ||
}; | ||
await page.setRequestInterception(true); | ||
page.on('request', intercept); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
|
||
module.exports = async (page, scenario) => { | ||
let cookies = []; | ||
const cookiePath = scenario.cookiePath; | ||
|
||
// READ COOKIES FROM FILE IF EXISTS | ||
if (fs.existsSync(cookiePath)) { | ||
cookies = JSON.parse(fs.readFileSync(cookiePath)); | ||
} | ||
|
||
// MUNGE COOKIE DOMAIN | ||
cookies = cookies.map(cookie => { | ||
if (cookie.domain.startsWith('http://') || cookie.domain.startsWith('https://')) { | ||
cookie.url = cookie.domain; | ||
} else { | ||
cookie.url = 'https://' + cookie.domain; | ||
} | ||
delete cookie.domain; | ||
return cookie; | ||
}); | ||
|
||
// SET COOKIES | ||
const setCookies = async () => { | ||
return Promise.all( | ||
cookies.map(async (cookie) => { | ||
await page.setCookie(cookie); | ||
}) | ||
); | ||
}; | ||
await setCookies(); | ||
console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = async (page, scenario, vp) => { | ||
await require('./loadCookies')(page, scenario); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = async (page, scenario, vp) => { | ||
console.log('SCENARIO > ' + scenario.label); | ||
await require('./clickAndHoverHelper')(page, scenario); | ||
|
||
// add more ready handlers here... | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const BACKSTOP_TEST_CSS_OVERRIDE = `html {background-image: none;}`; | ||
|
||
module.exports = async (page, scenario) => { | ||
// inject arbitrary css to override styles | ||
await page.evaluate(`window._styleData = '${BACKSTOP_TEST_CSS_OVERRIDE}'`); | ||
await page.evaluate(() => { | ||
const style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
const styleNode = document.createTextNode(window._styleData); | ||
style.appendChild(styleNode); | ||
document.head.appendChild(style); | ||
}); | ||
|
||
console.log('BACKSTOP_TEST_CSS_OVERRIDE injected for: ' + scenario.label); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module.exports = async (browser, scenario) => { | ||
const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector; | ||
const clickSelector = scenario.clickSelectors || scenario.clickSelector; | ||
const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector; | ||
const scrollToSelector = scenario.scrollToSelector; | ||
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int] | ||
|
||
if (keyPressSelector) { | ||
for (const keyPressSelectorItem of [].concat(keyPressSelector)) { | ||
await browser.$(keyPressSelectorItem.selector).waitForDisplayed(); | ||
const input = browser.$(keyPressSelectorItem.selector); | ||
input.setValue(keyPressSelectorItem.keyPress); | ||
} | ||
} | ||
|
||
if (hoverSelector) { | ||
for (const hoverSelectorIndex of [].concat(hoverSelector)) { | ||
await browser.$(hoverSelectorIndex).waitForDisplayed(); | ||
browser.$(hoverSelectorIndex).moveTo(); | ||
} | ||
} | ||
|
||
if (clickSelector) { | ||
for (const clickSelectorIndex of [].concat(clickSelector)) { | ||
await browser.$(clickSelectorIndex).waitForDisplayed(); | ||
const clickElement = browser.$(clickSelectorIndex); | ||
clickElement.click(); | ||
} | ||
} | ||
|
||
if (postInteractionWait) { | ||
await browser.$(postInteractionWait).waitForDisplayed(); | ||
} | ||
|
||
if (scrollToSelector) { | ||
await browser.$(scrollToSelector).waitForDisplayed(); | ||
|
||
await browser.execute(scrollToSelector => { | ||
document.querySelector(scrollToSelector).scrollIntoView(); | ||
}, scrollToSelector); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some issues with directly comparing, backstopjs puppeteer pictures with wdio pictures.
Therefore I added a BETA support, so maybe some people get interessted to work on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it is very very unlikely that you could ever render a reference image in puppeteer and then be able to test that against a test image generated in WDIO. Or vice versa. In addition to different high level rendering interpretations of the different application environments, there will also be a low-level rendering issue because different hardware will dither bitmap text differently. For example you can see this explanation.
TLDR; Screenshots generated by a single hardware, software and platform combination can only be compared against itself.