https://cypress.io logo
Join DiscordCommunities
Powered by
# e2e-testing
  • f

    flaky-airport-12178

    09/05/2022, 7:01 AM
    Hi team, Do you know whether we can combine the HTML tag: For example: cy.contains('span','A) cy.contains('label','A') I want to find the element that contains span or label tag with text A => cy.contains('span | label','A')
  • m

    mysterious-motherboard-13344

    09/05/2022, 7:27 AM
    yes ....you can use cy.contains('span', 'A') OR cy.get('span').contains('A')
  • f

    flaky-airport-12178

    09/05/2022, 7:28 AM
    No, I want to get all elements with label and span tag html in one command
  • c

    colossal-farmer-50435

    09/05/2022, 7:48 AM
    No I want to get all elements with label
  • f

    fierce-engineer-40904

    09/05/2022, 2:29 PM
    Hello, does anyone have a clue how to help me here?
    Copy code
    js
      it('Should open widget and do a preflight', () => {
        cy.get('[data-cy="twilio-widget"]').click({ force: true })
        cy.intercept(
          'GET',
          `https://INSERTURLHERE/token`,
          (req) => {
            const parsedToken = twilioVoiceEntity(req.body.token)
            const preflightTest = Device.runPreflight(parsedToken)
    
            preflightTest.on('completed', (report) => {
              console.log('report', report)
            })
          },
        )
      })
    I want to see the console log of the report in cypress and then assert if the test failed or passes.
  • b

    bitter-fountain-36713

    09/05/2022, 2:32 PM
    If you are looking to intercept a call, that should be done before the call is made, ie before a click or a page redirect/load.
  • f

    fierce-engineer-40904

    09/05/2022, 2:33 PM
    so all I would need to do is to create a call after this intercept that calls the URL specified in the interceptor?
  • f

    fierce-engineer-40904

    09/05/2022, 2:34 PM
    But running this test does the call in my test?
  • d

    delightful-microphone-80931

    09/05/2022, 2:43 PM
    Hi all, is there a shorter way of validating an array in the body response?
  • f

    fierce-engineer-40904

    09/05/2022, 3:00 PM
    is there a command to access the console.log output? I want to read what my previous network fetch outputted to the console
  • b

    bitter-fountain-36713

    09/05/2022, 3:05 PM
    Move your intercept before you click on your twilight widget.
  • n

    nutritious-army-46708

    09/05/2022, 3:26 PM
    I am new to cypress. Can I post my question here?
  • n

    nutritious-army-46708

    09/05/2022, 3:36 PM
    The test's domain is "exams.com/courses/XXXX"(xxxx is the course's #). After clicking the "buy course" button, the domain will be "payment.com".We filled in the payment information, and click the "pay" button, the webpage should be "exams.com/purchased_courses/XXXX". Now I used cy.origin: it("buy courses",()=>{ .........//click the "buy course" button cy.origin("payment.com",()=>{ .........//fill in the payment information cy.get('.submitButton-IconContainer').click() //click the "pay" button }) } ) Issue is: when running the testing, the webpage "exams.com/purchased_courses/XXXX" slashed a second, and finally, the webpage stays in "exams.com/courses/XXXX". Question: How can I let the testing shows "exams.com/purchased_courses/XXXX"? Thank you! env: cypress 10.X.X typescripe node.js 18.8.0
  • g

    gray-kilobyte-89541

    09/05/2022, 6:39 PM
    something like this https://glebbahmutov.com/blog/capture-all-the-logs/
  • f

    flaky-airport-12178

    09/06/2022, 2:31 AM
    expect(res.body.im....slice().deep.equal([])
  • b

    bitter-fountain-36713

    09/06/2022, 3:26 AM
    You can use cy-spok for response validations
  • g

    gray-kilobyte-89541

    09/06/2022, 11:07 AM
    Josh has "spoken"
  • m

    melodic-ocean-83158

    09/06/2022, 1:19 PM
    you can add all your string parameters on a array and do a for each loop
  • c

    chilly-quill-34099

    09/06/2022, 1:31 PM
    I would like to reuse several tests for the header, footer, side menu etc. of my websites for different URL-routes of my website. I want to minimize code duplication. I tried to create functions with the
    commands.ts
    file but the problem is: 1. My storage
    cy.restoreLocalStorage
    logic does not work (I have an microsoft authentification, which needs to be saved in the local storage) 2. The tests inside the function are being recognized as independent tests. There is only one single file. I can't find a way to reuse the cypress tests using different
    visit
    paths as parameter. Is there a best practice, which someone can point me to?
  • m

    melodic-ocean-83158

    09/06/2022, 1:40 PM
    I don't know if I understood well. You're saying you lose authentication when the second test runs, right?
  • m

    melodic-ocean-83158

    09/06/2022, 1:40 PM
    For this reason it cannot run the others?
  • m

    melodic-ocean-83158

    09/06/2022, 1:42 PM
    The contents of localStorage must be re-entered with each test. That is, your function that adds authentication must be in a BeforeEach.
  • c

    chilly-quill-34099

    09/06/2022, 2:06 PM
    You are right, I was restoring the local storage in the outer test suite, which was calling the function with the header tests. These needed a
    beforeEach
    as well, with the
    restoreLocaleStorage
    to have a valid authentication. So point 1 is working 🙂 Thank!!! @melodic-ocean-83158
  • c

    chilly-quill-34099

    09/06/2022, 2:18 PM
    Regarding point 2: In the pic you will see that there is no insight regarding the test of the function. Furthermore the function is never exiting, even though the timer stops.
    Copy code
    ts
    export function checkHeader(url: string): any {
      const currentUrl = url;
      describe('App Header', () => {
        beforeEach(() => {
          cy.restoreLocalStorage('logged in');
        });
    
        it('... appears', () => {
          cy.visit(currentUrl).get('[data-testid="app-header"]');
        });
        // ... more tests
      });
    }
  • c

    chilly-quill-34099

    09/06/2022, 2:33 PM
    I am calling the
    checkHeader
    function inside a
    it()
    -function, inside the test suite. The logic itself seems to work looking on the green check marks and also the interactive Preview of the Cypress UI. But not being able to get responses is a major disadvantage.
  • c

    chilly-quill-34099

    09/06/2022, 2:34 PM
    Do I have to make chainable or something? New to Cypress so these concepts aren't familiar to me 😅
  • g

    gray-kilobyte-89541

    09/06/2022, 2:38 PM
    you could start by reading intro to Cypress to get a sense of using the existing commands https://on.cypress.io/introduction
  • m

    melodic-ocean-83158

    09/06/2022, 2:40 PM
    This seems to me a conceptual error. 1 file != 1 test. A file can have multiple tests. Each "it" in your file is a different test. A test can have multiple assertions within it.
  • m

    melodic-ocean-83158

    09/06/2022, 2:41 PM
    From what you said, it looks like you need a structure like this:
  • m

    melodic-ocean-83158

    09/06/2022, 2:43 PM
    You are calling a test sequence inside another test, this shouldn't work.
1...959697...192Latest