使用Nunit在C#并行执行中的Selenium Grid [英] Selenium Grid in C# Parallel execution with Nunit

查看:127
本文介绍了使用Nunit在C#并行执行中的Selenium Grid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了硒网格2的设置.集线器和节点已启动并正在运行.我正在使用Selenium Webdriver + C#+ Nunit来运行测试,我现在想执行以下操作:

i just made the setup for selenium grid 2. The hub and the nodes are up and running. I'm using Selenium webdriver + C# + Nunit to run my tests, i want now to do the following:

1) 在不同节点之间分配测试用例(并行性),例如运行测试x的节点1和运行测试y的节点2

2) 我需要能够为每个节点配置浏览器和平台类型,我现在要做的就是创建一个设置功能并使用所有节点使用相同的平台和浏览器,因此如何通过分配每个节点所需的功能来实现这一目标.

问题是当我运行即将到来的代码时,我发现测试同时运行而不是并行运行.

我的代码快照:

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using NUnit;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace GridTest
{
    [TestFixture]
    [Parallelizable]
    public class Test_Grid
    {
        IWebDriver driver;

        [SetUp]
        public void Setup()
        {

            /////IE Setup/////////
            var capabilities = new DesiredCapabilities("internet explorer", string.Empty, new Platform(PlatformType.Any));
            capabilities.SetCapability("ignoreProtectedModeSettings", true);

            driver = new RemoteWebDriver(new Uri("http://localhost:4445/wd/hub"),capabilities);

         }

        //Search google test 
        [Test]
        [Parallelizable]
        public void GoogleSearch()
        {
            string homepage = "http://www.google.com";
            //Navigate to the site
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            driver.Navigate().GoToUrl(homepage);

        }

        [Test]
        [Parallelizable]
        public void BingSearch()
        {
            //var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bing.com");

        }


      [TearDown]
       public void Teardown()
        {

           driver.Quit();
        }
    }
}

推荐答案

简单易用...但是您不喜欢这个答案. :-(

Easy one... but you won't like the answer. :-(

NUnit尚不支持在夹具中并行运行测试方法.它只能并行运行单个灯具.

NUnit does not yet support running the test methods in a fixture in parallel. It only runs individual fixtures in parallel.

因此,您需要使用OneTimeSetUp选择正确的浏览器来对要在灯具级别并行运行的事物进行建模.

So you need to model those things you want run in parallel at the fixture level, using OneTimeSetUp to select the correct browser.

更新-2019年9月27日

UPDATE - 27 Sep 2019

我是在三年前写出上述答案的,那是真的!人们,请仔细阅读这些问题和答案的日期,因为除非删除,否则他们将永远留在这里.

I wrote the above answer over three years ago, when it was true! People, pleaseread the dates on these questions and answers, since they stay here forever unless removed.

发布答案几个月后,NUnit增加了并行运行各个测试用例(方法)的功能.有关受支持功能的最新信息的最佳来源是NUnit文档,而不是SO!大多数工具都是如此.

A few months after the answer was posted, NUnit added the ability to run individual test cases (methods) in parallel. Best source of current info about supported features is the NUnit docs, not SO! That's true for most tools.

这篇关于使用Nunit在C#并行执行中的Selenium Grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