Skip to content

Commit

Permalink
SBVT-1849: (Cypress) DOM capture incorrect after fullpage capture (#158)
Browse files Browse the repository at this point in the history
* simple check

* Fix Scroll before capture dom

* change name of function

* fix comparison

* Fix

* fix scroll

* add some more fixes

* Last fixes

* SBVT-1849: final updates

* SBVT-1849: removing ensureScrolledToTop to see what is failing the github actions

* SBVT-1849: JS_SCROLL does not 'ensure'

* SBVT-1849: Final touches

---------

Co-authored-by: trevornelms <[email protected]>
  • Loading branch information
Jakshas and tnelms1 authored Sep 18, 2023
1 parent 25e4059 commit fe48ad4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
26 changes: 22 additions & 4 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ let takeScreenshot = (element, name, modifiedOptions, win) => {
width: imageData.width
}
};
// Translate to the top of the page and then capture the dom
win.eval(`document.body.style.transform="translateY(0)"`);

ensureScrolledToTop(win)
captureDom(win);

// Read the new image base64 to blob to be sent to AWS
Expand Down Expand Up @@ -264,8 +264,8 @@ let takeScreenshot = (element, name, modifiedOptions, win) => {
modifiedOptions,
).then(() => {
if (vtConfFile.debug) cy.task('copy', {path: picProps.path, imageName, imageType});
// Translate to the top of the page and then capture the dom
win.eval(`document.body.style.transform="translateY(0)"`);

// ensureScrolledToTop(win) //this creates issues, but this is the JS_SCROLL method
captureDom(win);

// Read the new image base64 to blob to be sent to AWS
Expand Down Expand Up @@ -412,6 +412,24 @@ let captureDom = (win) => {
cy.writeFile(`./${vtConfFile.debug}/${imageName}-${imageType}/${imageName}.json`, dom);
}
};
let ensureScrolledToTop = (win) =>{
let tries = 0;
let scrollOffset = win.eval(`window.scrollY`);
while (scrollOffset !== 0 && tries < 40){
tries++;
cy.task('logger', {type: 'warn', message: `Page not scrolled to the top. Scroll offset is: ${scrollOffset}. Trying to scroll to the top again and waiting 250ms. Try #: ${tries}`});
cy.scrollTo(0,0);
win.eval(`window.scrollTo(0, 0);`)
cy.wait(250);
scrollOffset = win.eval(`window.scrollY`); //check and update the scrolled position again
}
if (tries < 40 && scrollOffset === 0){
cy.task('logger', {type: 'info', message: `Scroll offset is: ${scrollOffset}, after ${tries} tries`});
}else{
cy.task('logger', {type: 'error', message: `Couldn't scroll to the top of page after ${tries} tries. Scroll offset positon stuck at: ${scrollOffset}.`});
throw new Error(`Couldn't scroll to the top of page after ${tries} tries. Scroll offset positon stuck at: ${scrollOffset}.`);
}
}
let getComparisonMode = (comparisonMode, sensitivity) => {
cy.task('logger', {type: 'info', message: `comparisonMode: ${comparisonMode}, sensitivity: ${sensitivity}`});
layoutData = {};
Expand Down
16 changes: 8 additions & 8 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "ISC",
"dependencies": {
"@smartbear/visualtest-cypress": "file:..",
"cypress": "^13.1.0",
"cypress": "^13.2.0",
"mochawesome": "^7.1.3",
"mochawesome-merge": "^4.3.0"
}
Expand Down

0 comments on commit fe48ad4

Please sign in to comment.