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)