2016-10-01 153 views
0

我需要使用帶有Maven的FirefoxDriver創建簡單的自動測試。從pom.xml中如何使用Maven在Firefox中運行Selenium WebDriver測試用例?

摘錄:

<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.53.1</version> 
</dependency> 

測試用例:

@BeforeTest 
public void StartBrowser_NavURL() { 
    capability = DesiredCapabilities.firefox(); 
    capability.setCapability("platform", Platform.ANY); 
    capability.setCapability("binary", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); 


    driver = new FirefoxDriver(capability); 
    driver.manage().window().maximize(); 
} 

@AfterTest 
public void CloseBrowser() { 
    driver.quit(); 
} 

@Test 
public void testToCompareDoubles() { 
    driver.get("http://www.google.com"); 
} 

並運行測試執行命令後

mvn -test 

我收到以下異常:

org.openqa.selenium.WebDriverException:端口7055無法連接到二進制FirefoxBinary(C:\ Program Files(x86)\ Mozilla Firefox \ firefox.exe);過程輸出如下:輕量級關機攔截器LightweightThemeManager

Mozilla Firefox version: 49.0.1(它應該與Selenium Webdriver兼容)。 「hosts」文件是空的。 Windows防火牆被禁用。

你有什麼想法,我該如何解決這個問題?

回答

1

看起來像Selenium2Mozilla Firefox version: 49.0.1之間的不兼容問題。

其實Mozilla has launched executable geckodriver to support latest firefox >= v47就像其他驅動程序可執行與硒。

You need to download latest geckodriver executable first,提取下載的zip文件到您的系統中的任何位置,並與可變webdriver.gecko.driver設定可執行文件本身這個可執行文件路徑爲System正常。

Now run selenium script to launch Mozilla Firefox using marionette如下: -

System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe"); 

//Now you can Initialize marionette driver to launch firefox 
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
capabilities.setCapability("marionette", true); 

WebDriver driver = new MarionetteDriver(capabilities); //for selenium 3 use new FirefoxDriver(capabilities); 

注意: - 如果安裝Mozilla Firefox在默認位置爲您的系統,無需提供明確的二進制文件路徑爲硒腳本,硒本身會從默認位置找到它。

相關問題