Skip to content
This repository was archived by the owner on Mar 6, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ function recordStep(step, args) {
let task = `${step.name}: ${step.humanizeArgs()}`;
let val;

// check to ensure browser is loaded
recorder.add('wait-for-browser-ready', function(){
return new Promise((resolve, reject) => {

if (step.helper.isReady || step.helper.isReady === undefined) {
resolve();
} else {

// Check for the page to be loaded for n number of times.
var checkTimes = 100;

// poll every n ms to see if page has loaded
var check = setInterval(() => {

// the page is now ready
if(step.helper.isReady){
resolve();
clearInterval(check);
}

checkTimes--;
// If check times is below 0 then throw an error as the page is unable to load
if(checkTimes < 0){
clearInterval(check);
reject(`${step.helperMethod} failed to inject codecept.js`);
}

}, 100);

}

});
});

// run step inside promise
recorder.add(task, () => {
event.emit(event.step.started, step);
Expand Down
1 change: 1 addition & 0 deletions lib/codecept.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

let Mocha = require('mocha/lib/mocha');
let fsPath = require('path');
let readFileSync = require('fs').readFileSync;
let readdirSync = require('fs').readdirSync;
Expand Down
2 changes: 2 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,6 @@ class Helper {

}

Helper.isReady = true;

module.exports = Helper;
9 changes: 8 additions & 1 deletion lib/helper/Nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ class Nightmare extends Helper {

_startBrowser() {
this.browser = this.Nightmare(this.options);
this.browser.on('dom-ready', () => this._injectClientScripts());
this.browser.on('did-start-loading', () => {
this.isReady = false;
});
// when dom is ready, inject client script and set our flag to true to enable tests to run again
this.browser.on('dom-ready', () => {
this._injectClientScripts();
this.isReady = true;
});
this.browser.on('console', (type, message) => {
this.debug(`${type}: ${message}`);
});
Expand Down