【问题标题】:Multiple public constructors with same maximum parameter count are not supported不支持具有相同最大参数计数的多个公共构造函数
【发布时间】:2018-11-08 08:19:38
【问题描述】:

我有这两门课

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)

请帮忙!

【问题讨论】:

标签: c# selenium-webdriver


【解决方案1】:

基于这个答案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");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多