0

一段时间以来,我一直在努力寻找解决这个问题的好方法,但还没有想出一个强有力的解决方案。我使用 WebDriver 和 C# 创建了一个测试套件来针对我们的站点运行我们的测试套件。我唯一剩下的问题是我想找到一种方法让整个套件在 FireFox、Chrome 和 IE 中执行。所以基本上,我需要在 FireFox 中完成测试,然后在 Chrome 中完成,最后在 IE 中完成。

我已经研究了 Selenium Grid,目前正在解决它的启动和运行问题,但由于我们没有任何虚拟机可供使用,因此我需要在本地运行它。因此,如果这个问题的一部分是不可能的,或者不是一个好的解决方案,是否有人能够指导我如何设置 Selenium 网格以在我本地的这 3 个主要浏览器中运行?我找到的所有文档都需要虚拟机设置。

4

1 回答 1

1

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

I created an Enum:

/// <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
}

Called it in the TestFixture like so:

/// <summary>
/// Tests related to browsing Google
/// </summary>
[TestFixture(BrowserTypeEnum.Chrome)]
[TestFixture(BrowserTypeEnum.Firefox)]
public class GoogleTests : 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;
        }
    }

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
{
}

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.

于 2012-08-29T12:06:10.143 回答