https://cypress.io logo
Join Discord
Powered by
# e2e-testing
  • e

    early-optician-55799

    08/23/2022, 5:31 PM
    And as we speak about environment variables... I've found some documentation about storing hardcoded environment variables (the one I've linked above to juanrepo), but I would like to do something similar, yet not with a variable I've hardcoded before but with a variable that will be set based on response from intercepted api request (I want to save one parameter from the response and reuse later). Please, just, bear in mind I'm new to Cypress, javascript, typescript (which I'm obliged to use instead of classic js) and even coding in general, so I might be missing basic concepts So, after hours of struggling I've managed to intercept a value from one parameter (applicationId) in order to use it later in cypress request event (cy.request function) but only with .then function
    Copy code
    cy.intercept("POST", "**/application").as("startApplication");
      cy.get("@startApplication")
        .its("response")
        .then((response) => {
          const applicationId = response.body.applicationId;
          cy.request({
            method: "POST",
            url: `${apiBaseUrl}/e2e/application/${applicationId}`,
          });
        });
    However, I need to use this applicationId few more times during my e2e tests in order to call other api endpoints later... I don't want to redo the same thing each time, meaning cy.get + .then (cy.request). I would like to do cy.request right off the bat with this applicationId I already managed to get... btw, for what I care it doesn't have to be an environmental variable, it might be alias, const or whatever that would let me nicely reuse that applciationId later 🙂
  • m

    melodic-ocean-83158

    08/23/2022, 8:37 PM
    do it first: const user = Cypress.env('user')
  • m

    melodic-ocean-83158

    08/23/2022, 8:38 PM
    then use the object in your action: .type(user.username)
  • m

    melodic-ocean-83158

    08/23/2022, 8:43 PM
    if you look closely, you will see that in the blog the author passes the whole object as a parameter, not just a key. You need to resolve the cy.env call first and then access the object's attributes
  • c

    chilly-queen-22182

    08/23/2022, 8:54 PM
    Thanks @acceptable-hamburger-48790 :-), thats exactly I am looking for.
  • h

    hallowed-lighter-4305

    08/23/2022, 9:10 PM
    Gracias @melodic-ocean-83158 I just implemented it that way and it throws me this error I have the code in this way in the Commands.js file Cypress.Commands.add('login', () => { const user = Cypress.env('user') cy.log(
    Iniciar sesión en ${Cypress.env('environment') ? Cypress.env('environment') : 'local'} environment
    ) if (Cypress.env('environment') === 'pre') { Cypress.env('user', Cypress.env('prelogUser')) } else if (Cypress.env('environment') === 'prod') { Cypress.env('user', Cypress.env('prodUser')) } else if (Cypress.env ('environment') === 'dev') { Cypress.env('user', Cypress.env('devUser')) } cy.visit('/login')
  • m

    melodic-ocean-83158

    08/23/2022, 9:34 PM
    it works.
  • m

    melodic-ocean-83158

    08/23/2022, 9:34 PM
    Ensure your cypress.env is like this
  • h

    hallowed-lighter-4305

    08/23/2022, 10:09 PM
    Thank you very much @melodic-ocean-83158 , do you implement this code in the commands.js? and in the spec.cy.js file how do you implement it?😅
  • q

    quiet-breakfast-31238

    08/23/2022, 10:10 PM
    Hi everyone. I've just updated Cypress to 10.6 and Cypress doesn't show my tests but it founds 2 files. Who can please help me?
  • m

    melodic-ocean-83158

    08/23/2022, 10:14 PM
    @hallowed-lighter-4305 this code was in the .spec file
  • m

    melodic-ocean-83158

    08/23/2022, 10:16 PM
    I didn't use the command file. But if you paste this code in your command, you can simply call "cy.login()" on your .spec file and he will execute
  • m

    melodic-ocean-83158

    08/23/2022, 10:17 PM
    you update from 9.x version? have you already put the "cy" in the filename? like "test.spec.cy.js"?
  • q

    quiet-breakfast-31238

    08/23/2022, 10:19 PM
    Thanks for the answer. Yes, from 9.x. No, I didn't put it, just automatically migrated
  • m

    melodic-ocean-83158

    08/23/2022, 10:20 PM
    try to rename manually with ".cy.js"
  • q

    quiet-breakfast-31238

    08/23/2022, 10:21 PM
    Ok, thx
  • q

    quiet-breakfast-31238

    08/23/2022, 10:23 PM
    Doesn't help
  • m

    melodic-ocean-83158

    08/23/2022, 10:31 PM
    I believe something is wrong with your cypress.config files. But I don't have any migrated project here to compare
  • q

    quiet-breakfast-31238

    08/23/2022, 10:31 PM
    Ok, thanks. Maybe somebody else will help.
  • h

    hallowed-lighter-4305

    08/23/2022, 11:09 PM
    @melodic-ocean-83158 thank you very much for your help
  • c

    cold-van-45410

    08/24/2022, 5:21 AM
    how can we wait for spinner to disappear in cypress ? After loading of spinner i want to execute my next code
  • e

    early-optician-55799

    08/24/2022, 6:43 AM
    @cold-van-45410 I would use one of these cy.get('yourSpinner', {timeout: 30000}).should('not.be.visible'); cy.get('yourSpinner', {timeout: 30000}).should('not.exist'); As "timeout" set as many milliseconds as you are willing to wait for the spinner to disappear before Cypress throws error
  • c

    cold-van-45410

    08/24/2022, 6:56 AM
    its not working for me ,cypress is still too fast
  • e

    early-optician-55799

    08/24/2022, 7:01 AM
    I'm not sure what you mean by cypress is too fast... Maybe you need to wait for the spinner to be visible first and then wait for it to disappear? cy.get('yourSpinner', {timeout: 30000}).should('be.visible'); cy.get('yourSpinner', {timeout: 30000}).should('not.be.visible');
  • c

    cold-van-45410

    08/24/2022, 7:18 AM
    thanks buddy its working fine i did some mistake😁
  • q

    quiet-breakfast-31238

    08/24/2022, 8:57 AM
    Who can help? Maybe somebody had this issue?
  • a

    acceptable-hamburger-48790

    08/24/2022, 9:55 AM
    Is there a reproducible repo you can share ? that would speed up the helping
  • q

    quiet-breakfast-31238

    08/24/2022, 9:56 AM
    no
  • f

    fancy-airplane-60156

    08/24/2022, 12:42 PM
    Hi, is there a known solution to multiple redirects error on Cypress ?
  • f

    fancy-airplane-60156

    08/24/2022, 12:44 PM
    I get this error "redirected you too many times." and my test fails. This happens when a logs on a second domain URL SSO page
1...878889...192Latest