https://cypress.io logo
Join Discord
Powered by
# help
  • w

    wonderful-author-91008

    05/01/2022, 9:32 PM
    Hi Guys, I noticed with cypress, it identify the element correctly in grid, but it click on wrong element, it console the correct element in output, when it click, it clicks on next element in Grid. Does anyone else faced this? I added cy.wait(1000), it started working fine, but I want to exclude wait. Does anyone face this issue please? Thank you
  • g

    gentle-accountant-4760

    05/02/2022, 2:58 PM
    Hello people! Im currently having issue using "window:before:load" where I am using this code:
    Copy code
    js
    Suite('Test Cypress', () => {
      before(() => {
        prepare();
      });
    
      Scenario('Test', () => {
        Given('works', () => {
          const bomMessage = cy.stub().as('bom');
    
          cy.on('window:before:load', (win) => {
            win.addEventListener('message', (event) => {
              if (event.data.event === 'BOMComputationReady') {
                bomMessage(event.data);
              }
            });
          });
    
          cy.visit('https://wwww.google.com');
    
          cy.get('@bom', { timeout: 30_000 }).should('be.calledOnce');
        });
    Inside my prepare(); is
    Copy code
    js
    cy
        .visit('https://google.com/barry', { auth: username: 'helloworld', password: 'testing');
    
      cy.get('div.hello_world')
        .window()
        .then((window) => {
          Object.assign(ProvisionConfig, (window).provisionConfig);
        });
    the script works fine I comment away the "prepare()" but if I keep it, then the
    cy.get('@bom', { timeout: 30_000 }).should('be.calledOnce');
    will never be called but it works if I comment the
    prepare()
    - Anyone knows the reason?
  • g

    gentle-accountant-4760

    05/02/2022, 6:54 PM
    Anyone? 🙂
  • m

    magnificent-finland-58048

    05/02/2022, 7:04 PM
    sorry, no experience with the BDD plugin Is it possible to repro this in a repository?
  • g

    gentle-accountant-4760

    05/02/2022, 7:05 PM
    Not sure how I can reproduce it to you really 😦 Its more of a question if its possible to use the
    window:before:load
    if you do a before() call. beacuse when I do the prepare() call, then the
    window:before:load
    doesn't work for me 😦
  • m

    magnificent-finland-58048

    05/02/2022, 7:07 PM
    100% sure it is possible it's the only area I have ever used it in
  • g

    gentle-accountant-4760

    05/02/2022, 7:09 PM
    Ah crap, yeah so im not sure if it has to do with visit in the prepare that causing it. Because again, if I remove the prepare call then it works fine. - Hence why I think its something with cy.visit before you call the cy.on
  • g

    gray-kilobyte-89541

    05/02/2022, 7:25 PM
    well, if you visit the app before the you attach event listener to it, it is too late, and the initial calls will be "lost", right
  • g

    gentle-accountant-4760

    05/02/2022, 7:26 PM
    But if you look at the code, I do another visit after the event listener as well
  • g

    gray-kilobyte-89541

    05/02/2022, 8:29 PM
    then it is hard to say what is going one without a fully reproducible example one can run
  • g

    gentle-accountant-4760

    05/02/2022, 9:03 PM
    I see, i'm not sure how I can create a application to reproduce this error more than just showing the code I have provided :/
  • w

    wonderful-author-91008

    05/03/2022, 2:43 AM
    Hi Guys, I noticed with cypress, it identify the element correctly in grid, but it click on wrong element, it console the correct element in output, when it click, it clicks on next element in Grid. Does anyone else faced this? I added cy.wait(1000), it started working fine, but I want to exclude wait. Does anyone face this issue please? Thank you
  • g

    gentle-accountant-4760

    05/03/2022, 7:39 AM
    I was able to imrpove my code to do sometihng like:
    Copy code
    ts
    Given('works', () => {
      const bomMessage = cy.stub().as('bom');
    
      cy.visitWithAuth('https://helloworld.com');
    
      // Wait for BOM to be loaded
      cy.window().then((win) => {
        win.addEventListener('message', (event) => {
          if (event.data.event === 'BOMComputationReady') {
            bomMessage(event.data);
          }
        });
      });
    
      cy.get('@bom').should('be.calledOnce');
    });
    My question is if its possible to somehow refactor it and skip the cy.stub()? and to continue once the event is found?
  • g

    gray-kilobyte-89541

    05/03/2022, 10:05 AM
    what do you mean: "continue"?
  • g

    gentle-accountant-4760

    05/03/2022, 10:08 AM
    continue the test 😁but i think using stub is best option. I could use some variables checks but then it can be some issues when it comes to async/syn'
  • g

    gray-kilobyte-89541

    05/03/2022, 12:57 PM
    not sure what you intend to do, but here are a few stub and spy examples https://on.cypress.io/stubs-spies-and-clocks and https://glebbahmutov.com/cypress-examples/commands/spies-stubs-clocks.html
  • h

    hundreds-father-43644

    05/03/2022, 4:12 PM
    Hi guys. I'm trying intercept a PATCH request but dont work. I don't know why. Sometimes work, sometimes don't work. I use react-query library to make my api request
  • m

    magnificent-finland-58048

    05/03/2022, 7:01 PM
    what's the intercept command you're using?
    cy.intercept('PATCH', '**/coupons/*')
    ? you can try a regex too
    cy.intercept('PATCH', /coupons/whateverFunStuff/$)
  • h

    hundreds-father-43644

    05/03/2022, 7:11 PM
    I use:
    Copy code
    describe('Edit coupon good alerts', () => {
      const affiliatesUrl = Cypress.env('api_url') + Cypress.env('get_affiliates')
      const affiliateCategoriesUrl = Cypress.env('api_url') + Cypress.env('coupon_affiliate_categories')
      const storesUrl = Cypress.env('api_url') + '/stores*'
      const getCoupom = Cypress.env('api_url') + "/coupons/385162-2"
    
      beforeEach(() => {
        cy.clearCache()
        cy.setFirebaseCookies()
        cy.intercept('PATCH', getCoupom, { statusCode: 201, delay: 5000 }).as('editCoupon');
        cy.intercept('GET', storesUrl, { fixture: 'store/good.response.json' }).as('store')
        cy.intercept('GET', affiliatesUrl, { fixture: 'affiliate/good.response.json' }).as('affiliates')
        cy.intercept('GET', affiliateCategoriesUrl, { fixture: 'affiliate-categories/good.response.json' }).as('affiliateCategories')
        cy.intercept('GET', getCoupom, { statusCode: 201, fixture: 'coupon/coupon.json' }).as('coupon');
        cy.visit('/cupons/385162-2')
        cy.wait(['@coupon', '@affiliateCategories', '@affiliates'])
      })
    
      afterEach(() => {
        cy.clearCache()
      })
      
      it('Should show success alert when edit Coupon success', () => {
        cy.get('[data-cy="coupon-id"]').type('TESTE123450192TESTE')
        
        cy.get('[data-cy="coupon-save-button"]').click()
        cy.wait('@editCoupon')
        
        cy.get('[data-cy="snack-alert"]').invoke('text').should('eq', 'O Cupom foi editado com sucesso!')
      })
    })
  • l

    little-france-10142

    05/03/2022, 10:40 PM
    Would appreciate some help. I posted last week. I have a similar issue. I am just trying to get the button to return true on click and cypress to confirm that true got passed to it. I feel like I'm missing something insanely simple.
    Copy code
    it('renders an active base button', () => {
      mount(
        <Button
          onClick={() => {
            return true
          }}
        >
          Click me
        </Button>
      )
    
      cy.get('button').click().should('be.true')
    })
  • g

    gray-kilobyte-89541

    05/04/2022, 12:05 AM
    Copy code
    js
    import React from 'react'
    import { mount } from '@cypress/react'
    
    const Button = ({ onClick, children }) => (
      <button onClick={onClick}>Click me</button>
    )
    
    it('renders an active base button', () => {
      mount(<Button onClick={cy.stub().as('click')}>Click me</Button>)
    
      cy.get('button').click()
      cy.get('@click').should('have.been.calledOnce').invoke('resetHistory')
      cy.get('button').click().click()
      cy.get('@click').should('have.been.calledTwice')
    })
  • l

    little-france-10142

    05/04/2022, 12:18 AM
    @gray-kilobyte-89541 Oh man this is perfect! So it's the
    cy.stub()
    and
    '@click'
    concepts I was not aware of. Thank you!
  • g

    gray-kilobyte-89541

    05/04/2022, 12:21 AM
    Take a look at https://glebbahmutov.com/blog/my-vision-for-component-tests - the component mounting syntax is a little bit different now, but it kind of shows what is the goal for the component testing was/is
  • h

    hundreds-father-43644

    05/04/2022, 12:20 PM
    I see some weird action in intercept. Somes seconds after crash test the cypress intercept a request. Why this is happen?
  • l

    little-france-10142

    05/04/2022, 1:12 PM
    This is great! It looks like Cypress component testing is the next big thing.
  • l

    little-france-10142

    05/04/2022, 1:13 PM
    I just realized there's a component testing channel and all this should probably be over there huh?
  • t

    thousands-pharmacist-63522

    05/04/2022, 6:44 PM
    did any one use cypress-msw-interceptor https://github.com/deshiknaves/cypress-msw-interceptor
  • t

    thousands-pharmacist-63522

    05/04/2022, 6:45 PM
    it looks awesome the ability to Updating a mock is sweet
  • w

    wonderful-author-91008

    05/04/2022, 8:26 PM
    Hi Guys, I noticed with cypress, it identify the element correctly in grid, but it click on wrong element, it console the correct element in output, when it click, it clicks on next element in Grid. Does anyone else faced this? I added cy.wait(1000), it started working fine, but I want to exclude wait. Does anyone face this issue please? If I remove wait it click on the next element. cy.get('[data-cy="invoiceGridData"]').within(() => { cy.wait(1000); cy.contains(".lt-list-item-title", "Cypress").click({ force: true }); }
  • m

    melodic-king-62847

    05/05/2022, 9:44 AM
    Hello world!! I'm having this error and I don't how to fix it... My web project and that localhost runs correctly but cypress couldn't detected it so then all tests I've made fails because it can't enter to that link. Please, could anyone help me????
1...596061...252Latest