2017-04-22 36 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; 
     } 
    } 
相關問題