0
votes

I am using CucumberJS with Selenium-Webdriver for automating my test cases. Currently I am having multiple feature files with their respective step-definition files. When I am trying to run the test cases then it is throwing an error:

Error: The previously configured ChromeDriver service is still running. You must shut it down before you may adjust its configuration. 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) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Module.require (module.js:597:17) at require (internal/module.js:11:18) at supportCodePaths.forEach.codePath (D:\code\egov-test-cases\node_modules\cucumber\lib\cli\index.js:142:42) at Array.forEach () at Cli.getSupportCodeLibrary (D:\code\egov-test-cases\node_modules\cucumber\lib\cli\index.js:142:22) at D:\code\egov-test-cases\node_modules\cucumber\lib\cli\index.js:169:41 at Generator.next () at asyncGeneratorStep (D:\code\egov-test-cases\node_modules\cucumber\lib\cli\index.js:44:103) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Since I am automating the tests, I have put the below code for automating chrome in world.js file, and then tried importing the driver from world.js, but still it is giving 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();
  }
}
2
Are you killing the driver in the after hooks? If not I recommend you do and cleanup after each testRay
No, actually I don't know how to do that.Megha Verma
Added an answer belowRay

2 Answers

0
votes

What you may need to do is kill your browser after each test run as the containers are reused(hence why a browser may already be running). To do this you will want to add a hooks file to your support folder and include something as follows

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

for more info take a look at the docs https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md

0
votes

I found the solution to my problem. Actually the driver was getting initialized multiple times and that is why it was giving me the above error. I was creating the driver inside the constructor in the class World in world.js file. Everytime i was taking an instance of the class World, I was creating a new driver. I shifted the driver declaration outside the class as const driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build() and created a method as initialize() { return driver; } in world.js file. I am calling the initialize() method in my step definition files as let world = new World(); let driver = world.initialize(). Now I am good to go!