How to read parameter's value, present in conf.js file of protractor in specs

不羁岁月 提交于 2019-12-20 04:33:09

问题


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;
     }) 
 }


来源:https://stackoverflow.com/questions/42414538/how-to-read-parameters-value-present-in-conf-js-file-of-protractor-in-specs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!