-
Notifications
You must be signed in to change notification settings - Fork 40
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
screenshot a particular element #56
Comments
Not a particularly useful comment, but just gotta say that this feature would be awesome. |
This is totally possible & something we have in the Ember SDK (but not any of the others). -- We'll need to do that after asset discovery since we're not sure what CSS / JS needs to be setup to snapshot a specific piece of the page. I tried a very hacky solution last night that uses our cy.percySnapshot('Pass scoped selector?', {
domTransformation: (documentClone) => {
let bioContainer = documentClone.querySelector('.bio-container');
documentClone.querySelector('body').innerHTML = bioContainer.innerHTML;
return documentClone;
}
}) Mostly because it was missing CSS needed to style properly. Also, that snippet makes the assumption that all resources / css is within the |
Tossing in that I'd love this as well! Being able to screenshot specific components would be really helpful |
Just to put this out there....you could also use a whitelisting technique rather than the blacklisting they suggest in the docs. Something like this global scss 👇 @media only percy {
* {
visibility: hidden;
}
.show-in-percy * {
visibility: visible;
}
}
|
@Robdel12 |
Hey @eyup-aydin! Any kind of mutation that happens to the DOM there will be what is rendered in Percy. So, if there are CSS selectors that dependent on DOM ordering, they could be broken in isolation. Or if a stylesheet is scoped out of the DOM, it won't be captured as an asset. The DOM that is returned from |
Hi, is there any news about specific element screenshot? |
Hey @wawagit! Nothing new here -- you would either use Percy CSS, |
Thanks @Robdel12 for your response. I'll give a try to the domTransformation option or isolate my component like you said. |
@Robdel12 |
Hi here a command (in typescript) I've created that easily make a screenshot on a particular element :) // cypress/integration/Test.test.ts
it('MyTest', () => {
cy.visit('/');
cy.get(`[data-cy=myData]`).percySnapshotElement('Snapshot Name');
}); // cypress/support/commands.ts
Cypress.Commands.add('percySnapshotElement', { prevSubject: true }, (subject, name, options) => {
cy.percySnapshot(name, {
domTransformation: (documentClone) => scope(documentClone, subject.selector),
...options,
});
});
function scope(documentClone: Document, selector: string): Document {
const element = documentClone.querySelector(selector);
documentClone.querySelector('body').innerHTML = element.outerHTML;
return documentClone;
} // cypress/types.d.ts
declare namespace Cypress {
// Precy.io ------------------------------------------------------
interface SnapshotOptions {
domTransformation: (documentClone: Document) => void;
}
interface Chainable {
percySnapshotElement(name?: string, options?: SnapshotOptions);
}
// ---------------------------------------------------------------
} |
@Robdel12 Any updates on this? The workarounds provided here are helpful for some scenarios, but not all. |
Hey everyone! Sadly, this isn't something that is going to be implemented in the near future. It's also not an SDK specific issue (its a product issue) so I'm going to close this (& related issues). Maybe we create a meta repo with a discussion topic for product issues? Not sure (cc @djones) With that said, this needs to be implemented in the rendering environment, where browsers easily can isolate & capture screenshots of elements (and/or the differ crops to the bounding box of the element). It's a huge rabbit hole trying to capture a subset of the DOM to send to the API for capture. You're going to miss parent>child CSS relationships, have missing assets, collapsed box model issues (when elements rely on sibling/parents for padding/margin), etc. I'm sure if anyone has attempted to use |
Hey, how can I import this in JS instead of TS. |
import '@percy/cypress'
/**
* Create percySnapshopElement
* @see {@link https://github.com/percy/percy-cypress/issues/56#issuecomment-792860231}
*/
Cypress.Commands.add('percySnapshotElement', { prevSubject: true }, (subject, name, options) => {
cy.percySnapshot(name, {
domTransformation: (documentClone) => scope(documentClone, subject.selector),
...options
})
})
function scope (documentClone, selector) {
const element = documentClone.querySelector(selector)
documentClone.querySelector('body').innerHTML = element.outerHTML
return documentClone
} |
This is a show-stopper to us. We might decide to go with Applitools instead of percy.io just because of this. I honestly liked Percy better but it's not supported and not even in your plans. |
Hi, could you please advice where will we add this and how is this code utilised please? |
Hey @p00rni! You can pass that as a snapshot option or in the percy config file: https://docs.percy.io/docs/percy-specific-css#snapshot-options--sdk-options |
Jusssst wanted to come by and drop a little hint that this is starting to be worked on. Don't wanna give an ETA on it, but it's going to ship within this quarter 😃 (its mostly infrastructure/differ work). I'll give another update here when it does ship! |
👋🏼 Upgrade to the latest CLI and you can now use the cy.percySnapshot({ scope: '.cookie-banner' }); Or in your Percy config file: version: 2
snapshot:
scope: '.cookie-banner' |
Hey, @Robdel12 great news, I will give it a try in the next few days as I'm overbusy at this moment. |
@Robdel12 I am trying to use this but is not available in the latest percy cypress lib? (3.1.2) |
@Phonesis I would make sure you're on the latest version of |
@Robdel12 There is an unfortunate compatibility issue with the Percy CLI lib and usage of the Cypress Orb in CircleCI. As a result, you cannot have the Percy/CLI lib installed in your repo (just the percy/cypress one) Is this something your team are aware of? See percy/cli#1047 |
Could we screenshot just a particular element?
The text was updated successfully, but these errors were encountered: