Selenium 网格在浏览器之间混合测试
Selenium grid mixing up tests between browsers
假设我必须在 2 个浏览器中打开 google,在第一个浏览器中搜索测试 1,在第二个浏览器中搜索测试 2。它打开2个浏览器,在一个浏览器中编写Test1Test2并通过测试。我该如何解决?
如果我在每个测试函数中都声明驱动程序,它会工作得很好,但是如果我想稍后在不同的机器上使用 RemoteWebDriver 运行 它就无法做到这一点。(因为它只使用一个节点并且不't do anything on other) 也听说过使用非静态浏览器,但不确定如何使用它,也不确定这是否是问题的解决方案?
命名空间 ParallelGrid
{
[TestFixture]
[Parallelizable]
public class ParallelGrid1
{
[ThreadStatic]
public static IWebDriver driver;
[SetUp]
public void Setup()
{
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver();
// driver = new RemoteWebDriver(new Uri("http://xxx.xxx.xx.xxx:4444/wd/hub"), options.ToCapabilities(), TimeSpan.FromSeconds(600));//hub id goes here
}
[Test]
[Parallelizable]
public void Test1()
{
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).Click();
driver.FindElement(By.Name("q")).SendKeys("Test");
}
[Test]
[Parallelizable]
public void Test2()
{
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).Click();
driver.FindElement(By.Name("q")).SendKeys("Grid");
}
}
}
要使用 NUnit 和 C# 并行化,您一次只能在测试 class 上并行化。所以你必须对每个 class.
进行一次测试
假设我必须在 2 个浏览器中打开 google,在第一个浏览器中搜索测试 1,在第二个浏览器中搜索测试 2。它打开2个浏览器,在一个浏览器中编写Test1Test2并通过测试。我该如何解决?
如果我在每个测试函数中都声明驱动程序,它会工作得很好,但是如果我想稍后在不同的机器上使用 RemoteWebDriver 运行 它就无法做到这一点。(因为它只使用一个节点并且不't do anything on other) 也听说过使用非静态浏览器,但不确定如何使用它,也不确定这是否是问题的解决方案?
命名空间 ParallelGrid {
[TestFixture]
[Parallelizable]
public class ParallelGrid1
{
[ThreadStatic]
public static IWebDriver driver;
[SetUp]
public void Setup()
{
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver();
// driver = new RemoteWebDriver(new Uri("http://xxx.xxx.xx.xxx:4444/wd/hub"), options.ToCapabilities(), TimeSpan.FromSeconds(600));//hub id goes here
}
[Test]
[Parallelizable]
public void Test1()
{
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).Click();
driver.FindElement(By.Name("q")).SendKeys("Test");
}
[Test]
[Parallelizable]
public void Test2()
{
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).Click();
driver.FindElement(By.Name("q")).SendKeys("Grid");
}
}
}
要使用 NUnit 和 C# 并行化,您一次只能在测试 class 上并行化。所以你必须对每个 class.
进行一次测试