[Protractor] Running tests on multiple browsers

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"
  },
posted @   Zhentiw  阅读(306)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示