我正在尝试使用 WebDriver、Nunit 和 C# 在多个浏览器上运行测试。它正在运行,但我在 Chrome 中收到了烦人的安全警告。为了修复它,我需要使用“.AddArguments(”--test-type”);”重新创建驱动程序。但我只想在这次迭代浏览器 = Chrome 时这样做。这是我的代码。它可以工作,但它会先启动一个不需要的浏览器窗口。有人对此有任何想法吗?
namespace SeleniumTests
{
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
[SetUp]
public void CreateDriver()
{
this.driver = new TWebDriver(); //Creates a window that needs to be closed and re-constructed
if(driver is ChromeDriver)
{
driver.Quit(); //This kills the un-needed driver window created above
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--test-type");
driver = new ChromeDriver(chromeOptions);
}
}
最佳答案
为什么不在基类中简单地创建 chromedriver 呢?您还可以在那里使用 chromoptions
来传递必要的参数。然后使用
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
这也会避免不必要的代码重复和困惑。
我有驱动程序实例的完整实现 here
关于c# - 使用 WebDriver、Nunit 和 C# 测试具有不同选项的多个浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601515/