本文介绍了如何读取参数的值,在specs中的量角器的conf.js文件中出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ex:conf.js

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',

}

规格:

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

我需要读取conf.js文件中存在的参数值,以便我可以读取它们在specs.js文件中根据参数采取必要的操作;在conf.js中传递的值。有没有办法可以做到这一点。

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.

推荐答案

是的,您可以使用<$ c $访问所有配置值c> browser.getProcessedConfig 。查看了解更多详情

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

以下示例

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

这篇关于如何读取参数的值,在specs中的量角器的conf.js文件中出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:45