【发布时间】:2021-12-03 10:54:35
【问题描述】:
所以我正在使用 Visual Studio 并安装了 Specflow 扩展、Specflow 项目,并且有一个包含启动 Chrome 驱动程序的方法的类库项目。 我用 Specflow 编写的测试是;
LaunchDriver launchDriver = new LaunchDriver() ;
[Given(@"I Launch a Chrome Driver")]
public void GivenILaunchAChromeDriver()
{
launchDriver.LaunchChrome();
}
LaunchDriver 类的代码是:
public class LaunchDriver
{
public IWebDriver webDriver;
public void LaunchChrome()
{
string PathtoChromeExe = @"C:\Program Files (x86)\Google\Chrome\Application\";
webDriver = new ChromeDriver(PathtoChromeExe);
webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(5);
webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
webDriver.Manage().Window.Maximize();
}
}
当我尝试通过测试资源管理器运行此测试时,我看到测试由于以下错误而失败
启动驱动程序并导航到 Google.com 持续时间:378 毫秒
Message:
The file C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html
Stack Trace:
OpenQA.Selenium.DriverServiceNotFoundException: The file C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html
DriverService.ctor(String servicePath, Int32 port, String driverServiceExecutableName, Uri driverServiceDownloadUrl)
ChromiumDriverService.ctor(String executablePath, String executableFileName, Int32 port, Uri downloadUrl)
ChromeDriverService.ctor(String executablePath, String executableFileName, Int32 port)
ChromeDriverService.CreateDefaultService(String driverPath, String driverExecutableFileName)
ChromeDriverService.CreateDefaultService(String driverPath)
我需要启动的 Chrome 驱动程序,它的文件名是我指定的路径中的 chrome.exe,但由于某种原因,Specflow 或系统正在寻找 chromedriver.exe 以启动它无法找到。 如何配置我的代码以启动 chrome.exe 而不是 chromedriver.exe?
【问题讨论】:
标签: c# selenium selenium-webdriver selenium-chromedriver specflow