Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access parameters in my protractor configuration file?

I start my protractor tests by running the following:

protractor protractor.conf.js --params.baseUrl=http://www.google.com --suite all 

I would like to run a 'before launch' function which is dependant of one parameter (in this case, the baseUrl). Is it that possible?

exports.config = {     seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',     seleniumPort: 4455,     suites: {         all: 'test/*/*.js',     },     capabilities: {         'browserName': 'firefox'     },     beforeLaunch: function() {         console.log('I want to access my baseUrl parameter here: ' + config.params.baseUrl);     },     onPrepare: function() {          require('jasmine-reporters');         jasmine.getEnv().addReporter(             new jasmine.JUnitXmlReporter('output/xmloutput', true, true));      } }; 

If I run that I get a ReferenceError because config is not defined. How should I do that? Is that even possible?

like image 478
Julio Avatar asked Apr 02 '15 07:04

Julio


People also ask

What is config file in Protractor?

The configuration file tells Protractor how to set up the Selenium Server, which tests to run, how to set up the browsers, and which test framework to use. The configuration file can also include one or more global settings.

How do you use a global variable in Protractor?

It is possible to set globals from the Protractor config file with the help of params property: exports. config = { // ... params: { glob: 'test' } // ... };


1 Answers

I am not completely sure if protractor globals are set at the beforeLaunch() stage, but they are definitely available at onPrepare() step.

Access the params object through the global browser object:

console.log(browser.params.baseUrl); 

Update: Using Jasmine 2.6+, protractor 4.x, browser.params was empty, but the following worked in onPrepare() step:

console.log(browser.baseUrl); 
like image 70
alecxe Avatar answered Oct 19 '22 05:10

alecxe