-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (68 loc) · 1.86 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* global browser */
/* global protractor */
'use strict';
var enabled = false;
function setup() {
browser.addMockModule('protractorHttpInterceptorModule_', function() {
var serviceId = 'mockedInterceptor';
angular.module('protractorHttpInterceptorModule_', [])
.config([ '$httpProvider', configMock ])
.factory(serviceId, [ mockedInterceptor ]);
var outstandingRequests = 0;
var pendingCallbacks = [];
window.whenNoRequests = function(callback) {
if (outstandingRequests <= 0) {
callback();
} else {
pendingCallbacks.push(callback);
}
};
function mockedInterceptor() {
return {
request : function(config) {
outstandingRequests += 1;
return config;
},
response : function(response) {
outstandingRequests -= 1;
if (outstandingRequests <= 0) {
pendingCallbacks.forEach((cb) => cb());
}
pendingCallbacks = [];
return response
}
};
}
function configMock($httpProvider) {
$httpProvider.interceptors.push('mockedInterceptor');
}
});
protractor.waitForXHROnly = function(enable) {
if (enable) {
enabled = true;
exports.skipAngularStability = true;
} else {
enabled = false;
exports.skipAngularStability = false;
}
};
}
function waitForPromise() {
if (enabled) {
return browser
.executeAsyncScript(
'window.whenNoRequests(arguments[arguments.length -1]);')
.then(function(browserErr) {
if (browserErr) {
throw 'Error while waiting to sync with the page: ' +
JSON.stringify(browserErr);
}
return true
});
} else {
return null;
}
}
exports.setup = setup;
exports.waitForPromise = waitForPromise;
exports.skipAngularStability = false;