WebDriver套件的顺序执行-C#//Selenium Grid-所有本地 [英] Sequential execution of WebDriver suite - C# // Selenium Grid - All Local

查看:186
本文介绍了WebDriver套件的顺序执行-C#//Selenium Grid-所有本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在试图找到一个很好的解决方案,但是还没有找到一个强有力的解决方案.我已经使用WebDriver和C#创建了一个测试套件,以便在我们的站点上运行我们的测试套件.我唯一剩下的问题是我想找到一种在FireFox,Chrome然后是IE中执行完整套件的方法.因此,基本上,我需要先在FireFox中完成测试,然后在Chrome中完成测试,然后依次在IE中完成测试.

I have been trying to find a good solution to this problem for a while now and have yet to come up with a strong solution. I have created a test suite using WebDriver and C# to run our test suites against our sites. My only remaining issue is I want to find a way to have the full suite execute in FireFox, Chrome then IE. So basically, I need the test to complete in FireFox, then complete in Chrome and finally complete in IE in order.

我已经对Selenium Grid进行了研究,目前正在努力使其启动并运行,但是由于没有可用的虚拟机,因此面临各种类型的问题,我需要在本地运行它.因此,如果无法解决这个问题,或者不是一个好的解决方案,那么有人可以指导我如何设置Selenium网格,使其在本地的这3种主要浏览器中运行吗?我找到的所有文档都需要虚拟机设置.

I have researched into Selenium Grid and am currently tackling getting that up and running but am facing all types of issues since we do not have any virtual machines to use, I would need to run it on my local. So if the part of this question is not possible, or not a good solution, would someone be able to direct me to how to setup Selenium grid to run in those 3 main browsers on my local? All documentation I have found requires virtual machine setups.

推荐答案

我刚刚使用了NUnit的参数化测试.

I have just used NUnit's parameterised test's.

我创建了一个枚举:

/// <summary>
/// Enum that holds references to different browsers used in testing.
/// </summary>
public enum BrowserTypeEnum
{
    /// <summary>
    /// Google Chrome.
    /// </summary>
    Chrome, 

    /// <summary>
    /// Mozilla Firefox.
    /// </summary>
    Firefox, 

    /// <summary>
    /// Internet Explorer.
    /// </summary>
    InternetExplorer
}

像这样在TestFixture中调用它:

Called it in the TestFixture like so:

/// <summary>
/// Tests related to browsing Google
/// </summary>
[TestFixture(BrowserTypeEnum.Chrome)]
[TestFixture(BrowserTypeEnum.Firefox)]
public class GoogleTests : AbstractTestFixture
{
}

在AbstractTestFixture中:

In AbstractTestFixture:

    /// <summary>
    /// Create's the browser used for this test fixture. 
    /// <para>
    /// Must always be called as part of the test fixture set up, not the base test fixtures.
    /// </para>
    /// <para>
    /// It is the actual test fixture's responsibility to launch the browser.
    /// </para>
    /// </summary>
    protected override void CreateBrowser()
    {
        switch (BrowserType)
        {
            case BrowserTypeEnum.Chrome:
                Browser = new ChromeDriver();
                break;
            case BrowserTypeEnum.Firefox:
                Browser = new FirefoxDriver();
                break;
            case BrowserTypeEnum.InternetExplorer:
                Browser = new IEDriver();
                break;
            default:
                break;
        }
    }

可能不是最佳解决方案,但我发现它可读性强.替代方法是使用Selenium Grid之类的方法,或者将驱动程序的类型传递给NUnit并直接创建它,如下所示:

May not be the best solution, but I found it pretty readable. The alternative is using something like Selenium Grid, or maybe passing the type of driver into NUnit and create it directly, like so:

/// <summary>
/// Tests related to browsing Google
/// </summary>
[TestFixture(typeof(FirefoxDriver))]
public class GoogleTests : AbstractTestFixture
{
}

另一种替代方法是,如果您使用CI Server解决方案,请创建配置设置以指示要使用哪个浏览器进行测试.让CI驱动程序重复测试3次,每次都编辑该配置设置.

Another alternative is if you use a CI Server solution, create a configuration setting to indicate which browser to use for the test. Have the CI Driver repeat the tests three times, editing that configuration setting each time.

这篇关于WebDriver套件的顺序执行-C#//Selenium Grid-所有本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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