I'm using the following code (taken from Setting up your own test automation environment )
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver_fx = new webdriver.Builder()
.forBrowser('firefox')
.usingServer('http://localhost:4444/wd/hub')
.build();
var driver_chr = new webdriver.Builder()
.forBrowser('chrome')
.usingServer('http://localhost:4444/wd/hub')
.build();
searchTest(driver_fx);
searchTest(driver_chr);
function searchTest(driver) {
driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.sleep(1000).then(function() {
driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});
driver.findElement(By.name('btnK')).click();
driver.sleep(2000).then(function() {
driver.getTitle().then(function(title) {
if(title === 'webdriver - Google Search') {
console.log('Test passed');
} else {
console.log('Test failed');
}
driver.quit();
});
});
}
It's supposed to go open both firefox and chrome, go to google, enter some text in the input, click the search button and then check the window title.
I run the selenium server using:
java -Dwebdriver.gecko.driver=/home/sean/bin/geckodriver -Dwebdriver.chrome.driver=/home/sean/bin/chromedriver ar ~/Downloads/selenium-server-standalone-3.14.0.jar
And then node index.js
to run the tests. This opens both firefox and chrome and gives this error:
WebDriverError: Element <input name="btnK" type="submit"> is not clickable at point (564,411) because another element <div class="sbqs_c"> obscures it
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: 'mx', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-46-generic', java.version: '1.8.0_171'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (/home/sean/workspace/selenium-test/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/home/sean/workspace/selenium-test/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/home/sean/workspace/selenium-test/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:118:7)
From: Task: WebElement.click()
at thenableWebDriverProxy.schedule (/home/sean/workspace/selenium-test/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
at WebElementPromise.schedule_ (/home/sean/workspace/selenium-test/node_modules/selenium-webdriver/lib/webdriver.js:2010:25)
at WebElementPromise.click (/home/sean/workspace/selenium-test/node_modules/selenium-webdriver/lib/webdriver.js:2092:17)
at searchTest (/home/sean/workspace/selenium-test/index.js:58:39)
at Object.<anonymous> (/home/sean/workspace/selenium-test/index.js:47:1)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
If I run the tests in 1 browser at a time they both pass.
I tried not using selenium server and letting selenium-webdriver module handle starting the processes. Also tried starting a hub with multiple nodes (in the same machine) and running each browser in a different node. All with the same error.
Am I correct to understand that if my tests have actions such as click() then only 1 browser instance (same webdriver or not) must be open at a time in the same physical/virtual machine to avoid browser windows overlapping each other?
What are the best practices? 1 docker per each selenium node and setting maxSession 1 for each node? only opening a single browser and running all tests there?
Are there test automation tools which do not have this constraint?
Edit: using 3rd party services such as browserstack and saucelabs is not an option
Aucun commentaire:
Enregistrer un commentaire