Sean Condon | 6a6f9a0 | 2020-01-09 14:09:36 +0000 | [diff] [blame] | 1 | // 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 | |
| 8 | const protractorUtils = require('@bazel/protractor/protractor-utils'); |
| 9 | const protractor = require('protractor'); |
| 10 | const path = require('path'); |
| 11 | |
| 12 | module.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 | }; |