c# - 在多个浏览器上并行运行测试

标签 c# selenium selenium-grid

我找到了在多个浏览器上逐一运行测试的方法,但是我找不到一种使用 selenium grid 来在多个浏览器上并行运行测试的方法(使用 C#)。 这就是我目前正在使用的:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.Threading;

namespace SeleniumTests 
{
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
    private IWebDriver driver;

    [SetUp]
    public void CreateDriver () {
        this.driver = new TWebDriver();
    }

    [Test]
    public void GoogleTest() {
        driver.Navigate().GoToUrl("http://www.google.com/");
        IWebElement query = driver.FindElement(By.Name("q"));
        query.SendKeys("Bread" + Keys.Enter);

        Thread.Sleep(2000);

        Assert.AreEqual("bread - Google Search", driver.Title);
        driver.Quit();
    }
  }
}

Run Selenium tests in multiple browsers one after another from C# NUnit

最佳答案

  1. 在 Visual Studio 的测试资源管理器中应该有一个按钮,该按钮包含三行,线条左侧有圆圈,右侧有箭头(如果将鼠标悬停在它上面,它会显示“并行运行测试”) ')。确保选中此项(选择时其背景颜色将与测试资源管理器面板不同)。

  2. 对于您想要并行的每个测试,请添加属性Parallelized。因此,您的方法上方看起来像 [Test] 的内容将变为 [Test, Parallelizable]

  3. 额外 - 这不适用于您,但适用于少数人,因此我将添加它。如果您的驱动程序是静态实例(如单例),您需要使用 [ThreadStatic] 对其进行注释,否则不同的测试都将在同一驱动程序上调用。

关于c# - 在多个浏览器上并行运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43780706/

相关文章:

c# - 有条件地检查用户是否登录 Umbraco

c# - 按升序排列数组的值

python-3.x - 使用 Selenium 修改 HTML

javascript - 如何从我们使用selenium输入的文本区域获取文本

selenium - 使用 selenium 网格进行并行测试时,如何创建文件夹(每个浏览器使用)?

c# - 开发数学库

c# - 如果列表不为空,则将拦截添加到查询

java - 从属性文件设置 SuiteClassess 并在命令行中 indtentify 属性文件

java - 尝试通过 Selenium Grid 独立 jar 3.14 在 LINUX 上创建 FIREFOX 驱动程序时如何解决 SessionNotCreatedException 异常

selenium - 创建 RemoteWebDriver 时传递的 Url/Ip