1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Fix initial test script to wait for app to load

This commit is contained in:
Brett Sun 2016-01-25 17:32:04 +01:00
parent f246005d9c
commit bdc13473a1
2 changed files with 54 additions and 16 deletions

View File

@ -168,20 +168,19 @@ describe('Login logs users in', function() {
let browser; let browser;
``` ```
Create the driver to control the browser. Create the driver to control the browser. `before` will be executed once at the
start of the test before any `it` functions. Use `beforeEach` instead if you'd
like to run some code before each `it` function.
```javascript ```javascript
before(function() { before(function() {
browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80); browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80);
return browser.init({ browserName: 'chrome' });
});
```
This function will be executed before each `it` function. Here we point the // Start the browser, go to /login, and wait for the react app to render
browser to a specific URL. return browser
.init({ browserName, version, platform })
```javascript .get(config.APP_URL + '/login')
beforeEach(function() { .waitForElementByCss('.ascribe-default-app', asserters.isDisplayed, 10000);
return browser.get('http://www.ascribe.ninja/app/login');
}); });
``` ```
@ -208,6 +207,38 @@ without writing new functions.
}); });
``` ```
All together:
```javascript
function testSuite(browserName, version, platform) {
describe(`[${browserName} ${version} ${platform}] Login logs users in`, function() {
// Set timeout to zero so Mocha won't time out.
this.timeout(0);
let browser;
before(function() {
// No need to inject `username` or `access_key`, by default the constructor
// looks up the values in `process.env.SAUCE_USERNAME` and `process.env.SAUCE_ACCESS_KEY`
browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80);
// Start the browser, go to /login, and wait for the react app to render
return browser
.init({ browserName, version, platform })
.get(config.APP_URL + '/login')
.waitForElementByCss('.ascribe-default-app', asserters.isDisplayed, 10000);
});
after(function() {
return browser.quit();
});
it('should contain "Log in" in the title', function() {
return browser.title().should.become('Log in');
});
});
}
```
## How to run the test suite ## How to run the test suite
To run the tests, type: To run the tests, type:
```bash ```bash

View File

@ -1,14 +1,16 @@
'use strict'; 'use strict';
const Q = require('q');
const wd = require('wd'); const wd = require('wd');
const asserters = wd.asserters; // Commonly used asserters for async waits in the browser
const chai = require('chai'); const chai = require('chai');
const chaiAsPromised = require('chai-as-promised'); const chaiAsPromised = require('chai-as-promised');
const config = require('./config.js'); const config = require('./config.js');
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
chai.should(); chai.should();
function testSuite(browserName, version, platform) { function testSuite(browserName, version, platform) {
describe(`[${browserName} ${version} ${platform}] Login logs users in`, function() { describe(`[${browserName} ${version} ${platform}] Login logs users in`, function() {
// Set timeout to zero so Mocha won't time out. // Set timeout to zero so Mocha won't time out.
@ -19,11 +21,17 @@ function testSuite(browserName, version, platform) {
// No need to inject `username` or `access_key`, by default the constructor // No need to inject `username` or `access_key`, by default the constructor
// looks up the values in `process.env.SAUCE_USERNAME` and `process.env.SAUCE_ACCESS_KEY` // looks up the values in `process.env.SAUCE_USERNAME` and `process.env.SAUCE_ACCESS_KEY`
browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80); browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80);
return browser.init({ browserName, version, platform });
});
beforeEach(function() { // Start the browser, go to /login, and wait for the react app to render
return browser.get(config.APP_URL + '/login'); return browser
.init({ browserName, version, platform })
.get(config.APP_URL + '/login')
.waitForElementByCss('.ascribe-default-app', asserters.isDisplayed, 1000)
.catch(function (err) {
console.log('Failure -- unable to load app.');
console.log('Skipping tests for this browser...');
return Q.reject(err);
});
}); });
after(function() { after(function() {
@ -33,7 +41,6 @@ function testSuite(browserName, version, platform) {
it('should contain "Log in" in the title', function() { it('should contain "Log in" in the title', function() {
return browser.title().should.become('Log in'); return browser.title().should.become('Log in');
}); });
}); });
} }