我有这两个课程
public class BrowserContext
{
private readonly ChromeDriver _driver;
public BrowserContext(ChromeDriver driver)
{
_driver = driver;
}
public void NavigateTo()
{
_driver.Navigate().GoToUrl("http://bbc.com");
}
}
public class Homepage
{
private readonly BrowserContext _browserContext;
public Homepage(BrowserContext browserContext)
{
_browserContext = browserContext;
}
[Given(@"I navigate to url")]
public void GivenINavigateToUrl()
{
_browserContext.NavigateTo();
}
当我尝试运行测试时,出现以下错误
多个具有相同最大参数计数的公共构造函数不 支持的! OpenQA.Selenium.Chrome.ChromeDriver(解析路径: ClassLibrary3.Steps.Homepage-> ClassLibrary3.Support.BrowserContext)
请帮助!
答案 0 :(得分:0)
基于此答案https://stackoverflow.com/a/26402692/10148657的解决方案是在BrowserContext构造函数中实例化ChromeDriver,而不是在构造函数中接受它:
public class BrowserContext
{
private readonly ChromeDriver _driver;
public BrowserContext()
{
_driver = new ChromeDriver();
}
public void NavigateTo()
{
_driver.Navigate().GoToUrl("http://bbc.com");
}
}