2017-02-23 14 views
1

例:conf.js如何讀取參數的值,存在於規範量角器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中傳遞的值進行必要的操作。有沒有辦法可以做到這一點。

+0

你想讀什麼價值? ..你的conf.js不包含任何定義的值 – AdityaReddy

+0

我想讀取參數的值,例如seleniumAddress的值,它是http:// localhost:4444/wd/hub –

+0

是的,明白了....請檢查下面的ans – AdityaReddy

回答

1

是的,你可以使用browser.getProcessedConfig。檢查here更多細節

下面

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

如果一個例子,你正在尋找,使其可重複使用的

this.getConfParameterValue = function() { 
    return browser.getProcessedConfig().then(function(config) { 
      return config.directConnect; 
    }) 
} 
訪問所有的配置值
+0

FunctionLibrary.js this.getConfParameterValue =函數(){ browser.getProcessedConfig(),然後(函數(配置){ 回報config.directConnect; //如果我打印那麼它的罰款,但我不能回有沒有什麼辦法可以從這裏返回東西 } } –

+0

我已經用你正在尋找的東西解決了答案...你的方法定義正確..你只需要返回值 – AdityaReddy

+0

嗨,在調用getConfParameterV alue函數,它返回一個promise。我想返回config參數的值 –

相關問題