red-toddler-79937
05/28/2022, 12:07 AMts
function isClosed () {
return new Cypress.Promise<boolean>((resolve) => {
cy.get('.landing-page').first().then(($e) => {
if ($e.text().includes('Restaurant Closed')) {
console.log("isClosed() <----", true);
return resolve(true);
} else {
return resolve(false);
}
});
});
}
let isClosedTrue = false;
specify('Unit test if restaurant is closed', async function() {
isClosedTrue = await isClosed();
});
crazyrapid-airport-48908
05/28/2022, 2:38 AMlittle-tiger-22751
05/28/2022, 3:42 AMlittle-tiger-22751
05/28/2022, 3:42 AMgray-kilobyte-89541
05/28/2022, 5:24 AMred-toddler-79937
05/28/2022, 9:15 AMancient-zoo-12002
05/28/2022, 9:56 AMgray-kilobyte-89541
05/28/2022, 1:01 PMasync
or await
in Cypress it probably does not do what you think it does. My examples don't include skipping the rest of the test if an element exists, because ... it is weird. But you can probably derive how to do it from the examples
js
cy.get('element selector').should(Cypress._.noop).then($el => {
if ($el.length) {
return
}
// other test Cypress commands
})
red-toddler-79937
05/28/2022, 1:07 PMgray-kilobyte-89541
05/28/2022, 1:15 PMred-toddler-79937
05/28/2022, 8:41 PMred-toddler-79937
05/28/2022, 8:42 PMts
let i = 0;
cy.get('.add-item-to-cart').each((e) => {
e.trigger('click');
i++;
})
.then(() => {
cy.get('.cart-size').first().should('have.text', ` ${i} `); // [here].
});
I changed my code to this.gray-kilobyte-89541
05/29/2022, 6:28 AMjs
// the count starts at zero
cy.contains('#count', 0)
// click each button
cy.get('ul button')
.click({ multiple: true })
// the displayed count should equal the number of buttons
.its('length')
.then((n) => {
cy.contains('#count', n)
})
See https://github.com/bahmutov/cypress-examples/commit/4eeb2af1f9ac56e14e9c70416d1c3a3b0cf94e00red-toddler-79937
05/29/2022, 11:30 AMnice-restaurant-99469
05/30/2022, 11:25 AMadventurous-branch-4501
05/30/2022, 1:30 PMmysterious-photographer-32876
05/30/2022, 3:09 PMmysterious-photographer-32876
05/30/2022, 3:10 PMmysterious-photographer-32876
05/30/2022, 3:14 PMimportant-park-97069
05/30/2022, 3:20 PMimportant-park-97069
05/30/2022, 3:20 PMcalm-nail-75610
05/31/2022, 7:24 AMechoing-painting-40909
05/31/2022, 7:55 AMrhythmic-butcher-48923
05/31/2022, 8:14 AMcurved-apple-36824
05/31/2022, 10:08 AMadventurous-branch-4501
05/31/2022, 3:44 PMelegant-dress-62146
05/31/2022, 3:45 PMscrollIntoView({force: true})
?adventurous-branch-4501
05/31/2022, 4:04 PMvictorious-midnight-45836
05/31/2022, 4:33 PMlet scrollToBottom = require("scroll-to-bottomjs");
describe("Lazy loading example", () => {
it("captures lazy loading images", () => {
cy.visit("https://sdk-test.percy.dev/lazy-loading");
cy.window().then(cyWindow => scrollToBottom({ remoteWindow: cyWindow }));
cy.percySnapshot("Lazy loading images");
});
});
bitter-apple-86316
06/01/2022, 5:51 AM