I'm using Sauce Labs to run my Selenium test scripts with Mocha as the testing framework. Scripts ran perfectly, but the problem is, the job does not finish - seems driver.quit()
is ignored, and I'm prompted a timeout error after 90 secs.
Here's the code:
const { driver } = require('./config');
const { By, until } = require('selenium-webdriver');
describe('Integration test', function () {
this.timeout(20000);
it('can login as test user', function () {
driver.get('https://www.example.com');
driver.wait(until.elementIsNotVisible(driver.findElement(By.id('vale'))), 8000, 'Vale cannot fade');
driver.findElement(By.name('email')).sendKeys('test_user@test.com');
driver.findElement(By.name('password')).sendKeys('password');
return driver.findElement(By.id('authFormSubmitButton')).click();
});
after(() => {
console.log('Quiting driver');
// This does not work!
driver.quit();
});
});
In the config a driver
is built and connected to remote server.
When running this, in the console I can see the test passing and Quiting driver
message, but in Sauce labs dashboard the task just keeps waiting until time out.
Btw I tested the above code with local chromdriver
and everything works fine - driver
is quitted immediately after the task.
Any help or idea is appreciated.
Needs a return
before driver.quit()
.
Instead of calling done(), Mocha accepts a promise as return value. If a test returns a promise, Mocha understands that it’s asynchronous, and waits for the Promise to be resolved before passing to the next test.
This article is valuable.