[Protractor] Running tests on multiple browsers

本文介绍如何使用Protractor进行多浏览器测试,并提供快速开发时仅针对单一浏览器运行测试的方法。通过配置文件灵活选择测试浏览器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Testing your AngularJS application on multiple browsers is important, and Protractor offers this ability through the multiCapabilities configuration option. Learn how to use this option, as well as configure your e2e tests to run on only a single browser for rapid development.

 

By default, protractor will use chrome as default browser. You can also use other browser:

exports.config = {

    capabilities: {
        name: "Firefox",
        browserName: "firefox"
    },
    specs: [
        './e2etest/**/*.spec.js'
    ],
    seleniumAddress: 'http://localhost:4444/wd/hub'
};

 

If you want to run on multi browsers, then you can use 'multiCapabilities':

exports.config = {
    multiCapabilities: [
        {
            name: "Chrome",
            browserName: "chrome"
        },
        {
            name: "Firefox",
            browserName: "firefox"
        }
    ],
    specs: [
        './e2etest/**/*.spec.js'
    ],
    seleniumAddress: 'http://localhost:4444/wd/hub'
};

 

But it probably good when you are actually developing the project, you can run only on one browser for saving time, so you can modify the scripts tags:

    "test-e2e": "protractor conf.js",
    "test-e2e-dev": "protractor conf.js --chrome"

 

More flexable code:

var browsers = {
  firefox: {
    name: 'Firefox',
    browserName: 'firefox'
  },
  chrome: {
    name: 'Chrome',
    browserName: 'chrome'
  }
}

var config = {
  specs: [
    './e2etest/**/*.spec.js'
  ],

  baseUrl: 'http://localhost:3333'
};

if (process.argv[3] === '--chrome') {
  config.capabilities = browsers.chrome;
}  else {
  config.multiCapabilities = [
    browsers.firefox,
    browsers.chrome
  ]
}

exports.config = config;

 

 

package.json:

  "scripts": {
    "test-start": "webdriver-manager start",
    "test-e2e": "protractor conf.js",
    "test-e2e-dev": "protractor conf.js --chrome"
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值