Having developed multiple JavaScript tests using chromedriver to run them in Chrome, I am now facing the challenge of running these same tests in FireFox and IE. The test below is functional in Chrome:
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();
});
});
});
However, I am struggling to make it work on FF and IE. Changing the capabilities to firefox didn't yield the desired outcome. For IE, despite downloading the IEDriverServer and placing it in the same folder as the chromedriver, changing the driver capabilities to internetexplorer resulted in failed tests.
When attempting to run the test with internetexplorer capabilities, the following error occurred:
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)
...
Switching the capabilities to firefox produced a different 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
...
I've been stuck on this issue for some time now and would greatly appreciate any assistance. It could be a minor oversight on my part, but so far I haven't been able to resolve it.
Thank you, Anthony