2016-10-01 235 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在默认位置为您的系统,无需提供明确的二进制文件路径为硒脚本,硒本身会从默认位置找到它。

相关问题