-
Notifications
You must be signed in to change notification settings - Fork 0
/
aurelia-webdriver-plugin.js
69 lines (65 loc) · 2.24 KB
/
aurelia-webdriver-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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
browser.addCommand("waitForAureliaPage", function () {
return browser.executeAsync(function (done) {
const routerHook = function () {
const qs = document.querySelector("[aurelia-app]");
if (qs) {
if (qs.aurelia) {
if (!qs.aurelia.WEBDRIVERIO_NAVIGATION_READY) {
qs.aurelia.WEBDRIVERIO_NAVIGATION_READY = [];
qs.aurelia.WEBDRIVERIO_WAIT_ID = 0;
qs.aurelia.subscribe("router:navigation:complete", function () {
qs.aurelia.WEBDRIVERIO_NAVIGATION_READY.push(qs.aurelia.WEBDRIVERIO_WAIT_ID);
});
}
}
}
};
if (document.querySelector("[aurelia-app]")) {
routerHook();
done();
} else {
document.addEventListener("aurelia-composed", function () {
routerHook();
done();
});
}
});
});
browser.addCommand("loadAndWaitForAureliaPage", function (url) {
return browser
.url(url)
.waitForAureliaPage();
});
browser.addCommand("waitForRouterComplete", function () {
let waitId = 0;
return browser
.executeAsync(function (done) {
const qs = document.querySelector("[aurelia-app]");
if (qs) {
if (qs.aurelia) {
qs.aurelia.WEBDRIVERIO_WAIT_ID++;
waitId = qs.aurelia.WEBDRIVERIO_WAIT_ID;
done();
} else {
done();
}
} else {
done();
}
})
.waitUntil(function () {
browser.executeAsync(function (done) {
const qs = document.querySelector("[aurelia-app]");
if (qs) {
if (qs.aurelia) {
done(qs.aurelia.WEBDRIVERIO_NAVIGATION_READY &&
qs.aurelia.WEBDRIVERIO_NAVIGATION_READY.indexOf(waitId) > 0);
} else {
done(false);
}
} else {
done(false);
}
});
});
});