Selenium Grid with parallel testing using C#/NUnit

回眸只為那壹抹淺笑 提交于 2019-12-04 10:04:24

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);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!