Skip to content
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

Cy.screenshot should only capture the app #181

Closed
jasonLaster opened this issue Jul 6, 2016 · 34 comments
Closed

Cy.screenshot should only capture the app #181

jasonLaster opened this issue Jul 6, 2016 · 34 comments
Labels
pkg/driver This is due to an issue in the packages/driver directory type: feature New feature that does not currently exist
Milestone

Comments

@jasonLaster
Copy link

The screenshot captures the entire chrome viewport. It should only capture the app.

Will this be fixed for free with 17?

pythagorean

@brian-mann
Copy link
Member

Yah this is a good idea - we will make this configurable.

@brian-mann brian-mann added this to the 0.17.x milestone Jul 19, 2016
@jhanink
Copy link

jhanink commented Aug 18, 2016

+1 Thanks!

@fvitas
Copy link

fvitas commented Sep 9, 2016

+1 Nice idea

@jennifer-shehane jennifer-shehane added type: feature New feature that does not currently exist and removed type: question labels Dec 16, 2016
@artursgirons
Copy link

It would be great if there would be options to toggle:

  • side-panel
  • toolbar
  • full-height screenshots

@jhanink
Copy link

jhanink commented Dec 16, 2016

Perhaps screenshot and video recording as well?

@brian-mann
Copy link
Member

If we did this for video it would kind of take away the entire point of knowing why your tests failed.

Screenshots make sense to hide away the Cypress UI elements.

However "full height" and application size scaling is where the problems come in with screenshot diffing (and is just one tiny aspect which makes this very difficult to do well).

For instance if one machine is running Cypress at a different resolution than another, while we correctly scale the application, the screenshot will also be scaled, which means the same screenshot at two different scales will in fact register as completely different and fail.

So the machine taking the screenshots would need to be "normalized" and cannot change even though Cypress insulates you from different sized screens, there is no way to normalize the actual pixels the browser decides to paint when scaled.

@jhanink
Copy link

jhanink commented Dec 16, 2016

Makes sense. Thanks!

@jennifer-shehane jennifer-shehane removed this from the 0.17.x milestone Feb 3, 2017
@eidam
Copy link

eidam commented May 8, 2017

+1 :)

@jennifer-shehane jennifer-shehane added the stage: investigating Someone from Cypress is looking into this label Oct 27, 2017
@2Fwebd
Copy link

2Fwebd commented Nov 10, 2017

Hi Cypress team,

Is there any ETA on this feature? That feature would be very nice.

@bahmutov
Copy link
Contributor

bahmutov commented Dec 7, 2017

Everyone, no need to comment with +1 - use the reaction buttons!

@cypress-io cypress-io deleted a comment from jackblackCH Dec 7, 2017
@cypress-io cypress-io deleted a comment from aamorozov Dec 7, 2017
@acthp
Copy link

acthp commented Dec 7, 2017

To monkey-patch it, maybe something like this:

var screenshot = file => () => {
	var reporter = window.parent.document.getElementsByClassName('reporter-wrap')[0],
		display = reporter.style.display;
	reporter.style.display = 'none';
	return cy.wait(1).screenshot(file).then(() => {
		reporter.style.display = display;
	});
};

Use like doSomething.then(screenshot('foo')).

Not sure if this is reliable, i.e. if the DOM will always have updated 'display' when the screenshot happens, but it has been working for me so far.

@remiroyc
Copy link

remiroyc commented Dec 8, 2017

+1 This feature would be great

@jordanyeo
Copy link

If possible, it would be great to hijack chrome's "Capture full size screenshot" functionality to get app-only, full height scaled screenshots. Not sure if this relies on native events, etc.

@chit786
Copy link

chit786 commented Dec 25, 2017

+1 for this feature.

@alisharaju94
Copy link

can we specify screenshot height and width in config.js file?

@jennifer-shehane
Copy link
Member

@alisharaju94 Not as of 1.4.1

@alindsay55661
Copy link

Implementing this feature would go a long way for those of us that can't wait for #495, or want to use a different screen diffing algorithm.

@alindsay55661
Copy link

And ideally there would be an option to capture only the viewport (the configured size, not the browser size).

@dallonf
Copy link

dallonf commented Feb 13, 2018

I don't mind having the sidebar there, but the amount of space given to the sidebar vs the app itself is kind of ridiculous:

apps page -- shows keys not including af keys

So even just customizing the width of the Cypress chrome would be very helpful.

@brian-mann
Copy link
Member

The amount of space is controlled by you - you can drag the reporter (next to the scrollbar) which will resize the application automatically.

@canakguen
Copy link

This ticket is pretty old, is there an ETA for this feature?

@jennifer-shehane jennifer-shehane added stage: in progress and removed stage: investigating Someone from Cypress is looking into this labels Mar 6, 2018
@jennifer-shehane jennifer-shehane added pkg/driver This is due to an issue in the packages/driver directory stage: ready for work The issue is reproducible and in scope and removed stage: in progress labels Apr 16, 2018
@maximalism2
Copy link

