Reputation: 419
I have multiple JavaScript tests created that use the chromedriver to run tests in Chrome and I now want to run the same tests in FireFox and IE. This is one of my tests and it works correctly in Chrome with no issues:
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver');
test.describe('Click current location button.', function () {
test.it('Seems to have worked.', function () {
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
// Open Chrome (as specified by the Capabilities above) and go to the specified web page
driver.get('website url').
then(function () {
driver.wait(function () {
console.log("Looking for username");
return driver.findElement(webdriver.By.id('user_username')).isDisplayed();
}, 5000, 'Page did not load within 5 seconds');
driver.findElement(webdriver.By.id("user_username")).sendKeys('user');
driver.findElement(webdriver.By.id("user_password")).sendKeys('pword');
return driver.findElement(webdriver.By.id("signIn")).click();
}).
then(function () {
driver.sleep(4000);
// make sure page has loaded
driver.wait(function () {
console.log("Looking for current button");
return driver.findElement(webdriver.By.id('gaz_input')).isDisplayed();
}, 5000, 'Page did not load within 5 seconds');
// Click Accept cookies to prevent issues
if (driver.findElement(webdriver.By.xpath("//a[@class='cc-cookie-accept']")).isDisplayed()) {
driver.findElement(webdriver.By.xpath("//a[@class='cc-cookie-accept']")).click();
}
driver.sleep(1000);
// Click the current location button
driver.findElement(webdriver.By.xpath("//button[@class='btn']")).click();
console.log("Looking for search results");
driver.manage().timeouts().implicitlyWait(60000);
if (!driver.findElement(webdriver.By.xpath("//div[@class='panel panel-default']")).isDisplayed()) {
driver.wait(function () {
return driver.findElement(webdriver.By.xpath("//div[@class='panel panel-default']")).isDisplayed();
}, 2000, 'Query did not complete within 60 seconds.');
}
driver.sleep(1000);
}).
then(function () {
// Close the browser
return driver.quit();
});
});
});
So now I want to run this test in FF and IE. I thought that with FF all I had to do was change the capabilities and that it should just work but that didn't happen. For IE I thought I just had to just download the IEDriverServer and put it in the same folder as the chromedriver but when I did that and changed the driver capabilities from chrome to internetexplorer the tests do not work for it either.
If I try running the test when the capabilities are set to internetexplorer I get this error:
C:\Projects\build>mocha ietest.js
.
0 passing (42ms)
1 failing
1) Click current location button. Seems to have worked.:
TypeError: Object function (opt_other) {
/** @private {!Object} */
this.caps_ = {};
if (opt_other) {
this.merge(opt_other);
}
} has no method 'internetexplorer'
at Context.<anonymous> (C:\Projects\build\ietest.js:9:43)
at webdriver.promise.ControlFlow.runInNewFrame_ (C:\Projects\build\node_modules\selenium-webdriver\lib\webdriver\promise.js:1598:20)
at webdriver.promise.ControlFlow.runEventLoop_ (C:\Projects\build\node_modules\selenium-webdriver\lib\webdriver\promise.js:1463:8)
at wrapper [as _onTimeout] (timers.js:252:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
at Context.<anonymous> (C:\Projects\build\node_modules\selenium-webdriver\testing\index.js:126:14)
at Test.Runnable.run (C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:196:15)
at Runner.runTest (C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:374:10)
at C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:452:12
at next (C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:299:14)
at C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:309:7
at next (C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:247:23)
at Object._onImmediate (C:\Users\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
And if I change the capabilities to firefox I get this error:
C:\Projects\build>mocha ietest.js
.
0 passing (1s)
1 failing
1) Click MyNearest current location button. Seems to have worked.:
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (C:\Projects\build\node_modules\selenium-webdriver\http\index.js:128:16)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (C:\Projects\build\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:131:49)
at Function.webdriver.WebDriver.createSession (C:\Projects\build\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:111:30)
at Builder.build (C:\Projects\build\node_modules\selenium-webdriver\builder.js:106:20)
at Context.<anonymous> (C:\Projects\build\ietest.js:10:3)
at webdriver.promise.ControlFlow.runInNewFrame_ (C:\Projects\build\node_modules\selenium-webdriver\lib\webdriver\promise.js:1598:20)
at webdriver.promise.ControlFlow.runEventLoop_ (C:\Projects\build\node_modules\selenium-webdriver\lib\webdriver\promise.js:1463:8)
at wrapper [as _onTimeout] (timers.js:252:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
==== async task ====
at Context.<anonymous> (C:\Projects\build\node_modules\selenium-webdriver\testing\index.js:126:14)
at Test.Runnable.run (C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:196:15)
at Runner.runTest (C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:374:10)
at C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:452:12
at next (C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:299:14)
at C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:309:7
at next (C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:247:23)
at Object._onImmediate (C:\Users\akeogh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
I have been fighting this issue for a long time now without any success, any help really would be appreciated. It may just be something small that I'm not doing correctly but I haven't been able to figure it out.
thanks, Anthony
Upvotes: 0
Views: 3684
Reputation: 21
I know it has been a while since this question was asked, but for anyone coming across this issue, this might help.
It looks like the Selenium Server hasn't started for you. I wait for the Server to start before executing code against it.
function startSeleniumServer(callback) {
seleniumServer = new SeleniumServer(path/to/selenium/server/jar, { port: 4444 });
var promise = seleniumServer.start();
promise.then(function() {
console.log("Selenium Server: Started");
return callback();
});
};
Upvotes: 0
Reputation: 11
For Firefox, see the code example in the WebDriverJs documentation at https://code.google.com/p/selenium/wiki/WebDriverJs#Using_the_Stand-alone_Selenium_Server. You will need to install the Stand-alone Selenium Server, and fill in the pathToSeleniumJar in the code example with the appropriate value.
For IE, you do something similiar:
var webdriver = require('selenium-webdriver'),
SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
var pathToSeleniumJar = 'C:\\selenium-2.41.0\\selenium-server-standalone-2.41.0.jar';
var server = new SeleniumServer(pathToSeleniumJar, {
port: 4444
});
server.start();
var driver = new webdriver.Builder().
usingServer(server.address()).
withCapabilities(webdriver.Capabilities.ie()).
build();
This should work as the IE Driver should already be in your path. Also see https://code.google.com/p/selenium/wiki/InternetExplorerDriver for tweaks you may need to do to your IE settings.
Upvotes: 1