-
Notifications
You must be signed in to change notification settings - Fork 5
/
protractor-testability-plugin.js
42 lines (39 loc) · 1.72 KB
/
protractor-testability-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* global browser */
'use strict';
var fs = require('fs');
return (module.exports = {
name: 'protractor-testability-plugin',
onPageLoad: function () {
var testability = fs.readFileSync(require.resolve('testability.js')).toString();
var browserInstrumentation = require('testability-browser-bindings');
var protractorBindings = require('./client/protractor-bindings');
browser.executeScript('if(!window.testability) {(function(){' +
testability +
'}.bind(window))()}');
browser.executeScript(function (browserInstrumentation) {
var head = document.getElementsByTagName('head')[0];
var scriptText='(' + browserInstrumentation + ')();';
var scriptEl = document.createElement( 'script' );
scriptEl.type = 'text/javascript';
scriptEl.textContent = scriptText;
head.insertBefore( scriptEl, head.firstChild );
}, browserInstrumentation.toString());
browser.executeScript(
protractorBindings,
JSON.stringify(this.config.customFrameworkTestability, function replacer (key, item) {
return typeof item === 'function' ? 'var temp=' + item.toString() + ';temp;': item;
})
);
},
waitForPromise: function () {
return browser.executeAsyncScript(function (cb) {
return window.testability ?
window.testability.when.ready(cb):
cb('Error, testability is not loaded in the browser window :-(.');
}).then(function (browserErr) {
if (browserErr) {
throw 'Error while waiting to sync with the page: ' + JSON.stringify(browserErr);
}
});
}
});