【问题标题】:Sequential execution of WebDriver suite - C# // Selenium Grid - All LocalWebDriver 套件的顺序执行 - C# // Selenium Grid - All Local
【发布时间】:2012-08-28 17:48:58
【问题描述】:

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

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

【问题讨论】:

    标签: c# .net selenium-webdriver selenium-grid


    【解决方案1】:

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

    我创建了一个枚举:

    /// <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 中这样调用它:

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

    在 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 并直接创建它,如下所示:

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

    另一种选择是,如果您使用 CI 服务器解决方案,请创建一个配置设置以指示用于测试的浏览器。让 CI 驱动程序重复测试 3 次,每次都编辑该配置设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 2016-01-17
      • 1970-01-01
      • 2016-06-27
      相关资源
      最近更新 更多