-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 2.26 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function uniteLoadAndWaitForPage(url, timeout) {
return browser.get(url).then(function () {
let rootLocator = $("#root");
return browser.wait(protractor.ExpectedConditions.and(protractor.ExpectedConditions.presenceOf(rootLocator),
function() {
return rootLocator.getText()
.then((text) => {
return text && text.length > 0;
});
}), timeout ? timeout : 5000, "Timeout expired waiting for #root content");
});
}
/* Borrowed from here https://github.com/angular/protractor/pull/4392/files */
function customShadowRoot(selector, starting) {
var selectors = selector.split('::sr');
if (selectors.length === 0) {
return [];
}
var shadowDomInUse = (document.head.createShadowRoot || document.head.attachShadow);
var getShadowRoot = function (el) {
return ((el && shadowDomInUse) ? el.shadowRoot : el);
};
var findAllMatches = function (selector /*string*/, targets /*array*/, firstTry /*boolean*/) {
var scope, i, matches = [];
for (i = 0; i < targets.length; ++i) {
scope = (firstTry) ? targets[i] : getShadowRoot(targets[i]);
if (scope) {
if (selector === '') {
matches.push(scope);
} else {
Array.prototype.push.apply(matches, scope.querySelectorAll(selector));
}
}
}
return matches;
};
var matches = findAllMatches(selectors.shift().trim(), [starting || document], true);
while (selectors.length > 0 && matches.length > 0) {
matches = findAllMatches(selectors.shift().trim(), matches, false);
}
return matches;
}
exports.setup = function () {
browser.ignoreSynchronization = true;
var path = require("path");
var uniteConfig = require(path.join(process.cwd(), "../unite.json"));
if (/aurelia/i.test(uniteConfig.applicationFramework)) {
var app = require("aurelia-protractor-plugin");
app.setup();
browser.uniteLoadAndWaitForPage = browser.loadAndWaitForAureliaPage;
} else {
browser.uniteLoadAndWaitForPage = uniteLoadAndWaitForPage;
}
by.addLocator('customShadowRoot', customShadowRoot);
};