user1161657
user1161657

Reputation: 991

Setting Protractor baseUrl dynamically

In our end-to-end tests, we dynamically generate the URL endpoint for us to test against. In our Protractor configuration, I was hoping to use beforeLaunch or onPrepare to retrieve the URL endpoint and set it to baseUrl before running our tests. However it seems no matter what I try, Protractor runs tests with the wrong baseUrl, not the one I set in beforeLaunch or onPrepare.

We're using Protractor version 1.4.0. This is a simple configuration file demonstrating the issue:

exports.config =
    directConnect: true

    framework: 'jasmine'

    jasmineNodeOpts:
        isVerbose: true
        showColors: true
        includeStackTrace: true

    suites:
        login: 'login/**/*.coffee'
        full: '**/*.coffee'

    capabilities:
        browserName: 'chrome'

    beforeLaunch: ->
        setBaseUrl 'https://test-url.com'

    onPrepare: ->
        setBaseUrl 'https://test-url.com'

setBaseUrl = (baseUrl) ->
    exports.config.baseUrl = baseUrl

Thanks for the help!

Upvotes: 3

Views: 1793

Answers (1)

user1161657
user1161657

Reputation: 991

It looks like calling browser.baseUrl = "https://test-url.com" does the trick in onPrepare

Upvotes: 2

Related Questions