[英]Selenium Grid with parallel testing using C#/NUnit
I've got several unit tests written with NUnit that are calling selenium commands. 我用NUnit编写了几个调用selenium命令的单元测试。 I've got 2 win2k3 server boxes setup, one is running selenium grid hub along with 2 selenium rc's. 我有2个win2k3服务器盒设置,一个运行selenium网格集线器和2个selenium rc。 The other box is running 5 selenium rc's. 另一个盒子正在运行5个selenium rc。 All of them are registered with the hub as running Firefox on Windows (to keep it simple). 所有这些都在集线器中注册为在Windows上运行Firefox(为了保持简单)。 In my unit test setup method I've got it connected to the hub's hostname at port 4444. 在我的单元测试设置方法中,我已经将它连接到端口4444处的集线器主机名。
When running the tests, they only run sequentially (as expected). 运行测试时,它们只按顺序运行(按预期方式)。 I've done a lot of reading on NUnit's roadmap and how they are shooting for parallel testing abilities. 我已经完成了很多关于NUnit路线图的阅读以及他们如何为并行测试能力拍摄。 I've seen lots of pointers to using PNUnit in the meantime. 我已经看到很多指针在此期间使用PNUnit。 However this seems to completely defeat the purpose of the Selenium Grid. 然而,这似乎完全打败了Selenium Grid的目的。
Have any of you successfully implemented parallel testing using C#/NUnit connected to a Selenium Grid setup? 有没有人使用连接到Selenium Grid设置的C#/ NUnit成功实现了并行测试? If so, please elaborate. 如果是这样,请详细说明。
I'm at a complete loss at how this will/can work using NUnit as it exists now (I'm using version 2.9.3) 我现在完全不知道如何使用NUnit,因为它现在存在(我使用的是版本2.9.3)
Unfortunately NUnit can not run tests in parallel, so you have to use another runner to archive all advantages of parallel testing with Selenium Grid. 不幸的是,NUnit不能并行运行测试,所以你必须使用另一个运行器来存档Selenium Grid的并行测试的所有优点。
I using Gallio runner for my tests on c# and have examples here: 我使用Gallio runner来测试c#并在这里举例说明:
project on c# with tests runned in parallel: http://code.google.com/p/design-of-selenium-tests-for-asp-net/ 同时运行测试的c#项目: http : //code.google.com/p/design-of-selenium-tests-for-asp-net/
description: http://slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html 说明: http : //slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html
Gallio test runner: http://www.gallio.org/ Gallio测试运行者: http ://www.gallio.org/
NCrunch( http://www.ncrunch.net/ )值得关注 - 它可以选择分布式处理作为构建的一部分,其中一个主要功能是并行测试。
还有PNUnit ,值得一看,我还没有尝试过并行测试。
By using Selenium Grid in combination with .NET's task Parallel library and the DynamicObject class you can run the same test on multiple Selenium Grid Nodes (multiple browsers) at the same time. 通过将Selenium Grid与.NET的任务并行库和DynamicObject类结合使用,您可以同时在多个Selenium Grid节点(多个浏览器)上运行相同的测试。
http://blog.dmbcllc.com/running-selenium-in-parallel-with-any-net-unit-testing-tool/ http://blog.dmbcllc.com/running-selenium-in-parallel-with-any-net-unit-testing-tool/
Gallio is outdated today so you could stick to NUnit solution. Gallio今天已经过时了,所以你可以坚持使用NUnit解决方案。
Since 3.7 version NUnit allows running test in parallel. 从3.7版本开始,NUnit允许并行运行测试。 Before that, it was possible to do that on a fixture level but in 3.7+ you can even for tests in one TestFixute. 在此之前,可以在夹具级别上执行此操作,但在3.7+中,您甚至可以在一个TestFixute中进行测试。 See my example below to demonstrate how it could be achieved. 请参阅下面的示例,以演示如何实现它。
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace ConsoleApp1
{
[TestFixture]
public class Dummy
{
static TestCaseData Case(int i)
=> new TestCaseData(TimeSpan.FromSeconds(2)).SetName($"Case {i}");
public static IEnumerable<TestCaseData> Cases()
=> Enumerable.Range(1, 5).Select(Case);
[TestCaseSource(nameof(Cases)), Parallelizable(ParallelScope.Children)]
public void ItShouldSleep(TimeSpan t)
=> Thread.Sleep(t);
static TestCaseData Case2(int i)
=> new TestCaseData(TimeSpan.FromSeconds(2)).SetName($"Case2 {i}");
public static IEnumerable<TestCaseData> Cases2()
=> Enumerable.Range(1, 5).Select(Case2);
[TestCaseSource(nameof(Cases2)), Parallelizable(ParallelScope.Children)]
public void ItShouldSleep2(TimeSpan t)
=> Thread.Sleep(t);
}
[TestFixture()]
public class Dummy2
{
static TestCaseData Case(int i)
=> new TestCaseData(TimeSpan.FromSeconds(2)).SetName($"Case {i}");
public static IEnumerable<TestCaseData> Cases()
=> Enumerable.Range(1, 5).Select(Case);
[TestCaseSource(nameof(Cases)), Parallelizable(ParallelScope.Children)]
public void ItShouldSleep(TimeSpan t)
=> Thread.Sleep(t);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.