【问题标题】:Protractor multiCapabilities with the same browser量角器 multiCapabilities 同一个浏览器
【发布时间】:2016-04-01 10:07:50
【问题描述】:

我正在使用“multiCapabilities”运行量角器,如下所示:

multiCapabilities : [
{  
  name : 'ChromeIphone',
  logName : 'Chrome Iphone',
  browserName: 'chrome',
  chromeOptions: {
    'args': ['user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4']
  },
  mobileEmulationEnabled: true
},
{
  name : 'ChromeAndroid',
  logName : 'Chrome Android',
  platformName: 'android',
  browserName: 'chrome',
  newCommandTimeout: 60,
  chromeOptions: {
    'args': ['user-agent=Mozilla/5.0 (Linux; Android 4.4.4; Samsung Galaxy S4 - 4.4.4 - API 19 - 1080x1920 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36']
  }
}
],

这会导致启动两个 Web 驱动程序实例。当其中一个失败时,我想知道我创建的报告中哪个失败了。

我尝试在“onPrepare”中使用以下函数。

browser.getCapabilities().then(function (cap) {
  browser.name = (cap.browserName === undefined) ? (cap.caps_) ? cap.caps_.browserName : 'chrome' : cap.browserName;
  console.log('Current browser: ' + browser.name);
});

在我的情况下这有点没用,因为我一直使用“chrome”作为浏览器。

有什么方法可以让我在运行时知道正在使用的用户代理?或者也许有可能知道我的“multiCapabilities”中的哪一项失败了?

【问题讨论】:

  • 使用 getCapabilities 可以在运行时检索浏览器名称。您使用的是哪种报告?在 html-screenshot-reporter 中,它清楚地说明了失败的位置。
  • 我知道浏览器名称...但是,我们总是使用“chrome”作为浏览器,使用不同的用户代理来模拟 android、iphone 等。在创建的报告的标题中,我想“ Android' 或 'Iphone' 可见。我使用的记者是'protractor-jasmine2-screenshot-reporter'
  • 哦,好吧,我不认为它们是直接允许的,因为它们只捕获浏览器的主体。我猜您需要自定义报告。如果您找到解决方案,请告诉我。

标签: google-chrome jasmine protractor karma-runner


【解决方案1】:

您可以从已处理的配置文件中获取值:

onPrepare: function() {
    browser.getProcessedConfig().then(function(currentConfig) {
        console.log('Current browser: ' + currentConfig.capabilities.name);

        // if you want to see all the properties, you can use this
        // console.log(JSON.stringify(currentConfig.capabilities, null, 4));
    });
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多