I'm doing automated Mocha testing with Selenium WebDriver on Travis. If I just run the test synchronously and call done()
at the end, the tests pass beautifully. As soon as I introduce async behavior (ie. .then(function(){... done()})
, Travis tests fail, although locally they still run as they're supposed to.
For example:
describe('Map load test', function() {
let driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
this.timeout(60000);
beforeEach(function(done) {
console.log('beforeEach');
driver.get(index).then(function() {
console.log('Loaded index');
done();
});
});
after(function() {
console.log('after');
driver.quit();
});
it('Should load the choropleth demo without issues', function(done) {
console.log('Starting Choropleth test');
driver.getCurrentUrl().then(function(url) {
assert.equal(url, index, 'Initial url did not match');
console.log('loaded' + url);
driver.findElement(By.css('#demo0')).click();
driver.findElement(By.css('.loadDemoButton')).click();
driver.sleep(3000);
console.log('slept for 3000');
driver.getCurrentUrl().then(function(url) {
assert.equal(url, index + '#edit', 'File loaded url did not match');
done();
});
});
});
Results in (Note - doesn't even go into the actual test but fails on beforeEach)
Map load test
beforeEach
1) "before each" hook for "Should load the choropleth demo without issues"
after
0 passing (1m)
1 failing
1) Map load test "before each" hook for "Should load the choropleth demo without issues":
Error: Timeout of 60000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
But doing
beforeEach(function(done) {
console.log('beforeEach');
driver.get(index).then(done());
});
continues on to the next test.
Travis.yml:
language: node_js
addons:
firefox: "latest"
node_js:
- "6.9.0"
- "7.6.0"
before_install:
- wget https://github.com/mozilla/geckodriver/releases/download/v0.13.0/geckodriver-v0.13.0-linux64.tar.gz
- mkdir geckodriver
- tar -xzf geckodriver-v0.13.0-linux64.tar.gz -C geckodriver
- export PATH=$PATH:$PWD/geckodriver
Thanks for any suggestions. Debugging Travis failures is such a PITA...
via Simopaa
No comments:
Post a Comment