最近使用eclipse进行自动化测试时,遇到一种情况,无法调起浏览器,且有报错,如下:
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: 'YuXuefengdeiMac-2.local', ip: 'fe80:0:0:0:3ac9:86ff:fe44:58bb%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x109b95a8e - backtrace::backtrace::trace::h69682bcb53decaf6
1: 0x109b95acc - backtrace::capture::Backtrace::new::hdc9d731a957304a6
2: 0x109af78e3 - webdriver::error::WebDriverError::new::h4c6ae7c4aac049c6
3: 0x109af8352 - _$LT$webdriver..error..WebDriverError$u20$as$u20$core..convert..From$LT$std..io..error..Error$GT$$GT$::from::ha068e680ab4e1954
4: 0x109acb21e - geckodriver::marionette::MarionetteHandler::create_connection::hc09196342b760e35
5: 0x109aad7d4 - _$LT$webdriver..server..Dispatcher$LT$T$C$$u20$U$GT$$GT$::run::hfda25a6dc0b512aa
6: 0x109a85645 - std::sys_common::backtrace::__rust_begin_short_backtrace::h95009c1d3a320838
7: 0x109a8d11d - std::panicking::try::do_call::h8c5f07f1fc714fb2
8: 0x109c469cc - __rust_maybe_catch_panic
9: 0x109aa2f55 - _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h6a96e09ff4d37bff
10: 0x109c42c3b - std::sys::imp::thread::Thread::new::thread_start::h823686b907c11c46
11: 0x7fff9585f99c - _pthread_body
12: 0x7fff9585f919 - _pthread_start
查了资料发现是由于本地的DNS配置中未指定当前主机名的IP地址,解决办法如下:
1、打开Mac系统的终端,查看当前主机的DNS配置:输入命令:cat /etc/hosts(当前电脑中的hosts文件地址);
2、然后编辑主机配置,增加主机名的映射,输入命令sudo vi /private/etc/hosts,进入VI编辑器,增加如下的映射
127.0.0.1 YuXuefengdeiMac-2.local(错误信息中系统的host地址)
3、注意,若之前的DNS配置中缺少127.0.0.1 localhost,一定要加上之后再添加步骤2中信息并保存,如:
127.0.0.1 localhost
127.0.0.1 YuXuefengdeiMac-2.local
4、最后,在终端中输入刷新的命令dscacheutil -flushcache
参考资料:http://blog.csdn.net/longyuhome/article/details/50674442