获取量角器multicapabilities配置中的当前名称?

时间:2015-01-27 21:15:55

标签: angularjs protractor

我使用browser.getCapabilities()来获取browserName和平台详细信息。

Multicapabilities配置:



    multiCapabilities:[
    {
    browserName: 'chrome',
    name: 'iPhone',
    chromeOptions: {
            args: ['--window-size=400,800','--user-agent="Mozilla/5.0 (iPad; CPU iPhone OS 7_0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A4449d Safari/9537.53"']
        }
    }
    ]

" browser.getCapabilities()"返回以下内容,



    { caps_: 
       { platform: 'MAC',
         acceptSslCerts: true,
         javascriptEnabled: true,
         browserName: 'chrome',
         chrome: { userDataDir: '/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/.org.chromium.Chromium.ten2tT' },
         rotatable: false,
         locationContextEnabled: true,
         mobileEmulationEnabled: false,
         'webdriver.remote.sessionid': '1a7542e9-8a70-469c-964d-3c3cd4330145',
         version: '40.0.2214.93',
         takesHeapSnapshot: true,
         cssSelectorsEnabled: true,
         databaseEnabled: false,
         handlesAlerts: true,
         browserConnectionEnabled: false,
         nativeEvents: true,
         webStorageEnabled: true,
         applicationCacheEnabled: false,
         takesScreenshot: true } }

有没有办法从功能对象中获取名称?

2 个答案:

答案 0 :(得分:0)

如果在conf.js页面中设置了多个浏览器,则以下内容应返回运行测试的浏览器名称:

browser.browserName

在测试的beforeEach函数中,我添加了console.log(browser.browserName);,并为每个测试导出了正确的浏览器名称。

[launcher] Running 3 instances of WebDriver

------------------------------------
[safari #2] PID: 36412
[safari #2] Using the selenium server at http://localhost:4444/wd/hub
[safari #2] safari
[safari #2] 
[safari #2]   Test - pass
[safari #2] 
[safari #2] 
[safari #2] Finished in 1.469 seconds
[safari #2] 1 test, 0 assertions, 0 failures
[safari #2] 

[launcher] 2 instance(s) of WebDriver still running

------------------------------------
[firefox #3] PID: 36413
[firefox #3] Using the selenium server at http://localhost:4444/wd/hub
[firefox #3] firefox
[firefox #3] 
[firefox #3]   Test - pass
[firefox #3] 
[firefox #3] 
[firefox #3] Finished in 1.464 seconds
[firefox #3] 1 test, 0 assertions, 0 failures
[firefox #3] 

[launcher] 1 instance(s) of WebDriver still running

------------------------------------
[chrome #1] PID: 36411
[chrome #1] Using the selenium server at http://localhost:4444/wd/hub
[chrome #1] chrome
[chrome #1] 
[chrome #1]   Test - pass
[chrome #1] 
[chrome #1] 
[chrome #1] Finished in 2.173 seconds
[chrome #1] 1 test, 0 assertions, 0 failures
[chrome #1] 

[launcher] 0 instance(s) of WebDriver still running
[launcher] safari #2 passed
[launcher] firefox #3 passed
[launcher] chrome #1 passed

Process finished with exit code 0

答案 1 :(得分:0)

您可以在onPrepare方法中添加其他信息,例如:

browser.getCapabilities()
  .then( cap => browser.name = cap.caps_.browserName )

其中browserNamemultiCapabilities对象的属性:

chrome: {
  browserName: 'chrome',
  logName: 'Chrome'
},
firefox: {
  browserName: 'firefox',
  logName: 'Firefox'
}

在测试中,您可以使用browser.name检索当前浏览器的名称。

更新2017-01-07:

对于Protractor 4,您不再需要使用内部caps_属性,因为这些值将直接在getCapabilities()结果中公开。