blob: b45a62d07f91facb569e627f3ce4712635597d7c [file] [log] [blame]
Sean Condon6a6f9a02020-01-09 14:09:36 +00001// The function exported from this file is used by the protractor_web_test_suite.
2// It is passed to the `onPrepare` configuration setting in protractor and executed
3// before running tests.
4//
5// If the function returns a promise, as it does here, protractor will wait
6// for the promise to resolve before running tests.
7
8const protractorUtils = require('@bazel/protractor/protractor-utils');
9const protractor = require('protractor');
10const path = require('path');
11
12module.exports = function(config) {
13 // In this example, `@bazel/protractor/protractor-utils` is used to run
14 // the server. protractorUtils.runServer() runs the server on a randomly
15 // selected port (given a port flag to pass to the server as an argument).
16 // The port used is returned in serverSpec and the protractor serverUrl
17 // is the configured.
18 const isProdserver = path.basename(config.server, path.extname(config.server)) === 'prodserver';
19 return protractorUtils.runServer(config.workspace, config.server, isProdserver ? '-p' : '-port', [])
20 .then(serverSpec => {
21 const serverUrl = `http://localhost:${serverSpec.port}`;
22 protractor.browser.baseUrl = serverUrl;
23 });
24};