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

    red-toddler-79937

    06/17/2022, 12:19 AM
    i dont know how to solve this
  • r

    red-toddler-79937

    06/17/2022, 12:19 AM
    yet
  • r

    red-toddler-79937

    06/17/2022, 1:00 AM
    I think this is the issue
  • r

    red-toddler-79937

    06/17/2022, 1:01 AM
    But I cannot put mine in the before each...
  • r

    red-toddler-79937

    06/17/2022, 1:17 AM
    Any ideas on how I can store my token? So that I can use it in other tests?
  • b

    bored-baker-20372

    06/17/2022, 3:35 AM
    Hi, were you able to set the response to a variable separately or our only way is to pass it to a function? I'm also interested on how you can access that response outside the function. 🙂
  • b

    breezy-area-11544

    06/17/2022, 6:46 AM
    Hello, can someone help please 🙏 I'm getting this error:
    Copy code
    visit/
    CypressError
    cy.visit() failed trying to load:
    
    https://gaspedaal.nl/
    
    The response we received from your web server was:
    
    > 403: Forbidden
    
    This was considered a failure because the status code was not 2xx.
    
    If you do not want status codes to cause failures pass the option: failOnStatusCode: false
    
    Because this error occurred during a before all hook we are skipping the remaining tests in the current suite: Smoke tests flow`
  • b

    bitter-apple-86316

    06/17/2022, 6:50 AM
    @gray-kilobyte-89541 you haven't cover websocket examples in your paid course
  • a

    adorable-stone-42197

    06/17/2022, 7:14 AM
    Hey guys, is someone test autocomplete? Maybe etc to type some easy query type ( when you try to type select than autocomplete appears and choose SELECT? If someone have example to share
  • n

    nutritious-honey-65632

    06/17/2022, 8:17 AM
    store it somewhere after getting it, like
    Copy code
    cy.get('@something').then(res => {
                myArray.push(res)
            })
  • b

    breezy-area-11544

    06/17/2022, 8:46 AM
    This error is happening because of cloudflare
  • b

    breezy-area-11544

    06/17/2022, 8:47 AM
    I tried to add an user agent:
    Copy code
    cy.visit({
                url: "https://www.gaspedaal.nl/",
                headers: {
                    "user-agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
                },
            });`
    But it still fails. I don't know what else to do. Someone please help
    b
    • 2
    • 1
  • b

    breezy-area-11544

    06/17/2022, 8:47 AM
    It's the last day of the sprint and I'm losing my mind 😿
  • r

    red-toddler-79937

    06/17/2022, 9:14 AM
    doesnt work because when i call settogglestate again it will throw an error that the alias doesn't exist
  • r

    red-toddler-79937

    06/17/2022, 9:14 AM
    and if i put it in login what you said, i will get undefined when i call settogglestate
  • r

    red-toddler-79937

    06/17/2022, 9:15 AM
    if i figure it out i'll let you know
  • p

    polite-alarm-78904

    06/17/2022, 9:31 AM
    I have an element that is being re-rendered after clicking a button. `cy.getBySel(
    item-approved-${id}
    ).should("be.visible")` This returns the detached element. How can I wait for the element to render before trying to make assertions? It randomly worked once when I added a timeout, but its not consistent.
  • n

    nutritious-honey-65632

    06/17/2022, 9:35 AM
    don't get
    @token
    inside function, pass the token as the function parameter
  • f

    fresh-doctor-14925

    06/17/2022, 9:39 AM
    Well, you can chain assertions, so :
    Copy code
    cy.getBySel(item-approved-${id})
      .should("be.visible")
      .and(...)
    But if that's asserting on the detached element, you could do a second
    get
    once the element is in the desired state. That's how I've gotten past detachment issues in the past. Would be interested to know if there's a better way
    Copy code
    cy.getBySel(item-approved-${id})
      .should("be.visible")
      .getBySel(item-approved-${id})
      .doStuff()
  • r

    red-toddler-79937

    06/17/2022, 9:40 AM
    a string paremeter or?
  • r

    red-toddler-79937

    06/17/2022, 9:40 AM
    i can try
  • r

    red-toddler-79937

    06/17/2022, 9:44 AM
    ```ts let token: string; function login() { cy.intercept({ method: 'POST', url: '/api/auth/login', }).as('loginResponse'); cy.visitPage('login', 'abc-auth-template'); cy.fillField('email', 'info@abc.nl'); cy.fillField('password', 'password'); cy.clickButton('submit'); cy.wait('@loginResponse').its('response.statusCode').should('equal', 200); cy.get('@loginResponse').its('response.body.data').then($response => { token = $response; }); } function setToggleState(productId: number, state: boolean, token: string) { cy.request({ method: "PUT", url:`/api/products/${productId}/update-availability`, headers: { Authorization:
    Bearer ${token}
    }, body: { isAvailable: state } }); } ```Is this what you meant?
  • n

    nutritious-honey-65632

    06/17/2022, 9:47 AM
    yes, does it work?
  • r

    red-toddler-79937

    06/17/2022, 9:48 AM
    my cpress server crashed when i ran this so i am rebooting the entire server, might take a min
  • r

    red-toddler-79937

    06/17/2022, 9:48 AM
    > 401: Unauthorized nop
  • r

    red-toddler-79937

    06/17/2022, 9:49 AM
    that's because the token is undefined
  • f

    fresh-doctor-14925

    06/17/2022, 10:00 AM
    Probably because your use of
    cy.get()
    here isn't correct.
    @loginResponse
    is aliased to the intercept itself, rather than what is intercepted. Also, not sure you need to verify that the response code is 200. Cypress will do that under the hood. Try:
    Copy code
    cy.wait('@loginResponse')
    .its('response.body.data').then(token => {
        // do stuff with token
      });
  • r

    red-toddler-79937

    06/17/2022, 10:06 AM
    ```ts async function login() { cy.intercept({ method: 'POST', url: '/api/auth/login', }).as('loginResponse'); cy.visitPage('login', 'abc-auth-template'); cy.fillField('email', 'info@abc.nl'); cy.fillField('password', 'password'); cy.clickButton('submit'); cy.wait('@loginResponse').its('response.body.data').then($response => { console.log($response); // Returns token as expected. token = $response; }); } ```This still returns undefined for token.
    f
    • 2
    • 58
  • r

    red-toddler-79937

    06/17/2022, 10:07 AM
    I can of course also put my
    setTogglState
    inside the
    .then()
    of
    login()
    but I need to use it multiple times in my code.
  • f

    fresh-doctor-14925

    06/17/2022, 10:31 AM
    ```ts
1...535455...192Latest