Is there a way to use TestCafé to simultaneously log into multiple services?

I've been experimenting with testcafé in an effort to simultaneously log into multiple services using the role mechanism. My goal is to have my tests logged into multiple services concurrently without switching between roles.

While a guide on this topic () suggests that it's possible to achieve this with testcafé, I've only been able to switch between roles, rather than being logged into multiple services simultaneously.

The guide states:

For instance, assume that you switch to a role that logs you in on website A. After you switch to this role, you log in to website B in test code. TestCafe adds a new cookie to the role branch. If you switch to a different role and then back to the initial role in the same test run, you will be logged to both website A and B. If you switch to this role in a different test, you will be logged in to website A only.

I've made several attempts to achieve the desired outcome as described above, but unfortunately, none of them have been successful.

import { Role } from "testcafe";

const role1 = Role("https://some-website.org", async t => {
  await t
    .typeText("input[type=text]", "")
    .typeText("input[type=password]", "")
    .click(".button");
});

const role2 = Role("https:/another-website.org", async t => {
  await t
    .typeText("input[type=text]", "")
    .typeText("input[type=password]", "")
    .click(".button");
});


fixture `Getting Started`;

test("test 1", async t => {
  await t.useRole(role1);
  // now logged in as "role1"
  await t.useRole(role2);
  // now logged in as "role2"

  // ... but not logged in as "role1" and "role2"
});

test("test 2", async t => {
  await t
    .useRole(role1) // now logged in as "role1"
    .useRole(role2); // now logged in as "role2"

  // ... but not logged in as "role1" and "role2"
});

test("test 3", async t => {
  await t
    .useRole(role1) // now logged in as "role1"
    .useRole(role2) // now logged in as "role2"
    .useRole(role1); // now logged in as "role1"

  // ... but not logged in as "role1" and "role2"
});

What steps should I take to ensure that I am logged into multiple services simultaneously?

testcafé version: 1.8.8

browser: Chrome 84.0.4147.89 / macOS 10.15.5

Answer №1

When User Roles clean all associated cookies upon application, it prevents you from achieving this using two separate User Roles.

To work around this, you can either create a single role that handles login on both pages or utilize the first User Role and log the second user in manually within the test body.

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

Convert the easeInExpo function from jQuery easing to vanilla JavaScript and CSS

Currently, I am in the process of converting a piece of code from jQuery to plain JavaScript and CSS. The specific code snippet I am focusing on involves creating easing functions without relying on jQuery. const customEasing = { easeInExpo: function ( ...

Continuous polling with Ajax in Rails does not trigger the display of an alert box

Trying to implement ajax polling using the RailsCast tutorial on ajax polling (#229) but encountering an issue where the alert box doesn't pop up after running the server. Here's the code in app/views/quotes/index.js.erb: alert('Hey') ...

Using jQuery to deactivate the submit button when a field is empty or a checkbox is left unchecked

Today is my first attempt at using jQuery, and I could really use some assistance as I'm struggling to achieve the desired outcome. I'm dealing with a table of documents, each containing a checkbox for selection purposes. Additionally, there&apo ...

Recursively converting trees in JS/ES6

Currently, I am attempting to convert a tree structure provided in the following format: {"Parent": { "Child1": ["toy1"], "Child2": { "Nephew": ["toy2", "toy3"] } } } into a standardized tree form ...

Facing the issue once more - Angular displaying "Http failure response for... 0 Unknown Error"

I have been researching extensively on this issue, particularly on Stack Overflow. Many of the responses point to it being a CORS problem, but I am uncertain if that is the case in my situation. Therefore, I am reaching out for help once again and would gr ...

What is the most effective way to access a variable from a service in all HTML files of Angular 2/4 components?

In my angular 4 project, I have an alert service where all components can set alerts, but only specific components display them in unique locations. My question is: how can I access a variable from this service across all HTML files? The structure of my s ...

(node:19502) UnresolvedPromiseRejectionNotification: Promise rejection not handled (rejection id: 1): TypeError: Unable to access property 'indexOf' of undefined

I successfully integrated cucumber with nightwatch.js. Here is a snippet of my package.json file: { "name": "learning-nightwatch", "version": "1.0.0", "description": "learning nightwatch", "license": "UNLICENSED", "scripts": { "nightwatch": ...

How would you go about creating a VueJS component that displays a table with a set number of columns and automatically distributes the cells within them?

Hey there! I'm currently working with a VueJS component that looks like this: <template> <div> <table> <tbody> <tr v-for="(item, index) in items" :key="index"> <t ...

Arrange objects in an array based on certain criteria using JavaScript in a dynamic

I have an array containing various items that need to be sorted according to specific rules. The goal is to group all values with "rules" together, and ensure that "ELIG_DATABASE" is grouped with "ELIG_SERVICE." const items =[{"name":"ELIG_ ...

Evaluating the criteria and presenting two distinct notifications with setCustomValidity

When validating text fields in an HTML form, I am looking to check two conditions. Currently, the code below checks if the phone number entered is in the correct format and displays a message 'Enter a valid mobile number' if it is incorrect using ...

Attempting to persist a nested document in MongoDB using mongoose within a Nodejs environment

I attempted to save an address as a nested document in the following format When sending data from the client side, it was formatted like this: const address = JSON.stringify( { addressline1:form.addressline1.value, addressline2:form.addressline2.value, c ...

What is the best way to remove an item from my online shopping cart using JavaScript?

I am currently developing an online store website. One issue I am facing is deleting items from the cart after a customer completes an order. Below is the array of cart items: const products = [ { id: '0', name: 'Nike Slim Shirt&ap ...

turning off next.js server side rendering in order to avoid potential window is undefined issues

I am currently managing a private NPM package that is utilized in my Next.js project, both of which are React and Typescript based. Recently, I integrated a graph feature into the NPM package and encountered an issue where any reference to window within t ...

Loop through and write files using Node.js

I've been experimenting with a Google Trends API integration in node.js to gather data on the popularity of various search terms. My goal is to store a list of search words in an array, iterate through this array, call the Google Trends API for each ...

Is there a hierarchy to be followed within the <head> element?

I have been developing websites using HTML for nearly 3 years now, but since I had to teach myself, there are still a few things I am unsure about. One question that has recently become important is whether it is possible to create groups within the <h ...

5-item carousel in CSS gridView

I'm currently working on a thumbnail slider project. My goal is to display 5 thumbnails at a time, and allow users to move to the next or previous set of thumbnails by clicking on the corresponding buttons. I attempted to modify an existing slider tha ...

Button within the Magnific Popup (do not use to close)

I am currently developing a website with a gallery page that utilizes the Magnific Popup plugin. My client has provided lengthy 'captions' for each image, almost like short stories. To display these captions effectively, I have utilized the titl ...

Angular.js and D3 - The Perfect Combination for Dynamic Data Visualization!

Having some trouble creating a chart with angular.js. The chart is not appearing on the page when using rout.js, but it works fine without it. Here's my code: var myapp = angular.module('myapp', ['angularCharts']); function D3 ...

The declaration file for module 'react-scroll-to-bottom' appears to be missing

I recently added react-scroll-to-bottom to my project and it is listed in my dependencies. However, I am encountering the following error: Could not find a declaration file for module 'react-scroll-to-bottom'. The path 'c:/Users/J/Desktop/w ...

Issue with array filter not functioning correctly upon page refresh when utilizing vue-router

I have a method (shown below) that functions perfectly when I'm directed from a <router-link>. selectedSpaceObj() { if (!this.selectedSpace) { return {}; } else { return th ...