Issue encountered: Failure in automating login through Cypress UI with Keycloak

Struggling with automating an e-commerce store front using Cypress, specifically encountering issues with the login functionality.

The authentication and identity tool in use is keycloak. However, the Cypress test fails to successfully log in or register users. The workflow involves visiting siteundertest.com > Clicking on login/register > redirecting to keycloak > entering valid login credentials > clicking login. Expected outcome: Successful login leading to authenticated home page redirection (siteundertest.com). Actual result: "An error occurred processing your request."

Key points:

  • This login process works flawlessly using Selenium
  • POST requests are disabled for keycloak on the current domain, impeding the ability to bypass login/register via API calls (Bypass UI Login using Cypress)
  • There's a suspicion of losing cookie/header information, unsure about what data needs to be provided alongside Cypress
  • Attempts made to resolve through cypress.json config modifications like disabling web security and other suggested methods (Unable to signup using Keycloak through Cypress)
  • Error persists across different browser environments (headless, Chrome, FF, Edge)
  • Manual login functions correctly using various user accounts
  • Encountering the same error when attempting registration via Keycloak button clicks
  • Exploration of preserving cookies through Cypress Cookies but can't identify the root issue

A supportive developer assisted in gathering insights from keycloak regarding cookies, comparing Cypress vs. Selenium vs. Manual Web: https://i.sstatic.net/Oz920.png

The script:

describe('Login to Keycloak with Email', function(){ 

  before(function () {
    cy.fixture('logindata').then(function (data) {
      this.data = data;           
    })
  })

  it('Open Homepage', function(){
    cy.visit(this.data.OccTestHmepageUrl)
  })
 
  it('Click Log In', function(){
   cy.get('[data-bind="visible: !(loggedInUserName() && (loggedIn() || isUserSessionExpired()))"] > #CC-loginHeader-login').click()
  });
  
  it('Verify Redirect to Keycloak', function(){
    cy.get('.auth-land-page > :nth-child(1) > .text-center')
  });

  it('Click login button', function(){
    cy.get('.emailLogin > .auth-button-content').click()    
  })

  it('Enter valid email address', function(){
    cy.fixture('logindata').then(function (data) {
    this.data = data;
    cy.get('#emailUsername')
    .type(this.data.LoginEmail)}
    )}
  )

  it('Enter valid password', function(){
    cy.fixture('logindata').then(function (data) {
      this.data = data;
      cy.get('#password')
      .type(this.data.LoginPassword)}
      )}
    )

  it('Click login button', function(){
    cy.get('#loginBtn').click()
    // Error occurs here
  })

  it('Verify successful login', function(){
    //Redirect fails
    cy.get('#CC-loginHeader-logout')
    })
  })

Appreciation in advance for any assistance provided!

Answer №1

The issue might be stemming from the divide in the login process. Have you considered consolidating the entire login procedure into a single test scenario? I once broke down my functional login assessment into multiple tests for experimentation, only to discover that it failed to function properly. This led me to believe that perhaps combining them into one comprehensive test is the way to go. It's possible that you have already found a solution or the subject matter is no longer a priority for you, given that this question was posed 8 months ago :) However, I would appreciate hearing about your experiences—if this adjustment resolves your predicament, if it doesn't alter anything, or if you stumbled upon an alternative approach that worked.

Here’s an example of how the revised code could appear:

