Skip to content

Commit

Permalink
functional tests: try reloading page on error
Browse files Browse the repository at this point in the history
Attempts to fix
https://saucelabs.com/job/9d1712e8df32462889cc8686a0038e61 where I think
the web server hasn't initialised in time
  • Loading branch information
tjenkinson authored and mangui committed Feb 9, 2017
1 parent 7db86ae commit cf1028e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"watch": "watchify --debug -s Hls src/index.js -t [babelify] -o dist/hls.js",
"pretest": "npm run lint",
"test": "mocha --compilers js:babel-register --recursive tests/unit",
"testfunc": "mocha --compilers js:babel-register --recursive tests/functional/auto --timeout 40000",
"testfunc": "mocha --compilers js:babel-register tests/functional/auto/hlsjs.js --timeout 40000",
"lint": "jshint src/",
"serve": "http-server -p 8000 .",
"open": "opener http://localhost:8000/demo/",
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/auto/hlsjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
}
</script>
</head>
<body>
<body id="hlsjs-functional-tests">
<video id="video"></video>
<div id="log">
<div class="inner"></div>
Expand Down
44 changes: 39 additions & 5 deletions tests/functional/auto/hlsjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ var chromedriver = require('chromedriver');
var HttpServer = require('http-server');
var streams = require('../streams.json');

function retry(cb, numAttempts, interval) {
numAttempts = numAttempts || 20;
interval = interval || 3000;
return new Promise(function(resolve, reject) {
var attempts = 0;
attempt();

function attempt() {
cb().then(function(res) {
resolve(res);
}).catch(function(e) {
if (++attempts >= numAttempts) {
// reject with the last error
reject(e);
}
else {
setTimeout(attempt, interval);
}
});
}
});
}

var onTravis = !!process.env.TRAVIS;
var STREAM_ID = onTravis ? process.env.TEST_STREAM_ID : 'arte';
if (!STREAM_ID) {
Expand Down Expand Up @@ -74,11 +97,22 @@ describe('testing hls.js playback in the browser with "'+stream.description+'" o
console.log("Retrieving web driver session...");
return this.browser.getSession().then(function(session) {
console.log("Web driver session id: "+session.getId());
console.log("Loading test page...");
return this.browser.get('http://localhost:8000/tests/functional/auto/hlsjs.html');
}.bind(this)).then(function() {
console.log("Test page loaded.");
});
if (onTravis) {
console.log("Job URL: https://saucelabs.com/jobs/"+session.getId());
}
return retry(function() {
console.log("Loading test page...");
return this.browser.get('http://127.0.0.1:8000/tests/functional/auto/hlsjs.html').then(function() {
// ensure that the page has loaded and we haven't got an error page
return this.browser.findElement(webdriver.By.css('body#hlsjs-functional-tests')).catch(function(e) {
console.log("Test page not loaded.");
return Promise.reject(e);
});
}.bind(this));
}.bind(this)).then(function() {
console.log("Test page loaded.");
});
}.bind(this));
});

afterEach(function() {
Expand Down

0 comments on commit cf1028e

Please sign in to comment.