2017-04-22 35 views
7

我创建了一些在本地主机上工作得很好的硒测试,但是当我在appharbor上部署应用程序时,出现异常。在AppHarbor上的Selenium InternetExplorerDriver:无法在本地主机上启动驱动程序服务

此代码抛出异常创建InternetExplorerDriver的新实例:

var options = new InternetExplorerOptions(); 
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 
Driver = new InternetExplorerDriver(DriverDirectory, options); 

这里是个例外:

OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:35187/ 
    at OpenQA.Selenium.DriverService.Start() 
    at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) 
    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) 
    at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) 
    at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) 
    at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(String internetExplorerDriverServerDirectory, InternetExplorerOptions options) 
    ... 

能否请您指教可能是什么原因,是有什么办法解决它?

+0

您可以添加您正在使用的IE ExplorerDriver版本以及Selenium配置。我担心这可能是由于旧的Selenium配置或系统配置问题 - 有点像防火墙。 – demouser123

回答

1

为InternetExplorerDriverService指定的端口333落入公知的端口号码的范围内时:

在大多数系统中,公知的端口号只能由一个系统中使用的(根) 进程或由特权用户运行的程序。 允许驱动程序服务通过未明确指定一个 或提供可用端口来选择其自己的端口。

检查两件事情:

  • 驱动程序位于预期的位置
  • 双击IEDriverServer.exe会给你一个端口 消息的听力,看看它是自动拾取可用。
  • 检查Firwall不阻碍交通环回
2

添加到尼尔斯答案,有时你必须下载IE的.exe文件,并指定它在webdriver的呼叫路径。 如果您之前安装了硒驱动程序,即在安装过程中,它会自动搜索驱动程序。 或者您必须明确下载并提及IE.exe文件的路径。

下载.exe文件,访问链接 http://docs.seleniumhq.org/download/

1

既然不能看到代码,我将开始与此有关,即驱动程序路径。将名为Drivers的文件夹添加到解决方案中。将ie.exe文件添加到它。

将以下添加到您的驱动程序代码。我的猜测是,当你从本地主机到AppHarbor时,路径正在改变。我已经看到这个使用Jenkins和SauceLabs。使用getBasePath将会加载它的位置,并重新安装它。

我认为下面的s正确,但没有测试过。

InternetExplorerOptions options = new InternetExplorerOptions(); 
    options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 
    IWebDriver driver = new InternetExplorerDriver(Path.Combine(GetBasePath, @"Drivers\\"), options); 

driver.Navigate().GoToUrl("http://www.somewhere.com"); 


     public static string GetBasePath 
    { 
     get 
     { 
      var basePath = 
       System.IO.Path.GetDirectoryName((System.Reflection.Assembly.GetExecutingAssembly().Location)); 
      basePath = basePath.Substring(0, basePath.Length - 10); 
      return basePath; 
     } 
    } 
相关问题