How to read parameter's value, present in conf

2019-02-28 20:16发布

问题:

Ex: conf.js

exports.config = {

    directConnect: false,

    // multiCapabilities: [{
    //     browserName: 'firefox'
    // }, {
    //     browserName: 'chrome'
    // }, {
    //     browserName: 'internet explorer'
    // }],


    specs: ['Specs/spec.js'],

    seleniumAddress: 'http://localhost:4444/wd/hub',

}

Specs:

 it('should be able to select the required organization', function() {

            Select_Organization.selectOrganization();

            //console.log(browser.seleniumAddress);
//This is where I need to read the config paramater values, but above is printing undefined.

            expect(browser.getTitle()).toEqual('p3 by NextGen - CSR & Development Capital Management Platform');
     });

I need to read the parameter's value present in the conf.js file, so that I can read them in specs.js file to take necessary actions based on the parameter;'s value passed in the conf.js. Is there a way in which this can be possible.

回答1:

Yes, you can access all the config values using browser.getProcessedConfig.Check here for more details

An example below

describe('test', function(){
    it('test', function(){
        browser.get('http://www.way2automation.com/angularjs-protractor/registeration/#/login');
        browser.getProcessedConfig().then(function(config){
            console.log(config.baseUrl) // Print Url
            console.log(config.specs) // Prints specs
            console.log(config.capabilities) // Prints capabilities
        })
        browser.sleep(10000)
    });
});

In case you are looking to make it re-usable

 this.getConfParameterValue = function() {
     return browser.getProcessedConfig().then(function(config) {
           return config.directConnect;
     }) 
 }