如何在Protractor中按顺序运行多个浏览器测试?

时间:2016-09-16 00:30:39

标签: javascript protractor

例如,我有5个TC,需要在Firefox和Chrome上运行所有5个测试用例。因此,一旦Chrome完成执行5个TC,我需要Firefox浏览器启动并按顺序执行相同的工作。

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

2 个答案:

答案 0 :(得分:2)

您可以使用maxSessions var内部量角器配置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

答案 1 :(得分:1)

这已在量角器5.4.2版中进行了测试,并且工作正常,并且按照 Adolfo's 的答案,我添加了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'

}