Execute the code, such as the login function, based on the active test suite being run

TL;DR: Before running a test suite, I need to execute code that depends on which specific test suite is going to run, such as logging in as a particular user.


In my wdio.conf.js file, the relevant section looks like this:

exports.config = {
    specs: [
        './spec/**/*.spec.js'
    ],
    suites: {
        allExceptAandB: [
            './spec/**/!(A|B).spec.js'
        ],
        A: [
            './spec/A.spec.js'
        ],
        B: [
            './spec/B.spec.js'
        ]
    },
    [...]
}

When using the command line argument --suite A, only the A.spec.js will be executed, which is the expected behavior.

Now, I want to run some initialization code before each test suite based on which suite is being run, such as calling login(usernameA, passwordA) or login(usernameB, passwordB).

If I use

before: function(capabilities, specs) {
    login(username, password)
}

in my wdio.conf.js, this code seems to be executed before every single spec. Additionally, when using

beforeSuite: function(suite) {
    console.log(suite)
}

I noticed that it was also executed before every spec and displayed the suite information.

My expectation is that

  • before should run before any test suite begins
  • beforeSuite should run before each suite, and there should be a way to access the name of the suite being executed in order to adjust parameters for tasks like logging in

How can I achieve this functionality?

Answer №1

When faced with a lack of alternatives, I resorted to implementing a creative solution in my wdio.conf.js. This workaround involves parsing command line arguments to determine which test suite is currently being executed.

before: function (capabilities, suite, specs) {
    let suiteNameCliParamIndex = process.argv.indexOf("--suite") + 1
    let suiteName = process.argv[suiteNameCliParamIndex]
    if(suiteName === 'thisSuite') {
        doThisStuff()
    } else {
        doOtherStuff()
    }
}

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

Are there any notifications triggered when a draggable element is taken out of a droppable zone?

Within a single droppable area, there is a collection of individual Field Names that can be dragged, and a table featuring X headers, each of which can be dropped into. Initially, these headers are empty. Is there a way to detect when an item is taken out ...

The logout confirmation message functionality in Laravel 8 is malfunctioning

In my Laravel project, I am attempting to implement a logout confirmation message that will pop up when a user clicks on the logout button. Here is the code I have added to my navbar.blade.php: <a class="dropdown-item" id="logout" hr ...

Encountering a StaleElementReferenceException while trying to use Selenium for form submission

My current project involves using Selenium with Python to automate form submission on a website. The form consists of an input field and a submit button, which I am trying to locate using various methods such as find_element(), By.NAME, and By.XPATH. Whil ...

Utilizing ngModel within the controller of a custom directive in Angular, instead of the link function

Is there a way to require and use ngModel inside the controller of a custom Angular directive without using the link function? I have seen examples that use the link function, but I want to know if it's possible to access ngModel inside the directive ...

Discovering the category to which $(this) belongs

I am attempting to target the class of the clicked button in order to create a generic event that will fade out all elements of the generic class "gen", excluding the elements that belong to the clicked button. $(document).ready(function(){ $(this).cl ...

Pause animation when the mouse leaves the screen

After searching through various resources, I couldn't find a definitive solution to my issue. The problem I am facing is that when the .mouseenter(function(){ }) function is triggered, and immediately followed by the .mouseleave(function(){ }) functio ...

How can I obtain the true client IP address using Nginx?

I have a straightforward express app that has been containerized using Docker. You can find the repository here. In this setup, I utilized nginx as a reverse proxy. When accessing http://45.33.97.232:3000, it displays the actual server IP. However, if I v ...

What is the best way to integrate a spray paint feature into an HTML5 canvas?

After successfully implementing a pencil tool with customizable color options, I am now looking to add a spray paint tool that allows users to draw on a canvas and change the spray paint color as well. I have attempted to integrate the JavaScript for the ...

Sorting in Postgres is about organizing data in a specific order

I've been working on organizing my Postgres questions database by ID. Currently, the order seems random, but I want it to be sorted by ID in ascending order. Since I'm new to Postgres, I'm not entirely sure about what I need to do... All ...

Plugin for sliding images with jQuery

I am in need of a jQuery plugin that can handle a collection of images with varying sizes and file types (i.e. .jpg, .png, etc.). The plugin should offer features like next, previous buttons, caption titles, and the ability to slide through the images seam ...

Mysterious Ruby driver for Selenium unfound, alluding to Firefox

After successfully creating a selenium test that runs in Chrome, I attempted to extend its functionality to work in other browsers. Unfortunately, when trying to access Firefox, an error is encountered. Here is the code snippet leading up to the error: r ...

The server is not being reached by the Ajax PUT method

Having some issues with my login form when attempting to use the PUT method for logging in and storing the username. It seems like it's not communicating with the server properly and I'm unable to log in. Any help would be greatly appreciated. I ...

Deployment of NextJS optional catch all routes causing issues

We are currently working on a project with a dynamic route [productId]. Within this page, we have multiple other pages that contain optional catch-all routes. The structure in the pages folder looks like this: [productId] contentOne [[...slugOne]] U ...

What is the significance of authors stating "AngularJS compiles the DOM"?

Currently, I am diving into the book Lukas Ruebbelke's AngularJS in Action, The author emphasizes throughout the text that, In AngularJS, a view is essentially the modified version of HTML after it has been processed by AngularJS. I'm struggli ...

Is it possible to verify the truth of variables within a multi-dimensional array?

I am currently working on a project that involves calling arrays and verifying if the entire array is true (e.g. ["cell1", "cell2", "cell3"]). Below are my HTML and JS code snippets for reference. While I believe this issue may be an easy fix, I am facing ...

I would like to know more about the concept of getters and setters and how they can be effectively utilized

I've been struggling to understand the concept of getters and setters. Despite reading articles like JavaScript Getters and Setters and Defining Getters and Setters, I just can't seem to grasp it. Could someone please explain: The purpose of g ...

Can Selenium be used to test a Siebel Open UI application?

Can I use Selenium JavaScript to interact with the Siebel application without any additional add-ons? ...

Combining additional buttons to function as a single unit

Currently, I have a setup with two buttons that add and remove contacts, along with a third button that retrieves a user's geolocation. Is there a way to make the newly added buttons automatically incorporate the geolocation function? Essentially, whe ...

Consistent value displayed by addEventListener for each event

Hey everyone, I've been experimenting with different solutions for a few hours now but I'm still stuck on this problem. I have a function that takes JSON as input - I can create an 'a' element: CHECK I can set all the element propertie ...

React JS Button remains unaltered despite API call influence

I have encountered an issue with my page where a single post is displayed and there is a like button. The problem arises when the user clicks the like button - if the post is already liked, the button state should change to an unlike button. However, if th ...