簡體   English   中英

Selenium Grid使用C#/ NUnit進行並行測試

[英]Selenium Grid with parallel testing using C#/NUnit

我用NUnit編寫了幾個調用selenium命令的單元測試。 我有2個win2k3服務器盒設置,一個運行selenium網格集線器和2個selenium rc。 另一個盒子正在運行5個selenium rc。 所有這些都在集線器中注冊為在Windows上運行Firefox(為了保持簡單)。 在我的單元測試設置方法中,我已經將它連接到端口4444處的集線器主機名。

運行測試時,它們只按順序運行(按預期方式)。 我已經完成了很多關於NUnit路線圖的閱讀以及他們如何為並行測試能力拍攝。 我已經看到很多指針在此期間使用PNUnit。 然而,這似乎完全打敗了Selenium Grid的目的。

有沒有人使用連接到Selenium Grid設置的C#/ NUnit成功實現了並行測試? 如果是這樣,請詳細說明。

我現在完全不知道如何使用NUnit,因為它現在存在(我使用的是版本2.9.3)

不幸的是,NUnit不能並行運行測試,所以你必須使用另一個運行器來存檔Selenium Grid的並行測試的所有優點。

我使用Gallio runner來測試c#並在這里舉例說明:

同時運行測試的c#項目: http//code.google.com/p/design-of-selenium-tests-for-asp-net/

說明: http//slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html

Gallio測試運行者: http ://www.gallio.org/

NCrunch( http://www.ncrunch.net/ )值得關注 - 它可以選擇分布式處理作為構建的一部分,其中一個主要功能是並行測試。

還有PNUnit ,值得一看,我還沒有嘗試過並行測試。

通過將Selenium Grid與.NET的任務並行庫和DynamicObject類結合使用,您可以同時在多個Selenium Grid節點(多個瀏覽器)上運行相同的測試。

http://blog.dmbcllc.com/running-selenium-in-parallel-with-any-net-unit-testing-tool/

Gallio今天已經過時了,所以你可以堅持使用NUnit解決方案。

從3.7版本開始,NUnit允許並行運行測試。 在此之前,可以在夾具級別上執行此操作,但在3.7+中,您甚至可以在一個TestFixute中進行測試。 請參閱下面的示例,以演示如何實現它。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM