量角器——在不同的浏览器上并行运行多个测试

时间:2022-10-26 21:34:59

I can't find any information on how to set this up, but it seems like a pretty basic concept, so I'm sure there's an answer out there.

我找不到任何关于如何设置这个的信息,但是它看起来是一个很基本的概念,所以我确定有一个答案。

I know how to run protractor on different browsers by setting the browserName property of the capabilities object in the config. And that's working great. I can set it to 'chrome' or 'firefox' or whatever I need and it runs just as expected. But the only way to run a single test suite against multiple browsers (as far as I know) is to create separate config files, each with a different browserName and then run each browser with its own config. This works, but its really slow because tests are then running in sequence, rather than concurrently.

通过在配置中设置capability对象的browserName属性,我知道如何在不同的浏览器上运行量角器。这是伟大的工作。我可以将它设置为“chrome”或“firefox”或我需要的任何东西,它就会按预期运行。但是,针对多个浏览器(据我所知)运行单个测试套件的唯一方法是创建单独的配置文件,每个文件都有不同的浏览器名,然后使用自己的配置运行每个浏览器。这是可行的,但是非常慢,因为测试是按顺序运行的,而不是并发运行。

Is there any way to run it on multiple browsers in parallel?

有没有办法在多个浏览器上并行运行它?

Can it be done on SauceLabs? or even using a local Selenium-Grid?

能在煎锅上完成吗?或者甚至使用本地硒网格?

We are just trying to streamline our testing process and this would be a huge help. Any suggestions or info would be greatly appreciated. Thanks in advance.

我们只是在努力简化我们的测试过程,这将是一个巨大的帮助。如有任何建议或信息,我们将不胜感激。提前谢谢。

6 个解决方案

#1


20  

Update Feb 2014 - This answer is no longer valid. Use Paolo Moretti's answer below.

更新2014年2月-这个答案不再有效。使用Paolo Moretti的回答。


There may be a better way to do this but currently I am just executing these as concurrent Grunt tasks.

可能有更好的方法来实现这一点,但是目前我只是将它们作为并发的繁重任务执行。

1) Add the grunt concurrent plugin

1)添加并发插件

npm install grunt-concurrent --save-dev

2) Add a task for each browser under grunt.initConfig. We can add the browser as an arg to re-use our configuration file.

2)在grun. initconfig下为每个浏览器添加一个任务。我们可以添加浏览器作为arg来重用配置文件。

protractor: {
        options: {
            keepAlive: true,
            singleRun: false,
            configFile: "test/protractor.conf.js"
        },
        run_chrome: {
            options: {
                args: {
                    browser: "chrome"
                }
            }
        },
        run_firefox: {
            options: {
                args: {
                    browser: "firefox"
                }
            }
        }
    },

3) Register these as tasks;

3)登记为任务;

grunt.registerTask('protractor-chrome', ['protractor:run_chrome']);
grunt.registerTask('protractor-firefox', ['protractor:run_firefox']);

4) Create your concurrent task under grunt.initConfig

4)在grun. initconfig下创建并发任务

concurrent: {
        protractor_test: ['protractor-chrome', 'protractor-firefox']
    },

5) Add the grunt task for concurrent

5)添加并发的grunt任务。

grunt.registerTask('protractor-e2e', ['concurrent:protractor_test']);

And executing that should give you concurrent protractor tests.

执行它会给你同时的量角器测试。

#2


57  

There's new option called multiCapabilities for that:

有一个新选项叫做多配性:

multiCapabilities: [{
  'browserName': 'chrome'
}, {
  'browserName': 'firefox'
}],

Here's a complete example.

这是一个完整的示例。

#3


13  

using multiCapabilities will run all the tests in each of the browsers. So the configuration below will run every test twice, once in Firefox and once in Chrome:

使用多选项将在每个浏览器中运行所有的测试。因此,下面的配置将在每个测试中运行两次,一次在Firefox中,一次在Chrome中:

multiCapabilities: [{
  'browserName': 'chrome'
}, {
  'browserName': 'firefox'
}],

If you would rather have each test file just run once, but split up among multiple browsers, then use the splitTestsBetweenCapabilities option:

如果您希望让每个测试文件只运行一次,但是在多个浏览器中进行拆分,那么使用splittestsbetweenability选项:

splitTestsBetweenCapabilities: true

This blog post goes into further detail about the splitTestsBetweenCapabilities

这篇博文更详细地介绍了“中间人”的能力

#4


1  

I had the same problem and I've found that they are adding the feature for parallel execution as we speak! :D

我也遇到了同样的问题,我发现他们正在添加并行执行功能!:D

Take a look at this: https://github.com/angular/protractor/pull/492

看看这个:https://github.com/angular/protractor/pull/492

That change was merged to master, but a newer one (512) is still open. As soon as they merge it to master (should be today or tomorrow according to the discussion in the pull request) it should be in your hands :D.

这个变化被合并到主,但是一个新的(512)仍然是打开的。一旦他们将它合并到master(应该是今天或明天根据拉请求中的讨论),它应该在你的手中:D。

#5


1  

BrowserStack also can be used for this purposes. It has quite detailed start guide: https://www.browserstack.com/automate/node, but it is not free

BrowserStack也可以用于这个目的。它有非常详细的开始指南:https://www.browserstack.com/automate/node,但是它不是免费的

#6


1  

This is how I achieve this. Simply add the section below to the conf.js file:

我就是这样做到的。只需将下面的部分添加到conf.js文件中:

capabilities: {
  browserName: 'chrome',
  shardTestFiles: true,
  maxInstances: 1
}

shardTestFiles = true causes each spec file to run in a new browser instance. maxInstances is the max number of browsers that can be open at the same time.

shardTestFiles = true会使每个spec文件在一个新的浏览器实例中运行。maxinstance是同时打开的最大数量的浏览器。

#1


20  

Update Feb 2014 - This answer is no longer valid. Use Paolo Moretti's answer below.

更新2014年2月-这个答案不再有效。使用Paolo Moretti的回答。


There may be a better way to do this but currently I am just executing these as concurrent Grunt tasks.

可能有更好的方法来实现这一点,但是目前我只是将它们作为并发的繁重任务执行。

1) Add the grunt concurrent plugin

1)添加并发插件

npm install grunt-concurrent --save-dev

2) Add a task for each browser under grunt.initConfig. We can add the browser as an arg to re-use our configuration file.

2)在grun. initconfig下为每个浏览器添加一个任务。我们可以添加浏览器作为arg来重用配置文件。

protractor: {
        options: {
            keepAlive: true,
            singleRun: false,
            configFile: "test/protractor.conf.js"
        },
        run_chrome: {
            options: {
                args: {
                    browser: "chrome"
                }
            }
        },
        run_firefox: {
            options: {
                args: {
                    browser: "firefox"
                }
            }
        }
    },

3) Register these as tasks;

3)登记为任务;

grunt.registerTask('protractor-chrome', ['protractor:run_chrome']);
grunt.registerTask('protractor-firefox', ['protractor:run_firefox']);

4) Create your concurrent task under grunt.initConfig

4)在grun. initconfig下创建并发任务

concurrent: {
        protractor_test: ['protractor-chrome', 'protractor-firefox']
    },

5) Add the grunt task for concurrent

5)添加并发的grunt任务。

grunt.registerTask('protractor-e2e', ['concurrent:protractor_test']);

And executing that should give you concurrent protractor tests.

执行它会给你同时的量角器测试。

#2


57  

There's new option called multiCapabilities for that:

有一个新选项叫做多配性:

multiCapabilities: [{
  'browserName': 'chrome'
}, {
  'browserName': 'firefox'
}],

Here's a complete example.

这是一个完整的示例。

#3


13  

using multiCapabilities will run all the tests in each of the browsers. So the configuration below will run every test twice, once in Firefox and once in Chrome:

使用多选项将在每个浏览器中运行所有的测试。因此,下面的配置将在每个测试中运行两次,一次在Firefox中,一次在Chrome中:

multiCapabilities: [{
  'browserName': 'chrome'
}, {
  'browserName': 'firefox'
}],

If you would rather have each test file just run once, but split up among multiple browsers, then use the splitTestsBetweenCapabilities option:

如果您希望让每个测试文件只运行一次,但是在多个浏览器中进行拆分,那么使用splittestsbetweenability选项:

splitTestsBetweenCapabilities: true

This blog post goes into further detail about the splitTestsBetweenCapabilities

这篇博文更详细地介绍了“中间人”的能力

#4


1  

I had the same problem and I've found that they are adding the feature for parallel execution as we speak! :D

我也遇到了同样的问题,我发现他们正在添加并行执行功能!:D

Take a look at this: https://github.com/angular/protractor/pull/492

看看这个:https://github.com/angular/protractor/pull/492

That change was merged to master, but a newer one (512) is still open. As soon as they merge it to master (should be today or tomorrow according to the discussion in the pull request) it should be in your hands :D.

这个变化被合并到主,但是一个新的(512)仍然是打开的。一旦他们将它合并到master(应该是今天或明天根据拉请求中的讨论),它应该在你的手中:D。

#5


1  

BrowserStack also can be used for this purposes. It has quite detailed start guide: https://www.browserstack.com/automate/node, but it is not free

BrowserStack也可以用于这个目的。它有非常详细的开始指南:https://www.browserstack.com/automate/node,但是它不是免费的

#6


1  

This is how I achieve this. Simply add the section below to the conf.js file:

我就是这样做到的。只需将下面的部分添加到conf.js文件中:

capabilities: {
  browserName: 'chrome',
  shardTestFiles: true,
  maxInstances: 1
}

shardTestFiles = true causes each spec file to run in a new browser instance. maxInstances is the max number of browsers that can be open at the same time.

shardTestFiles = true会使每个spec文件在一个新的浏览器实例中运行。maxinstance是同时打开的最大数量的浏览器。