English 中文(简体)
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/

问题回答

There s also PNUnit, worth taking a look at, I haven t tried it yet for parallel testing.

NCrunch (http://www.ncrunch.net/) is worth looking at - it has the option of distributed processing as part of a build and one of it s main features is parallel testing.

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);
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签