describe('Login to Keycloak with Email', function () {
  
  before(function () {
    cy.fixture('logindata').then(function (data) {
      this.data = data;
    })
  })

  it('Login', function () {
    cy.visit(this.data.OccTestHmepageUrl)
    cy.get('[data-bind="visible: !(loggedInUserName() && (loggedIn() || isUserSessionExpired()))"e;] > #CC-loginHeader-login').click()
    cy.get('.auth-land-page & gt; :nth-child(1) > .text-center')
    cy.get('.emailLogin > .auth-button-content').click()
    cy.fixture('logindata').then(function (data) {
      this.data = data;
      cy.get('#emailUsername').type(this.data.LoginEmail)
    })
    cy.fixture('logindata').then(function (data) {
      this.data = data;
      cy.get('#password').type(this.data.LoginPassword)
    })
    cy.get('#loginBtn').click()
    // An error occurred here; perhaps segregating the tests isn’t ideal. Please inform me if this modification resolves the issue.
    // Redirect failure
    cy.get('#CC-loginHeader-logout')
  })
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic data retrieval with the power of JavaScript and AJAX

When attempting to send data using AJAX in PHP, I encountered an issue with my jQuery click function on a button that sends data only when the quantity is greater than 1. The error arises because PHP does not recognize the variables 'name' and &a ...

The error code 405 (Method Not Allowed) occurs in Ajax when the action field is empty or identical to the current page

Special thanks to @abc123 for sharing the code below in one of their posts: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <form id="formoid" a ...

Customize the MUI (JoyUI) Autocomplete feature in React using react-hook-form to display a unique value instead of the label

Currently, I am in the process of creating a form that includes JoyUI (material) autocomplete and react-hook-form functionality. The array of objects I am using for my options looks like this: [ { label: "Todo", param: "TODO" }, ...

What is the best way to retrieve recently inserted data using Sequelize in PostgreSql?

Is there a way to retrieve updated table values after adding a user to the "WOD" table without making an additional query? Currently, when I add a third user to my WOD table, I can only return the first two users because I am unable to access the updated ...

Exploring the functionality of a personalized hook using the useSelector method

I have developed a custom hook and I am in the process of testing it independently. However, I am encountering an issue where I need to wrap the hook inside a Provider to proceed further. The error message I am getting is displayed below: Error: could not ...

Update the second dropdown menu depending on the selection made in the first dropdown menu

While I know this question has been posed previously, I'm struggling to apply it to my current situation. In my MySQL database, I have a table named "subject" that includes columns for subject name and subject level. Here's an example: Subject ...

Display a list of items using ReactJS by mapping through an array of objects and rendering based on

How can I render a set of <div> </div> based on the items in an object without having to specify their names? In the code snippet below, I want the display of WorkObjectID and WorkObjectVal to be dynamic rather than static. If I include TempOb ...

Tips for adjusting the color of a <a> tag upon clicking, which remains unchanged until the URL is modified

My goal is to maintain the color of a link when it is clicked. Currently, hovering over the navbar link changes it to greyish, but I want it to remain a different color after clicking on it. I am implementing this using the react-router-dom library for the ...

If you scroll quickly, watch out for the flickering of the fadeIn and fadeOut

I have a script that fades in an element once the user scrolls more than 145px from the top of the page. $(window).scroll(function(){ if ($(this).scrollTop() > 145) { $('#fademenu').fadeIn(); } else { $('#fademenu').fadeOut(); } } ...

Coloring vertices in a Three.js geometry: A guide to assigning vibrant hues

This inquiry was previously addressed in this thread: Threejs: assign different colors to each vertex in a geometry. However, since that discussion is dated, the solutions provided may not be applicable to current versions of three.js. The latest versions ...

Modify data in a table using Dialog Component in Angular Material

I need to implement a Material Dialog feature that allows users to update entries in a table by clicking on the "Change Status" button. Check out this functional snippet: https://stackblitz.com/edit/angular-alu8pa I have successfully retrieved data fr ...

Display a loading state in Next.js until the page has finished loading completely

When working with a page that includes both getStaticProps and getStaticPaths, you may have noticed that loading the page can take some time, leaving the front-end blank. To enhance the user experience, you might want to display a simple message such as "P ...

When the menu active item is clicked, the header will automatically scroll to the top

I've implemented a sticky header using CSS and JavaScript along with a mega menu. However, I've encountered an issue where when scrolling to the bottom and clicking on the "more" link in the dropdown, the page scrolls back to the top. This is the ...

Tips for preventing directly mutating a prop within a recursive component

The child operates on its own copy of the prop data and can notify the parent using `$emit` when a change occurs. Imagine dealing with a recursive tree structure, like a file system for example: [ { type: 'dir', name: 'music', childr ...

Is it possible to automatically refresh an AJAX Powered Page without it reloading from the beginning?

Many websites, like Twitter and LinkedIn, use AJAX to load new content as you scroll down. Sometimes, after reaching the end of a long page loaded with AJAX (where no more items are being loaded), some content towards the top or middle gets updated. Is the ...

Unable to store object data within an Angular component

This is a sample component class: export class AppComponent { categories = { country: [], author: [] } constructor(){} getOptions(options) { options.forEach(option => { const key = option.name; this.categories[k ...

Employing variables as selectors in Selenium 2 Webdriver using the by.cssselector technique

I am currently developing automated tests using Selenium 2 Webdriver in C# within Visual Studio 2010. Despite my diligent efforts, I have been unable to locate any functional examples of utilizing variables as selectors. The only instance I came across inv ...

Utilize a function on specific attribute values

I have a function in JavaScript that is designed to convert all relative URLs into absolute URLs. function rel2Abs(_relPath, _base); //_relPath represents the relative path //_base indicates the base URL Now, my objective is to implement this function on ...

What is the optimal method for transmitting data for a substantially large music playlist via HTTP?

I am currently in the process of developing an online music player. My main challenge lies in retrieving a comprehensive list of songs from the database and transmitting it to the user. The user should have the ability to create playlists on-the-go, hence ...

How to filter jQuery DataTables by column using comparison operators

Recently, I've been utilizing the amazing DataTables jQuery plugin along with the filter plug in. But now, I find myself pondering if there's a way to filter table columns by row using a comparison operator (such as '<', '>&a ...