forked from cloudfoundry-community/stratos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protractor.conf.js
290 lines (258 loc) · 9.44 KB
/
protractor.conf.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const {
SpecReporter
} = require('jasmine-spec-reporter');
const moment = require('moment');
const skipPlugin = require('./src/test-e2e/skip-plugin.js');
const globby = require('globby');
const timeReporterPlugin = require('./src/test-e2e/time-reporter-plugin.js');
const browserReporterPlugin = require('./src/test-e2e/browser-reporter-plugin.js');
const https = require('https');
const {
ProtractorBrowserLogReporter
} = require('jasmine-protractor-browser-log-reporter');
// Test report folder name
var timestamp = moment().format('YYYYDDMM-hh.mm.ss');
var reportFolderName = timestamp + '-e2e-report';
const SECRETS_FILE = 'secrets.yaml';
const E2E_REPORT_FOLDER = process.env['E2E_REPORT_FOLDER'] || './e2e-reports/' + reportFolderName;
var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');
var browserstackHelper = require('./src/test-e2e/browserstack-helper.js');
const secretsPath = path.join(__dirname, SECRETS_FILE);
if (!fs.existsSync(secretsPath)) {
console.log('No secrets.yaml found at ... ', secretsPath);
console.log('Please provide a secrets.yaml, see `src/test-e2e/secrets.yaml.example` as reference.');
process.exit(1);
}
let secrets = {};
try {
secrets = yaml.safeLoad(fs.readFileSync(secretsPath, 'utf8'));
} catch (e) {
console.log('Invalid e2e secrets.yaml configuration file');
console.log(e);
process.exit(1);
}
// This is the maximum amount of time ALL before/after/it's must execute in
let timeout = 40000;
const checkSuiteGlob = './src/test-e2e/check/*-e2e.spec.ts';
if (process.env.STRATOS_SCRIPTS_TIMEOUT) {
timeout = parseInt(process.env.STRATOS_SCRIPTS_TIMEOUT);
console.log('Setting allScriptsTimeout to: ' + timeout);
}
// Allow test report to show relative times of tests
const specReporterCustomProcessors = [];
let showTimesInReport = false;
if (process.env.STRATOS_E2E_LOG_TIME || browserstackHelper.isConfigured()) {
specReporterCustomProcessors.push(timeReporterPlugin);
showTimesInReport = true;
}
function safeExcludeSuite(suite) {
return suite.map(file => file && file[0] !== '!' ? '!' + file : file);
}
const excludeTests = [
'!./src/test-e2e/login/*-sso-e2e.spec.ts',
'!' + checkSuiteGlob
];
const fullSuite = globby.sync([
'./src/test-e2e/**/*-e2e.spec.ts',
]);
const longSuite = globby.sync([
'./src/test-e2e/application/application-delete-e2e.spec.ts',
'./src/test-e2e/application/application-deploy-e2e.spec.ts',
'./src/test-e2e/application/application-deploy-local-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/cf-level/cf-users-list-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/org-level/org-users-list-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/space-level/space-users-list-e2e.spec.ts'
]);
const longServicesSuite = globby.sync([
'./src/test-e2e/marketplace/**/*-e2e.spec.ts',
]);
const manageUsersSuite = globby.sync([
'./src/test-e2e/cloud-foundry/manage-users-stepper-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/cf-level/cf-users-removal-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/org-level/org-users-removal-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/space-level/space-users-removal-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/cf-level/cf-invite-config-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/org-level/org-invite-user-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/space-level/space-invite-user-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/manage-users-by-username-stepper-e2e.spec.ts'
]);
const coreSuite = globby.sync([
'./src/test-e2e/check/check-login-e2e.spec.ts',
'./src/test-e2e/endpoints/endpoints-connect-e2e.spec.ts',
'./src/test-e2e/endpoints/endpoints-e2e.spec.ts',
'./src/test-e2e/endpoints/endpoints-register-e2e.spec.ts',
'./src/test-e2e/endpoints/endpoints-unregister-e2e.spec.ts',
'./src/test-e2e/home/home-e2e.spec.ts',
'./src/test-e2e/login/login-e2e.spec.ts',
'./src/test-e2e/login/login-sso-e2e.spec.ts',
'./src/test-e2e/metrics/metrics-registration-e2e.spec.ts',
]);
const autoscalerSuite = globby.sync([
'./src/test-e2e/application/application-autoscaler-e2e.spec.ts',
]);
const cfSummaryAndBelow = globby.sync([
'./src/test-e2e/cloud-foundry/**/*-e2e.spec.ts',
...safeExcludeSuite(manageUsersSuite),
...safeExcludeSuite(longSuite),
]);
const fullMinusOtherSuites = globby.sync([
...fullSuite,
...safeExcludeSuite(longSuite),
...safeExcludeSuite(longServicesSuite),
...safeExcludeSuite(manageUsersSuite),
...safeExcludeSuite(coreSuite),
...safeExcludeSuite(autoscalerSuite),
...safeExcludeSuite(cfSummaryAndBelow),
]);
const config = {
allScriptsTimeout: timeout,
// Exclude the dashboard tests from all suites for now
exclude: [
'./src/test-e2e/dashboard/dashboard-e2e.spec.ts',
],
// Suites - use globby to give us more control over included test specs
suites: {
e2e: globby.sync([
...fullSuite,
...excludeTests
]),
longSuite: globby.sync([
...longSuite,
...excludeTests
]),
longServicesSuite: globby.sync([
...longServicesSuite,
...excludeTests
]),
manageUsers: globby.sync([
...manageUsersSuite,
...excludeTests
]),
core: globby.sync([
...coreSuite,
...excludeTests
]),
autoscaler: globby.sync([
...autoscalerSuite,
...excludeTests
]),
cfSummaryAndBelow: globby.sync([
...cfSummaryAndBelow,
...excludeTests
]),
fullMinusOtherSuites: globby.sync([
...fullMinusOtherSuites,
...excludeTests
]),
sso: globby.sync([
...fullSuite,
'!./src/test-e2e/login/login-e2e.spec.ts',
'!' + checkSuiteGlob
]),
check: checkSuiteGlob,
},
// Default test suite is the E2E test suite
suite: 'e2e',
capabilities: {
'browserName': 'chrome',
chromeOptions: {
useAutomationExtension: false,
args: ['--no-sandbox', '--disable-dev-shm-usage', '--disable-infobars']
},
acceptInsecureCerts: true
},
directConnect: true,
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: timeout,
print: function () { }
},
params: secrets,
plugins: [],
onPrepare() {
// https://webdriver.io/docs/api/chromium.html#setnetworkconditions
// browser.driver.setNetworkConditions({
// offline: false,
// latency: 2000, // Additional latency (ms).
// download_throughput: 500 * 1024 * 1024, // Maximal aggregated download throughput.
// upload_throughput: 500 * 1024 * 1024 // Maximal aggregated upload throughput.
// });
// Ensuer base URL does NOT end with a /
if (browser.baseUrl.endsWith('/')) {
browser.baseUrl = browser.baseUrl.substr(0, browser.baseUrl.length - 1);
}
jasmine.getEnv().addReporter(new ProtractorBrowserLogReporter());
skipPlugin.install(jasmine);
require('ts-node').register({
project: 'src/test-e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: 'raw',
},
summary: {
displayStacktrace: 'raw',
},
customProcessors: specReporterCustomProcessors
}));
jasmine.getEnv().addReporter(skipPlugin.reporter());
if (showTimesInReport) {
browserReporterPlugin.install(jasmine, browser);
jasmine.getEnv().addReporter(browserReporterPlugin.reporter());
}
// Validate that the Github API url that the client will use during e2e tests is responding
const githubApiUrl = secrets.stratosGitHubApiUrl || 'https://api.github.com';
const path = '/repos/nwmac/cf-quick-app';
console.log(`Validating Github API Url Using: '${githubApiUrl + path}'`);
// This chunk can disappear when we update node to include the version of http that accepts `get(url, option, callback)`
const hasHttps = githubApiUrl.indexOf('https://') === 0;
const tempHost = hasHttps ? githubApiUrl.substring(8, githubApiUrl.length) : githubApiUrl;
const hasPort = tempHost.indexOf(':') >= 0;
const port = hasPort ? parseInt(tempHost.substring(tempHost.indexOf(':') + 1, tempHost.length)) : hasHttps ? 443 : null;
const host = hasPort ? tempHost.replace(':' + port, '') : tempHost;
const options = {
host,
port,
path,
accept: '*/*',
method: 'GET',
// Required by github to avoid 403
headers: {
'User-Agent': 'request'
},
rejectUnauthorized: false
};
var defer = protractor.promise.defer();
https
.get(options, (resp) => {
if (resp.statusCode >= 400) {
defer.reject('Failed to validate Github API Url. Status Code: ' + resp.statusCode);
} else {
defer.fulfill('Validated Github API Url successfully');
}
})
.on("error", (err) => {
defer.reject('Failed to validate Github API Url: ' + err.message);
});
// Print out success, errors fall through
return defer.promise.then(res => console.log(res));
}
};
if (process.env['STRATOS_E2E_BASE_URL']) {
config.baseUrl = process.env['STRATOS_E2E_BASE_URL'];
}
exports.config = config;
// Should we run e2e tests in headless Chrome?
const headless = secrets.headless || process.env['STRATOS_E2E_HEADLESS'];
if (headless) {
exports.config.capabilities.chromeOptions.args = ['--headless', '--allow-insecure-localhost', '--disable-gpu', '--window-size=1366,768', '--no-sandbox'];
}
// Browserstack support
if (browserstackHelper.isConfigured()) {
exports.config = browserstackHelper.configure(exports.config);
}