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?
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…
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);