Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set protractor(v1.4.0) baseUrl using protractor API instead of configuration file?

i use protractor v1.4.0 and I want to set protractor baseUrl from command line so i can't use

baseUrl: 'http://localhost:8000/',

config option in protractor configuration file. I want to define default value for base url with "params" option in protractor configuration file as follows:

params: { baseUrl: 'http://localhost:8080/' },

and then overwrite the default value by passing a new value from command line when i run protractor as follows:

protractor 'path_to_my_conf_file' --params.baseUrl http://localhost:80/

then in my spec file i need to set base url using protractor API, but i can't find how to do that.

The 1-st answer to the following question is exactly what i need but it doesn't work.

How can I add URL's dynamically to Protractor tests?

like image 695
Suren Aznauryan Avatar asked Dec 03 '14 15:12

Suren Aznauryan


3 Answers

As another option, could also try browser.baseUrl = "https://test-url.com" in onPrepare (works in Protractor 1.4.0)

like image 155
user1161657 Avatar answered Dec 01 '22 12:12

user1161657


You can just change it from the command line like so:

protractor --baseUrl http://whateveryouwant
like image 37
Jmr Avatar answered Dec 01 '22 11:12

Jmr


Run tests via grunt with grunt-protractor-runner and grunt-option libraries:

protractor: {
    options: {
        configFile: "path_to_my_conf_file",
        args: {
            baseUrl: grunt.option('baseUrl', 'http://localhost:80/')
        }
    }
}

Then, run the task via:

grunt protractor --baseUrl=http://mynewurl

And, to let it use the default baseUrl, just run:

grunt protractor
like image 28
alecxe Avatar answered Dec 01 '22 13:12

alecxe