snapshots: Does waitForSelector happen after the JS in execute()? #538
-
Hi! Thanks for the great service, but I'm trying to keep up here and I have a question. {
name: ...,
url: ...,
execute() {
// open each of the collapsed results
const accordions = document.querySelectorAll('.c-accordion-ui__trigger')
for (const a of accordions) { a.click(); }
},
waitForSelector: ".customClass"
} How my page works is that, after one of those collapsed elements are clicked, it triggers a chain of events that eventually results in a When I run @percy/cli to take snapshot it reports an error that it failed to find I'm curious as to whether this should work as described, or if this is user error or what. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @thecristen! We haven't documented this yet (it's quite new and we've been occupied with a couple networking bugs since #513). We pass a module.exports = async () => {
return [
{
name: 'example 1',
url: 'https://percy.io',
execute: {
async beforeResize({ waitFor }) {
await waitFor(() => !!document.querySelector('.hero-main-image'), 5000);
}
}
}
];
}; Or using your code: [{
name: '...',
url: '...',
async execute({ waitFor }) {
// open each of the collapsed results
await waitFor(() => !!document.querySelector('.customClass'), 5000);
const accordions = document.querySelectorAll('.c-accordion-ui__trigger')
for (const a of accordions) { a.click(); }
},
}] |
Beta Was this translation helpful? Give feedback.
Hey @thecristen! We haven't documented this yet (it's quite new and we've been occupied with a couple networking bugs since #513). We pass a
waitFor
function to execute, so you can make sure the page state is what you'd expect before executing your JavaScript. For example:Or using your code: