Closed jennifer-shehane closed 1 year ago
I can confirm, that this also happens on Electron (found it on Electron 80 and Cypress 4.3.0)
@jennifer-shehane should we remove this functionality from the docs until it is fixed? I think its causing a lot of people to spend time debugging when it is a known issue.
Or at least add a note to the docs about this bug. And I'm happy to submit a PR with a doc change if you think that is a good idea.
That's some impressive issue documentation. I'll add that the misalignment is exacerbated when the test is not run headless. It also happens in Chrome 85, Cypress 5.2.0.
During non-headless playback, the degree of misalignment is influenced by:
I'm especially interested in this fix because I'm using blackout as a shortcut for visual testing. Black out the non-deterministic bits of the screen, take the shot, and move on. Consistent function of the blackout option is crucial for this.
I am seeing this issue with Cypress 6.2.0 using Electron 87 and Chrome 89. I am trying to use the functionality for visual testing.
This issue is also present in Firefox 78 with Cypress 6.0.1
I can confirm this issue. Most of the elements I try it with the black box is not properly covering them. With some elements it's not even working, for example my position fixed header
is not blacking out at all, which is for which I would use this feature most.
Now I tried hiding the elements manually before taking the screenshot. But I realized cypress opens a new window or something like that to take the screenshot, thus this hack is not working.
My questions is why is there an algorithm to calculate such a black box positions? Why not just take the DOM snapshot, add a new div inside the target elements with position absolute, width height 100%, and background black; and after that take the screenshot? @jennifer-shehane
Actually never mind. I have found the following to work pretty well as an alternative:
Cypress.Commands.add('withHidden', (selector, callback) => {
cy.get(selector).invoke('attr', 'style', 'display: none');
callback();
cy.get(selector).invoke('attr', 'style', '');
});
cy.withHidden('header', () => cy.get('.element-to-captur').screenshot());
Any updates here? Seems making screenshots with Cypress is a big mess - we are trying to use it for our snapshot testing and with each build we are receiving different image sizes even if nothing was changed in code and the same Docker container was used.
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.
This issue has been closed due to inactivity.
Current behavior:
This issue is 2 fold, but overall demonstrates that the algorithm for calculating the blackout area of a screenshot is not thorough enough to cover all situations.
1. Chrome versions < 78
Below, the screenshot should black out the red area, but as you can see in Chrome 77 it is not.
I also tested this back to version Cypress 3.2.0 and the issues exhibits on all versions of Cypress.
Chrome 77.0.3865.90
Chrome 78.0.3904.108
2. Viewport size calculations
Below, the screenshot should black out the red area, but as you can see in smaller viewport sizes it is not.
1400x1080
1000x660
850x500
450x200
Desired behavior:
The DOM element specified should be blacked out on all Chrome versions at all viewport sizes
Steps to reproduce: (app code and test code)
I tried several variations of content, removing the lorem ipsum (so that scroll happens) will make the blackout not work or work under certain circumstances, but the below example will fail in all examples specified above.
index.html
spec.js
Versions
Cypress 3.2.0 - 3.7.0 (all tested versions) Chrome 77.0.3865.90