blob: fa7744ddabf71c2e820069c11d30846a326a7078 [file] [log] [blame]
// The function exported from this file is used by the protractor_web_test_suite.
// It is passed to the `onPrepare` configuration setting in protractor and executed
// before running tests.
//
// If the function returns a promise, as it does here, protractor will wait
// for the promise to resolve before running tests.
const protractorUtils = require('@bazel/protractor/protractor-utils');
const protractor = require('protractor');
const path = require('path');
module.exports = function(config) {
// In this example, `@bazel/protractor/protractor-utils` is used to run
// the server. protractorUtils.runServer() runs the server on a randomly
// selected port (given a port flag to pass to the server as an argument).
// The port used is returned in serverSpec and the protractor serverUrl
// is the configured.
const isProdserver = path.basename(config.server, path.extname(config.server)) === 'prodserver';
return protractorUtils
.runServer(config.workspace, config.server, '-p', [])
.then(serverSpec => {
// Example app is hosted under `/example` in the prodserver and under `/` in devserver
const serverUrl = `http://localhost:${serverSpec.port}` + (isProdserver ? '/example' : '');
protractor.browser.baseUrl = serverUrl;
});
};