简体   繁体   中英

Selenium Grid with parallel testing using C#/NUnit

I've got several unit tests written with NUnit that are calling selenium commands. I've got 2 win2k3 server boxes setup, one is running selenium grid hub along with 2 selenium rc's. The other box is running 5 selenium rc's. All of them are registered with the hub as running Firefox on Windows (to keep it simple). In my unit test setup method I've got it connected to the hub's hostname at port 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. I've seen lots of pointers to using PNUnit in the meantime. However this seems to completely defeat the purpose of the Selenium Grid.

Have any of you successfully implemented parallel testing using C#/NUnit connected to a Selenium Grid setup? 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)

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.

I using Gallio runner for my tests on c# and have examples here:

project on c# with tests runned in parallel: 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

Gallio test runner: 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.

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.

Since 3.7 version NUnit allows running test in parallel. Before that, it was possible to do that on a fixture level but in 3.7+ you can even for tests in one 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM