OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:60975/ error using SpecFlow in C# and ChromeDriver

huangapple go评论100阅读模式
英文:

OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:60975/ error using SpecFlow in C# and ChromeDriver

问题

环境设置:

  • 目标框架 - 6
  • Selenium.WebDriver.ChromeDriver - 115.0.5790.17000
  • Selenium.WebDriver - 4.11.0
  • Chrome 版本 - 115.0.5790.171

我试图启动 Chrome 驱动程序,但出现以下错误:

Message: 
OpenQA.Selenium.WebDriverException : 无法启动位于 http://localhost:60975/ 的驱动程序服务

驱动程序初始化代码 -

new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
driver = new ChromeDriver(); driver.Navigate().GoToUrl("www.google.com");

不确定如何解决这个问题?

尝试使用不同版本的 Selenium webdriver,仍然遇到相同的错误。

英文:

Environment settings:

  • Target Framework - 6
  • Selenium.WebDriver.ChromeDriver -115.0.5790.17000
  • Selenium.WebDriver - 4.11.0
  • Chrome Version - 115.0.5790.171

I am trying to launch the chrome driver and getting below error:

Message: 
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:60975/

Driver initialization code -

new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
driver = new ChromeDriver(); driver.Navigate().GoToUrl("www.google.com"); 

Not sure how to resolve this issue?

Tried with different version of Selenium webdriver. Still getting same error.

答案1

得分: 1

错误消息...

消息: OpenQA.Selenium.WebDriverException:无法在http://localhost:60975/上启动驱动程序服务。

...表明Selenium无法启动ChromeDriver服务。


使用Selenium v4.10+版本的解决方法

您需要仔细检查Selenium Manager是否已集成到当前的[tag:specflow] Test Framework_或任何较新版本的Specflow_ _Test Framework_中。

Selenium Manager现在已经完全集成到Selenium v4.10及以后的版本中,可以在后台静默下载匹配的ChromeDriver,并执行测试,您将不再需要WebDriverManager

因此,您的有效代码块可以是:

driver = new ChromeDriver(); 
driver.Navigate().GoToUrl("www.google.com");
英文:

This error message...

Message:  OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:60975/

...indicates that Selenium was unable to start the ChromeDriver service.


Solution with Selenium v4.10+ versions

You need to cross check if Selenium Manager is integrated within the current [tag:specflow] Test Framework or in any of the later versions of the Specflow Test Framework.

Selenium Manager which is now fully integrated with Selenium v4.10 and onwards, can silently download the matching ChromeDriver in the background and execute the test and you won't require WebDriverManager any more.

So your effective code block can be:

driver = new ChromeDriver(); 
driver.Navigate().GoToUrl("www.google.com");

答案2

得分: 0

你提供的代码使用了WebDriverManager来设置ChromeDriver实例。
您可能需要

  • 检查您设置的配置
  • 检查WebDriverManager是否正确下载驱动程序

您可以尝试不使用WebDriverManager,而是通过引用程序集路径中的chromedriver.exe来创建服务。

/// <summary>
/// 获取程序集路径
/// </summary>
/// <returns>程序集的完整路径</returns>
protected static string GetAssemblyPath()
{
    var codeBase = Assembly.GetExecutingAssembly().Location ?? throw new Exception();
    var uriBuilder = new UriBuilder(codeBase);
    var path = Uri.UnescapeDataString(uriBuilder.Path);
    return Path.GetFullPath(path);
}

/// <inheritdoc/>
protected override IWebDriver MakeLocalWebDriver()
{
    var service = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(GetAssemblyPath()));
    var driver = new ChromeDriver(service, ChromeOptions, CommandTimeout);
    return driver;
}

这是不使用WebDriverManager的方式来创建ChromeDriver服务的代码。

英文:

The code you provided uses WebDriverManager to setup a ChromeDriver instance.
You may need to

  • check the configuration that you set
  • check if the WebDriverManager is downloading the driver properly

Instead of using WebDriverManager, you may try to create the service by referring to the chromedriver.exe in the Assembly path.

    /// &lt;summary&gt;
    /// Get Assembly path
    /// &lt;/summary&gt;
    /// &lt;returns&gt;Full path to the assembly&lt;/returns&gt;
    protected static string GetAssemblyPath()
    {
        var codeBase = Assembly.GetExecutingAssembly().Location ?? throw new Exception();
        var uriBuilder = new UriBuilder(codeBase);
        var path = Uri.UnescapeDataString(uriBuilder.Path);
        return Path.GetFullPath(path);
    }


    /// &lt;inheritdoc/&gt;
    protected override IWebDriver MakeLocalWebDriver()
    {
        var service = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(GetAssemblyPath()));
        var driver = new ChromeDriver(service, ChromeOptions, CommandTimeout);
        return driver;
    }

答案3

得分: 0

问题是防火墙已经实施到我们的计算机上。禁用防火墙解决了问题。感谢您的支持。

英文:

The issue was to firewall that was implemented to our machine. Disabling the firewall fixed the issue. Thanks for the support.

huangapple
  • 本文由 发表于 2023年8月4日 05:06:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76831602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定