7

I have tried for awhile now to try to shutdown the ChromeDriver Service and I can't develop a solution on how to. I am doing a unit test using mocha and chai. The first test passes and the second one fails due to the error.

I tried looking in the selenium-webdrive/chrome.js module and couldn't find a function to close the service. I tried searching for answers but couldn't find anything on the web either. Maybe my approach to creating the chrome driver needs to be reworked. I tried wrapping the creation of the service and the setting of the default service in a if statement using 'selenium-webdriver/chrome.js'.getDefaultService().isRunning() but it fails the first test. I am stumped on this and it is most likely due to lack of knowledge.

This block of called is called during every unit test

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

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

This is the first unit test which passes without error

it('Should pass if the Driver is set to equal the Chrome driver by using chrome', function()
{
        var chromeDriver = Driver( { browserName: 'chrome' } );
        expect(chromeDriver.getCapabilities().browserName).to.equal('Google Chrome');
});

This is the second unit test which causes it to fail

it('Should pass if the Driver is set to equal the Chrome driver by using google chrome', function()
{
        var chromeDriver = Driver( { browserName: 'google chrome' } );
        expect(chromeDriver.getCapabilities().browserName).to.equal('Google Chrome');
});

Error message:

Error: The previously configured ChromeDriver service is still running. You must shut it down before you may adjust its configuration.
  at Error (native)
  at Object.setDefaultService (C:\Users\charles.sexton\WebstormProjects\node_modules\selenium-webdriver\chrome.js:346:11)
  at module.exports (C:\Users\charles.sexton\WebstormProjects\JS-Selenium-Toolkit\src\OrasiDriver.js:90:16)
  at Context.<anonymous> (C:\Users\charles.sexton\WebstormProjects\JS-Selenium-Toolkit\test\test.js:28:32)
  at callFn (C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runnable.js:315:21)
  at Test.Runnable.run (C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runnable.js:308:7)
  at Runner.runTest (C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runner.js:422:10)
  at C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runner.js:533:12
  at next (C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runner.js:342:14)
  at C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runner.js:352:7
  at next (C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runner.js:284:14)
  at Immediate._onImmediate (C:\Users\charles.sexton\WebstormProjects\node_modules\mocha\lib\runner.js:320:5)
Grim
  • 2,398
  • 4
  • 35
  • 54
  • This post may be able to help you http://stackoverflow.com/questions/21320837/release-selenium-chromedriver-exe-from-memory – KCaradonna Feb 24 '16 at 20:21
  • I just tried creating a batch file and using require('child_process').exec('cmd /c Kill_ChromeDriver.bat'); in node.js on windows 7. – Grim Feb 24 '16 at 21:28
  • Same error message and no new error messages, the batch file is in the same directory as the package.json – Grim Feb 24 '16 at 21:29
  • I still need help with this. I have tried various solutions and can't develop a solution that works. I tried running a batch file several times but I can't seem to get it to run the batch file. – Grim Mar 01 '16 at 13:07

1 Answers1

0

Try to execute this command from CMD:

taskkill /T /F /IM chromeserver.exe

When I use selenium to execute my automation scripts, each time there is a new instance of this driver running (which you can see if you open your task manager).

I use Java for scripting, so what I do is that I add this line for killing any active tasks in the beginning of my test:

Runtime.getRuntime().exec("taskkill /T /F /IM chromedriver.exe");
Prateek
  • 1,145
  • 1
  • 8
  • 21
  • I cant get it to work even with the argument that you provided. I did do some testing and with the setTimeout function I was able to check and make sure the chrome driver is running. I couldn't get exec or spawn to work in any way. I have read the child_processes doc several times. – Grim Feb 25 '16 at 13:47