我找到了在多个浏览器上逐一运行测试的方法,但是我找不到一种使用 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
最佳答案
在 Visual Studio 的测试资源管理器中应该有一个按钮,该按钮包含三行,线条左侧有圆圈,右侧有箭头(如果将鼠标悬停在它上面,它会显示“并行运行测试”) ')。确保选中此项(选择时其背景颜色将与测试资源管理器面板不同)。
对于您想要并行的每个测试,请添加属性
Parallelized
。因此,您的方法上方看起来像[Test]
的内容将变为[Test, Parallelizable]
。额外 - 这不适用于您,但适用于少数人,因此我将添加它。如果您的驱动程序是静态实例(如单例),您需要使用
[ThreadStatic]
对其进行注释,否则不同的测试都将在同一驱动程序上调用。
关于c# - 在多个浏览器上并行运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43780706/