maximalism2 commented May 3, 2018

Here is the unstable way to capture a screenshot without Cypress's runner UI

Hi guys! I've made a snippet which extends the cy.screenshot command to make a screenshot without cypress's UI controls.

Pros: Does not require any changes in your tests' code, with this we get a shot with original page scale (pixel ration is 1x1) and there is no cypress's UI on the picture.

Cons: It causes visible flash while taking a shot. Since cy.screenshot is an asynchronous (as mentioned in docs: https://docs.cypress.io/api/commands/screenshot.html#Asynchronous) original UI will be hidden until the screenshot method will resolve.

Usage

Put this snippet in __PROJECT_ROOT__/cypress/support/commands.js and that's it. It will work in all the places where cy.screenshot method had been called before.
It behaves the same as original cy.screenshot command

const screenshotModeClassName = "screenshotMode";

const styles = `
  .screenshotMode .runner.container {
    background: #444;
    left: 0 !important;
  }

  .screenshotMode .runner.container header {
    display: none;
  }

  .screenshotMode .reporter-wrap {
    display: none;
  }

  .screenshotMode .runner.container .size-container {
    transform: none !important;
    margin-left: auto !important;
    margin-right: auto;
  }

  .screenshotMode .aut-iframe {
    box-shadow: none;
  }


  .screenshotMode .message-container {
    display: none;
  }

  .screenshotMode .iframes-container {
    top: 10px;
  }
`;

Cypress.Commands.overwrite("screenshot", (originalScreenshot, filename) =>
  cy.window().then(({ parent }) => {
    const { document } = parent;
    const screenshotModeLinkTagId = "screenshotModeStyles";

    if (document.getElementById(screenshotModeLinkTagId) === null) {
      const linkTag = document.createElement("style");
      linkTag.type = "text/css";
      linkTag.id = screenshotModeLinkTagId;
      linkTag.innerHTML = styles;

      document.head.appendChild(linkTag);
    }

    document.body.classList.add(screenshotModeClassName);

    return originalScreenshot(filename).then(() => {
      document.body.classList.remove(screenshotModeClassName);
    });
  })
);

@brian-mann
Copy link
Member

brian-mann commented May 3, 2018

@necinc awesome - thanks for that.

I've got good news and bad news for you.

The good news is that one of our devs has spent the last month working on this to its fullest capacity. It may initially look really simple to do, but there is a ton of complexity around taking the screenshot at the right time. For instance, we found that Chrome itself does not actually paint or render synchronously (even when it recalculates the box models) because it has internal optimizations. In other words, given your method, it is possible for the screenshot to happen and render the Cypress UI even though it's technically been hidden with CSS.

We also expanded the API's to not only hide the Cypress UI, and to also handle the scaling (as you've done), but also to capture full page screenshots (we automatically stitch together the UI) and have even added support for element screenshots. We also took into account devicePixelRatio.

Additionally - we also added support for "blacking out" elements and provide callback functions prior to taking the screenshot, so that you may modify the DOM to remove things like dynamic elements, sliding banners etc.

We also even took it upon ourselves to try to create more deterministic tests by preventing all asynchronous callbacks in your app from firing and even forcing animations to be disabled during the screenshot taking process. Phew...

The bad news is that it's not quite done yet - but it's sitting in a PR here: #1504

You can see it is quite... a lot... of work.

@maximalism2
Copy link

@brian-mann oh 🙀, there is really a ton of work already done there. I will subscribe to this PR.
So it looks like I should remove "Solution" from the title of my previous comment 🙂
Thanks for your reply!

@nwshane
Copy link

nwshane commented May 9, 2018

@brian-mann it's awesome you all are tackling this! do you have an estimate of when the new cy.screenshot API will be released?

@jennifer-shehane
Copy link
Member

@nwshane It's mostly all working right now in the PR, but we've found a slight performance regression with the screenshot that we have to work through.

@jennifer-shehane jennifer-shehane added this to the 3.0.0 milestone May 16, 2018
@jennifer-shehane
Copy link
Member

The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

@nwshane
Copy link

nwshane commented May 17, 2018 via email

@krzkaczor
Copy link

@jennifer-shehane any ETA for the next release? The last one pushed to NPM was 3 months ago :(

@brian-mann
Copy link
Member

Perhaps tonight...

@jennifer-shehane jennifer-shehane added stage: pending release and removed stage: ready for work The issue is reproducible and in scope stage: pending release stage: investigating Someone from Cypress is looking into this stage: needs investigating Someone from Cypress needs to look at this labels May 24, 2018
@brian-mann
Copy link
Member

Released in 3.0.0.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Dec 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg/driver This is due to an issue in the packages/driver directory type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests