Managing multiple .js files for executing automated test cases with their respective tags in CucumberJS: A comprehensive guide

I have been using CucumberJS with Selenium-Webdriver to automate my test cases. Currently, I have multiple feature files along with their respective step-definition files. However, when I try to run the test cases, an error is thrown:

Error: The previously configured ChromeDriver service is still running and needs to be shut down before its configuration can be adjusted. at Object.setDefaultService (D:\code\egov-test-cases\node_modules\selenium-webdriver\chrome.js:305:11) at new World (D:\code\egov-test-cases\features\support\world.js:21:12) at Object. (D:\code\egov-test-cases\features\steps\create_approver_remittance_master.js:15:13) ...

Despite including code in the world.js file for automating Chrome, and importing the driver from it, I continue to encounter the same error.

 class World {
  constructor() {

    const { setDefaultTimeout } = require('cucumber');

    const webdriver = require('selenium-webdriver');
    const chrome = require('selenium-webdriver/chrome');
    const path = require('chromedriver').path;

    const screen = {
      width: 640,
      height: 480
    };

    setDefaultTimeout(100 * 5000);

    var service = new chrome.ServiceBuilder(path).build();
    chrome.setDefaultService(service);

    this.driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
  }
}

Answer №1

If you find that your browser needs to be killed after each test run because the containers are being reused, consider adding a hooks file to your support folder. You can include the following code snippet:

After({}, async function(scenario) {
  this.driver.quit();
});

For more information, refer to the documentation here.

Answer №2

After some troubleshooting, I finally figured out the root cause of my issue. It turns out that the driver was being initialized multiple times, resulting in the error message I was encountering. The problem stemmed from creating a new driver instance inside the constructor of the World class in the world.js file. Each time I instantiated the World class, a new driver was being created. To resolve this, I moved the driver declaration outside the class and defined it as follows:

const driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build()
. Additionally, I added a method called initialize() { return driver; } in the world.js file. Now, in my step definition files, I simply call the initialize() method by instantiating a new World object and accessing the driver like so:
let world = new World(); let driver = world.initialize()
. Problem solved!

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

Easily implement a wide variety of fonts in your web projects by dynamically loading hundreds of font

I am in possession of a directory called /assets/fonts containing a plethora of fonts that I wish to incorporate into a website in a dynamic manner. Users will be able to specify their font preferences, akin to a text editor. Individually assigning the fo ...

How to configure headers in Angular 5

When logging in a user, the function returns a token in the response body which is then set in the headers. this.headers = new HttpHeaders({'Content-Type': 'application/json'}); loginUser(email, password) { const body = {emai ...

Find the button for uploading files using Selenium

I am encountering an issue with trying to click the button displayed below (image and HTML). Despite attempting to locate it using both xpath and ID, Selenium is still unable to find it. https://i.stack.imgur.com/KMMku.png <input id="wsUpload1" type= ...

Expand and collapse dynamically while scrolling

// Closing Button for Main Navigation $('button#collapse-button').click(function () { $('nav#main-nav').toggleClass('closed'); }); $(window).on('scroll', function () { if ($(wind ...

Chat Bot - EmbedMessage

JavaScript is still very new to me and I find the actual code quite challenging to grasp. However, I do have one specific question - how can I display the "cahbResponses" in a MessageEmbed? Despite consulting the Discord JS guides on MessageEmbeds, I' ...

Encountering an issue with finding the module `scheduler/tracing` in React Native

Encountering an error during the react-native run-android process: Error: Unable to resolve module `scheduler/tracing` from `/Users/miftahali/projects/react/appscustomec/node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js`: Module ...

An issue with displaying images has been identified within Next.js, resulting in an error message related to the hostname

Encountering an error when using next js Image next.config.js: module.exports = { images: { domains: ['localhost'], }, }; Error image: https://i.stack.imgur.com/RvsdH.png I am struggling to understand how to correctly set up the image ...

Conceal the Vue router on a webpage

How can I hide the vue-router from my login page? I want to remove the menu on the Login page. Is it possible and how would I achieve that? Here is the code for the Login page: Login <template> <div> <h1>Login</h1> ...

I'm feeling a bit lost on how to pull out HTML tag elements using Python

I have been attempting to extract the html tags for alternative purposes, but due to the structure of the html file, I am facing challenges using conventional methods to locate the elements. The section containing the elements is quite long (consisting of ...

Issue: Module - webpack-dev-server.js cannot be located

I'm in the process of creating a React app from scratch. Typically, I use npm create-react-app which sets everything up for you automatically. Following this tutorial https://www.youtube.com/watch?v=deyxI-6C2u4&ab_channel=TraversyMedia has been he ...

Arranging the data in the table by alternating rows using Datatables

I need to organize my data in a way that includes an additional row for descriptive information, but this particular row should not be sorted. It is crucial for understanding the rest of the data, so hiding or showing it is not an option. Is it possible t ...

React Native issue: why are my variables resetting mysteriously?

Hey there, I'm currently encountering a peculiar situation involving the usage of var and React.useState() variables. I am utilizing the library https://github.com/tongyy/react-native-draggable#readme to define 2 variables - var color1 = ''; ...

Obtain the IP address of a Node application running within a Docker container

I currently have a node express application set up in a Docker container, and I am attempting to record the IP address of each incoming request within the app. However, due to running behind a firewall, my current method "req.headers['x-forwarded-for& ...

VueJS Unit Testing: Exploring the Content of Attributes- What to Test?

I'm currently facing some challenges with my initial VueJS unit tests using Jest. Although I grasp the concept and have already executed my first set of successful tests, I find myself pondering over the question of "What aspects should I test?" For ...

Issues with HTML5 audio playback ceasing after a period of time due to a leak

Currently, I am working on developing an HTML5/javascript real-time strategy game. Throughout the gameplay, there are multiple sounds being played continuously. However, what I have noticed is that after a period of time, the sounds seem to "crash" and all ...

Is it possible to leverage node.js as a Read-Eval-Print Loop (RE

This question may sound basic. I am attempting to utilize node.js as a live scripting environment for JavaScript, commonly known as REPL (read-evaluate-print loop). However, I'm facing issues with defining variables and functions within the shell. n ...

Looking for the 64-bit chromedriver.exe for Selenium WebDriver? Find out where to download it now!

Does anyone know where I can locate the 64-bit version of chromedriver.exe? I tried using the 32-bit version as well, but it doesn't seem to be calling the main method. ...

JavaScript (geolocation) error: Unhandled TypeError - Invocation not allowed

Encountering the Javascript error "Uncaught TypeError: Illegal invocation" while executing the code var nativeGeoloation = window.navigator.geolocation.getCurrentPosition; nativeGeoloation(function (){ alert("ok")}); Despite attempting to call the code w ...

Multiple css selectors, Arquillian Graphene

Currently, I am utilizing Arquillian Graphene to locate an element. However, since there are multiple elements with the same class and the ID is generated dynamically, I need to ensure that I am selecting the correct one. Therefore, I am seeking a solutio ...

Verify whether a specific point in time falls within the same week as any date string within an array of date strings

I am working on my backbone-app copyCLDRView and I am trying to replicate weeks along with their components and data. In simpler terms, I want to "copy one week and all its models into another week." My goal is to check if the target week has at least one ...