# Cypress E2E testing using keycloak-js

**URL:** <https://forum.keycloak.org/t/cypress-e2e-testing-using-keycloak-js/7267>\
**Category:** Getting advice\
**Created:** [February 8, 2021, 11:12pm UTC](https://forum.keycloak.org/t/cypress-e2e-testing-using-keycloak-js/7267 "2021-02-08T23:12:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonjcarr](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/simonjcarr/32/1360_2.png) [@simonjcarr](https://forum.keycloak.org/u/simonjcarr)\
**Post date:** [February 8, 2021, 11:12pm UTC](https://forum.keycloak.org/t/cypress-e2e-testing-using-keycloak-js/7267/1 "2021-02-08T23:12:42Z")

</div>

I use Cypress for E2E testing front end JS Apps. Cypress does not allow you to navigate to a different domain, other than the one being tested without adding the option `"chromeWebSecurity": false` to cypress.json config file.

By adding `"chromeWebSecurity": false` I can navigate to the keycloak login page, however cypress is then unable to interact with the login form.

I know some people will say why do you want to actually login when you can just pretend to login, but I need to be logged in, because my site relies on the functions provided by keycloak-js such as `hasResourceRole()`.

How do other people do E2E testing with keycloak and continue to use the clients provided by keycloak, such as keycloak-js?

---

<div class="post-metadata">

**Author:** ![rooch84](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/rooch84/32/189_2.png) [@rooch84](https://forum.keycloak.org/u/rooch84)\
**Post date:** [February 13, 2021, 10:37am UTC](https://forum.keycloak.org/t/cypress-e2e-testing-using-keycloak-js/7267/2 "2021-02-13T10:37:02Z")

</div>

We have done this with success (although have since migrated away from Keycloak to our in house SSO service).

Like you, chromeWebSecurity needs to be set to false, but otherwise it worked. Are you doing a redirect or popup? For redirect, the following worked fine for us…

```auto
cy.visit(Cypress.env("host")); // Our own site
  cy.get(".button").click(); // A login button that starts the process
  cy.get("#username") // The username field on the keycloak login page
    .type(Cypress.env("username"))
    .get("#password")
    .type(Cypress.env("password"));
  cy.get("#kc-login").click();
  cy.wait(300);

```

---

<div class="post-metadata">

**Author:** ![edewit](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/edewit/32/287_2.png) [@edewit](https://forum.keycloak.org/u/edewit)\
**Post date:** [February 15, 2021, 12:24pm UTC](https://forum.keycloak.org/t/cypress-e2e-testing-using-keycloak-js/7267/3 "2021-02-15T12:24:24Z")

</div>

We use cypress as well ( for the new keycloak admin client ) and we didn’t do anything in particular with to test the login see: [GitHub - keycloak/keycloak-admin-ui: Keycloak Admin Console](https://github.com/keycloak/keycloak-admin-ui/)

---

<div class="post-metadata">

**Author:** ![zhyd1997](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zhyd1997/32/5611_2.png) [@zhyd1997](https://forum.keycloak.org/u/zhyd1997)\
**Post date:** [April 19, 2022, 6:21am UTC](https://forum.keycloak.org/t/cypress-e2e-testing-using-keycloak-js/7267/4 "2022-04-19T06:21:51Z")

</div>

I can login with `cy.get('input[type=submit]').click();`

But I got an error as below pic shows:

 ![Screen Shot 2022-04-19 at 14.19.20](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/3/33a96d13dc6e7040a8e66b61463668f5a08a8dbd.jpeg)  
it said **Cookie not found. Please make sure cookies are enabled in your browser.**

I already set `chromeWebSecurity` to false in `cypress.json` and confirmed it in Cypress GUI window.
