-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Taking screenshots during cypress open
versus cypress run
result in different screenshot sizes
#3324
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Ok, so the base code in question is something like this: const visaulDiffWidth = 1280;
const visualDiffHight = 720;
options.capture = "viewport";
cy.viewport(visaulDiffWidth, visualDiffHight);
cy.document().then((doc) => {
cy.wrap(subject, { log: false })
.screenshot(screenshotTitle, options)
.then(() => {
cy.viewport(
Cypress.config("viewportWidth"),
Cypress.config("viewportHeight")
);
}) When you chain |
This comment has been minimized.
This comment has been minimized.
@jennifer-shehane I can verify the behaviour regardless of any custom commands being used: it('test', () => {
cy.visit('https://www.google.com')
cy.viewport(1280, 768)
cy.screenshot('google')
}) Running Setting I'm running: |
Could be display scaling. I don't know any macs that don't do display scaling due to their high pixel density screens. |
Yup. Seeing the same here. Very weird and inconsistent, BTW. Not sure I can see any logic, but sometimes the screenshot is the size of the viewport, and sometimes just the size the window is opened on. Interestingly enough, this sometimes happens in the runner too. |
I'm having this same issue. Running the specs with
Any ideas? 😕 |
@jennifer-shehane do we have any updates on this issue? Other folks have reported this issue in the |
same here @edelgado maybe @chrisbreiding or @brian-mann could give us a hand here? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hey @edelgado you mentioned that your issue is that during This issue of the screenshots being smaller in I can recreate this behavior from this test: it('test', () => {
cy.visit('https://www.google.com')
cy.viewport(1280, 768)
cy.screenshot('google')
}) In If I do The issue appears to be in the scaling as described in this comment: #2102 (comment) I suppose this is technically a separate problem from #2102, but all of this is a larger problem with how we do scaling and display size calculations overall. |
While I totally understand the issue, I find it weird that screenshots took during It's a bit against your fast and easy from your tagline "Fast, easy and reliable testing for anything that runs in a browser." 😔 |
I will also state I am hitting this issue now where |
In my case the problem was with the Retina display on Macbook. I was getting exactly twice as big screenshots when I used |
@valentindotxyz Yes, this is exactly what we're advocating. During So I could run my application tests on my Mac at resolution 2880x1800 taking screenshots to save to diff against, then Gleb opens up
To only take screenshots during Cypress.Commands.overwrite('screenshot', (originalFn, subject, name, options) => {
// only take screenshots in headless browser
if (Cypress.browser.isHeadless) {
// return the original screenshot function
return originalFn(subject, name, options)
}
return cy.log('No screenshot taken when headed')
})
// only takes in headless browser
cy.screenshot() |
I would never do something like this to you @jennifer-shehane |
This comment has been minimized.
This comment has been minimized.
I resolved this by slightly modifying @0xIslamTaha code. In accordance with the supported args: In on('before:browser:launch', (browser = {}, launchOptions) => {
if (browser.name === 'chrome') {
launchOptions.args.push('--window-size=1440,900');
return launchOptions
}
if (browser.name === 'electron') {
launchOptions.preferences['width'] = 1440;
launchOptions.preferences['height'] = 900;
return launchOptions
}
}) Mainly the electron part we are interested in because when operating as a Perhaps make these a potential cypress environment config. |
I don't see any way to pass the |
I think this is the issue related to the retina screen on Macs that scale every screenshot to 2x resolution. Cypress has an official solution: https://docs.cypress.io/api/plugins/browser-launch-api.html#Set-screen-size-when-running-headless In general, the physical device where you take the screenshot on will have an impact on the screenshot. For example, the color profile of the monitor will affect the actual color rendered. |
cypress open
versus cypress run
result in different screenshot sizes
@jennifer-shehane I don't think this statement is actually correct in a part where it says |
I had the same problem as you though. launchOptions.args.push("--window-size=1536,960"); I recommend you to try the command solved it for me. |
The fix that was implemented to not need the launch options did not actually fix the problem and the work-around is still needed but no longer works. When I set the viewport and then call the screenshot command with viewport specified, it should take a screenshot with the exact viewport size I specified and not limit it to my monitor's resolution/scaling on axis that exceeds that value. Even if the image is scaled a few pixels in either direction, the size must match. The behavior seems different across platforms (linux/OSX) as well. Headed and headless mode do not work as intended. |
The --force-device-scale-factor=1 fix works for Chrome (though I have to look at the non-Retina browser when I open it in UI mode). And there is no such option for electron, which results in huge screenshot sizes on the Mac. (even in headless mode). Don't you think it would be good to have an option for desirable screenshot sizes? |
Current behavior:
Screenshots are not taken at the height and width set prior for the viewport even when using the setting the capture to be the
viewport
. This interestingly only happens if you trigger the test from the runner and not if you trigger the test from terminal.Desired behavior:
For the screenshot height and width to match the height and width that the viewport is set to both when the test is triggered by the runner and when the test is triggered in the terminal.
Steps to reproduce: (app code and test code)
cypress run --spec '<path to test file>'
(Screenshot will match the viewport)Versions
Cypress 3.0.0
macOS Mojave 10.14.2
node v8.11.4
yarn 1.5.1
The text was updated successfully, but these errors were encountered: