-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (56 loc) · 2.44 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
exports = module.exports = function () {
browser.timeouts("script", 30000);
var path = require("path");
var uniteConfig = require(path.join(process.cwd(), "../unite.json"));
if (/aurelia/i.test(uniteConfig.applicationFramework)) {
require("./aurelia-webdriver-plugin");
browser.addCommand("uniteLoadAndWaitForPage", function (url) {
return browser
.url(url)
.waitForAureliaPage();
});
} else {
browser.addCommand("uniteLoadAndWaitForPage", function (url, timeout) {
return browser
.url(url)
.waitUntil(function () {
return browser.getText("#root")
.then(function (text) {
return text && text.length > 0;
});
}, timeout ? timeout : 5000);
});
}
/* Borrowed from here https://github.com/angular/protractor/pull/4392/files */
browser.addCommand("customShadowRoot", function (selector, starting) {
return browser.execute(function (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;
}, selector, starting);
});
};