# Chrome problems testing with Cypress

**URL:** <https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092>\
**Category:** Questions\
**Created:** [September 25, 2020, 11:29pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092 "2020-09-25T23:29:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggascoigne](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ggascoigne/32/2202_2.png) [@ggascoigne](https://devforum.okta.com/u/ggascoigne)\
**Post date:** [September 25, 2020, 11:29pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092/1 "2020-09-25T23:29:28Z")

</div>

Following Cypress recommendations we use direct api calls to login in most of our tests - basically if it’s not explicitly testing the login UI we bypass it, it’s much faster that way and we tend to login rather a lot to ensure we have good role based test coverage.

Based on examples in threads like this one [https://github.com/cypress-io/cypress/issues/4416](https://github.com/cypress-io/cypress/issues/4416), we have this login code:

```
cy.request({
  method: 'POST',
  url: `${OKTA_URL}/api/v1/authn`,
  body: {
    username,
    password,
    options: {
      warnBeforePasswordExpired: 'true',
    },
  },
})
  .then((resp) => {
    const sessionToken = resp.body.sessionToken
    const qs = {
      client_id: OKTA_CLIENT_ID,
      scope: 'openid',
      nonce: getRandomString(),
      state: 'test', // fyi state is used to link requests and responses, we don't care here
      code_challenge: 'test',
      redirect_uri: OKTA_REDIRECT_URI,
      response_type: 'id_token token',
      sessionToken: sessionToken,
    }

    cy.request({
      method: 'GET',
      url: `${OKTA_URL}oauth2/default/v1/authorize`,
      form: true,
      followRedirect: false,
      qs,
    }).then((respWithToken) => {
      const url = respWithToken.redirectedToUrl
      cy.visit(url).then(() => {
        cy.visit('/')
      })
    })
  })
  .then((res) => {
    Cypress.log({ message: `okta login success as ${username}` })
  })

```

And it works, or at least it works in Electron and Firefox.

In Chrome, it logs in, then the screen refreshes and we’re back at the okta login page.

I should add that the UI is using a pretty bar oidc-client implementation and not the okta-js pacakge if that’s relevant.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![ggascoigne](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ggascoigne/32/2202_2.png) [@ggascoigne](https://devforum.okta.com/u/ggascoigne)\
**Post date:** [October 1, 2020, 9:48pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092/2 "2020-10-01T21:48:59Z")

</div>

It’s disappointing that the project that I use for all of my personal development, auth0, has a nice blog post talking about how to solve this exact problem ([https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/](https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/)), but if you search for the same from okta you just people who either abandoned Okta or abandoned Cypress.

---

<div class="post-metadata">

**Author:** ![Fuzzard](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/fuzzard/32/1909_2.png) [@Fuzzard](https://devforum.okta.com/u/Fuzzard)\
**Post date:** [October 12, 2020, 5:52pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092/3 "2020-10-12T17:52:40Z")

</div>

are there any pointers as to what request fails in Chrome and how the response to the same request differs in Electron and Firefox?

---

<div class="post-metadata">

**Author:** ![ggascoigne](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/ggascoigne/32/2202_2.png) [@ggascoigne](https://devforum.okta.com/u/ggascoigne)\
**Post date:** [October 12, 2020, 6:45pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092/4 "2020-10-12T18:45:37Z")

</div>

Not a thing. Everything appears to be pretty much going along the same way until I end out back at the login page.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [October 13, 2020, 7:05pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092/5 "2020-10-13T19:05:12Z")

</div>

When/why is that screen refresh occurring and is there something on that page that is reliant on there being an Okta session in browser?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [November 11, 2020, 4:54pm UTC](https://devforum.okta.com/t/chrome-problems-testing-with-cypress/11092/6 "2020-11-11T16:54:21Z")

</div>


