Category : cypress

I’m having some trouble stub’ing out Stripe from my tests CartCheckoutButton.ts import React from ‘react’ import { loadStripe } from ‘@stripe/stripe-js’ import useCart from ‘~/state/CartContext’ import styles from ‘./CartCheckoutButton.module.scss’ const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY) const CartCheckoutButton = ({}: TCartCheckoutButtonProps) => { const { cartItems } = useCart() const handleCheckOutOnClick = async (event) => { const { ..

Read more

Using Cypress with TypeScript. My code goal is to extract all URLs in /sitemap.xml and cy.request() each URL for status 200. This version works: describe(‘Sitemap Urls’, () => { let urls: any[] = []; beforeEach(() => { cy.request({ method: ‘GET’, url: ‘https://docs.cypress.io/sitemap.xml’, }).then(response => { expect(response.status).to.eq(200); urls = Cypress.$(response.body) .find(‘loc’) .toArray() .map(el => el.textContent); cy.log(‘Array ..

Read more

I have the following trackers blocked during Cypress tests. Cypress keeps on logging these urls in the test runner logs which is ugly and interferes with other useful log messages and assertions and increases scrolling/searching effort from the user. Is there a way to disable logging of these urls in the test runner and console ..

Read more

I’m using cypress-cucumber-preprocessor I’m using Sauce Labs demo app for automation testing, https://www.saucedemo.com/ I have a step that is supposed to visit the homepage that has the following url: https://www.saucedemo.com/inventory.html I have the baseUrl defined in my cypress.json as shown below: cypress.json { "baseUrl": "https://www.saucedemo.com/", "testFiles": ["**/*.{feature,features}"], "chromeWebSecurity": false, "env": { "fixturesBaseDir": "test_data_files/" } } ..

Read more

I run Windows10, I have a project made on Cypress and I want to log the test results both on a file AND on console: I tried just printing on a file, using in my package.json this script: "scripts": { "open": "./node_modules/.bin/cypress open", "runheadless": "./node_modules/.bin/cypress run –headless –browser chrome –spec ‘cypress/integration/webpages.spec.js’ > cypresstest.log" } And ..

Read more

Note: this question is not related to test retries, this is about running the whole spec again from beginning, not about retrying a failed it() block within a spec. According to Cypress docs: https://docs.cypress.io/guides/guides/module-api#cypress-run you can rerun failing spec/specs after the catching the failures of cypress.run() process. I cannot find a way to do so. ..

Read more

I need to update a global variable of a call from inside a then function. Can some one help me on how to achieve it. Below is the code snippet: let valBefore=-1 let valAfter=-1 class abc{ helperMethod(cntr){ if(cntr>0){ cy.get(C).find(D).then(($el)=>{ return $el.length //NOT ABLE TO RETURN THIS VALUE }) } } method1(){ cy.get(A).then(($elA)=>{ var cntr = ..

Read more

I want to come out of a nested if loop if a particular condition is met. Below is the snippet:- cy.get(A).then(()=>{ do{ cy.get(B).each(()=>{ switch(C){ case "1": if(some condition){ this.method1() return false //THIS IS NOT BREAKING THE OUTERMOST THEN LOOP !!!!! } method2() break case "2": if(some condition){ this.method3() return false } method4() break } //switch ..

Read more

Hi, I want to improve this code to avoid repetition ! any ideas ? const captureEmailModal = email => { When(`I type ${email.fullName}`, () => { cy.wait(1000) cy.get(email.dataCyModalFullName).should(exist) .type(email.fullName) .invoke(‘val’) .should(‘match’, /^(?! )[A-Za-zs]+$/) cy.get(email.dataCyModalEmail).should(exist) .type(email.email) .invoke(‘val’) .should(‘match’, /^(([^<>()[].,;:[email protected]"] cy.get(email.dataCyModalPhone).should(exist) .type(email.phone) .invoke(‘val’) .should(‘match’, /^[0-9]+$/) .should(‘have.length’, 10) }) Just the email.dataCyFaqFullName / email.dataCyFaqEmail and email.dataCyFaqPhone who changes ..

Read more