Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [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 | |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 11 | module.exports = function (config) { |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 12 | // In this example, `@bazel/protractor/protractor-utils` is used to run |
| 13 | // the server. protractorUtils.runServer() runs the server on a randomly |
| 14 | // selected port (given a port flag to pass to the server as an argument). |
| 15 | // The port used is returned in serverSpec and the protractor serverUrl |
| 16 | // is the configured. |
| 17 | return protractorUtils |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 18 | .runServer(config.workspace, config.server, '--port', []) |
| 19 | .then((serverSpec) => { |
| 20 | protractor.browser.baseUrl = `http://localhost:${serverSpec.port}`; |
| 21 | }); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 22 | }; |