如何在量角器中按顺序运行多浏览器测试

How to run multi browser tests sequentially in Protractor?

本文关键字:运行 浏览器 测试 顺序 量角器      更新时间:2023-09-26

例如,我有5个tc,需要在Firefox和Chrome上运行所有5个测试用例。因此,一旦Chrome完成了5个tc的执行,我需要Firefox浏览器启动并依次执行相同的任务。

当我使用multiCapabilities时,它会同时启动Firefox和Chrome。

您可以在量角器配置中使用maxSessions变量conf.js

  // Maximum number of total browser sessions to run. Tests are queued in
  // sequence if number of browser sessions is limited by this parameter.
  // Use a number less than 1 to denote unlimited. Default is unlimited.
  maxSessions: -1

更多信息https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L198

示例conf.js (firefox, safari, chrome, chrome设备模拟器):

multiCapabilities: [
    {
        browserName: 'firefox'
    },
     {
     browserName: 'safari'
     },
    {
        browserName: 'chrome'
    },
    {
        browserName: 'chrome',
        // List of devices https://cs.chromium.org/chromium/src/chrome/test/chromedriver/chrome/mobile_device_list.cc
        'deviceName': 'Google Nexus 5'
    },
    {
        browserName: 'chrome',
        'deviceName': 'Apple iPhone 6'
    },
    {
        browserName: 'chrome',
        'deviceName': 'Apple iPad'
    },
    {
        browserName: 'chrome',
        'deviceName': 'Samsung Galaxy S4'
    }
],
maxSessions: 1

更多的例子和测试在实际设备https://github.com/aluzardo/protractor-cucumber-tests

这已经在量度器版本5.4.2中进行了测试并正常工作,并且根据Adolfo的答案,我添加了maxSessions: 1,因此它以顺序模式运行。换句话说,firefox规范首先被执行,然后才是chrome。

exports.config = {
  framework: 'jasmine',
  directConnect: false,

  multiCapabilities: [{
      browserName: 'firefox',
      'moz:firefoxOptions': {
            args: ['--verbose'],
            binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'
       //Need to start cmd via admin mode to avoid permission error
        },
      specs: ['src/com/sam/scriptjs/draganddrop.spec.js']
    }, 
    {
        browserName : 'chrome',
        chromeOptions: {
            args: [ "--start-maximized" ]
                     },
        specs: ['src/com/sam/scriptjs/iframes.spec.js']
    }],
    maxSessions: 1,//To run in sequential mode so first Firefox then chrome 
    //without max session it will open two windows at the same time for both browsers
     seleniumAddress: 'http://localhost:4444/wd/hub'
}