'未能查找地址信息'在Mac OS上使用Gecko驱动程序执行硒测试时显示错误

问题描述:

我在使用Gecko驱动程序在Mac OS中执行Selenium测试时遇到了凝灰岩时间问题。我使用Firefox 56.'未能查找地址信息'在Mac OS上使用Gecko驱动程序执行硒测试时显示错误

这是我用来初始化网络驱动程序的代码。

System.setProperty("webdriver.gecko.driver", "/Users/<username>/Documents/Tools/geckodriver"); 
DesiredCapabilities capabilities=DesiredCapabilities.firefox();   
capabilities.setCapability("marionette", true); 
WebDriver driver = new FirefoxDriver(capabilities); 

现在,当我执行测试,似乎壁虎驱动程序初始化,但显示下面提到的错误和浏览器未初始化。

1507662170977 geckodriver INFO geckodriver 0.19.0 
1507662170983 geckodriver INFO Listening on 127.0.0.1:42748 
FAILED CONFIGURATION: @BeforeClass initializeDriver 
org.openqa.selenium.WebDriverException: failed to lookup address information: nodename nor servname provided, or not known 
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z' 
System info: host: '<username>s-MacBook-Pro.local', ip: '192.168.1.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144' 
Driver info: driver.version: FirefoxDriver 
remote stacktrace: stack backtrace: 
    0:  0x10d96ca8e - backtrace::backtrace::trace::h69682bcb53decaf6 
    1:  0x10d96cacc - backtrace::capture::Backtrace::new::hdc9d731a957304a6 
    2:  0x10d8ce8e3 - webdriver::error::WebDriverError::new::h4c6ae7c4aac049c6 
    3:  0x10d8cf352 - _$LT$webdriver..error..WebDriverError$u20$as$u20$core..convert..From$LT$std..io..error..Error$GT$$GT$::from::ha068e680ab4e1954 
    4:  0x10d8a221e - geckodriver::marionette::MarionetteHandler::create_connection::hc09196342b760e35 
    5:  0x10d8847d4 - _$LT$webdriver..server..Dispatcher$LT$T$C$$u20$U$GT$$GT$::run::hfda25a6dc0b512aa 
    6:  0x10d85c645 - std::sys_common::backtrace::__rust_begin_short_backtrace::h95009c1d3a320838 
    7:  0x10d86411d - std::panicking::try::do_call::h8c5f07f1fc714fb2 
    8:  0x10da1d9cc - __rust_maybe_catch_panic 
    9:  0x10d879f55 - _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h6a96e09ff4d37bff 
    10:  0x10da19c3b - std::sys::imp::thread::Thread::new::thread_start::h823686b907c11c46 
    11:  0x7fffdf79f93a - _pthread_body 
    12:  0x7fffdf79f886 - _pthread_start 

您的解决方案,将不胜感激。

+0

以前是否有效?首先我检查这样奇怪的错误是,我使用的geckodriver与我拥有的Firefox版本兼容。我还检查了所有这些与我使用的硒版本兼容。 – mrfreester

+0

似乎你的DNS解析存在一些问题。你能设置你的日志来跟踪并再次显示输出吗? –

+0

@mrfreester不,我在Mac机上首次创建自动化框架。 –

显然存在问题with the JDK and OSX其中主机名不认本地主机。

解决方法是将localhost添加到/ etc/hosts

您需要的功能传递到驱动程序:

WebDriver driver = new FirefoxDriver(capabilities); 
+0

是的,我也试过这个。还是行不通。 –