我有以下代码来测试Selenium WebDriver。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Starter
{
public static void main(String[] args)
{
WebDriver wd = new FirefoxDriver();
for(String arg: args) wd.get(arg);
wd.close();
}
}
它在我的工作站上运行,但不在服务器上运行。它给了我以下错误:
1511550749849 geckodriver INFO geckodriver 0.19.0
1511550749853 geckodriver INFO Listening on 127.0.0.1:65267
1511550750132 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.svi5yF63xEow"
(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox-esr:15207): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1511550751081 Marionette INFO Listening on port 2828
(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox-esr/plugin-container:15330): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ded5223', ip: '209.239.169.110', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.61reflected', java.version: '1.8.0_102'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x4f388c - backtrace::backtrace::trace::h736111741fa0878e
1: 0x4f38c2 - backtrace::capture::Backtrace::new::h63b8a5c0787510c9
2: 0x442d88 - webdriver::error::WebDriverError::new::hea6d4dbf778b2b24
3: 0x449f99 - geckodriver::marionette::MarionetteHandler::create_connection::hf8b6061dba65cdd0
4: 0x42ac91 - <webdriver::server::Dispatcher<T, U>>::run::hba9181b5aacf8f04
5: 0x402c59 - std::sys_common::backtrace::__rust_begin_short_backtrace::h19de262639927233
6: 0x40c065 - std::panicking::try::do_call::h6c1659fc4d01af51
7: 0x5e38ec - panic_unwind::__rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:98
8: 0x420d32 - <F as alloc::boxed::FnBox<A>>::call_box::h953e5f59694972c5
9: 0x5dc00b - alloc::boxed::{{impl}}::call_once<(),()>
at /checkout/src/liballoc/boxed.rs:661
- std::sys_common::thread::start_thread
at /checkout/src/libstd/sys_common/thread.rs:21
- std::sys::imp::thread::{{impl}}::new::thread_start
at /checkout/src/libstd/sys/unix/thread.rs:84
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$22(ProtocolHandshake.java:365)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
另外,如果设置DISPLAY=:0
,我在服务器上安装了xvfb,如果重要的话。
请帮忙。
答案 0 :(得分:3)
您使用的Selenium和Firefox浏览器有哪些版本?您正在使用geckodriver 0.19.0,因此,如release notes中所述,您应该使用:
无论如何,如果你使用推荐的版本,你是否设置了geckodriver的路径?
你可以用不同的方式做到这一点:
通过webdriver.gecko.driver系统属性指定其位置(请参阅下面的示例)或
System.setProperty("webdriver.gecko.driver", "yourPathTo/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.uk/");
将您的geckodriver移至/usr/local/bin/
最后,无论如何,请确保你的geckodriver是可执行的:
chmod +x geckodriver
答案 1 :(得分:1)
这是几个星期前偶然发现的一个问题。这是我如何解决问题。但首先:你的问题是不同堆栈持有者之间的兼容性问题。
解决方案:
您需要使用以下工具组合
选项1: FF 52或53,GeckoDriver 0.16.0,Selenium Html Runner 3.4.0
选项2: FF 57或以上,GeckoDriver 0.19.0,Selenium Html Runner 3.10.0或 3.11.0
注意:此修复程序适用于Ubunto,Centos 7和Windows
以防万一:如果您正在对Jenkins进行测试并遇到问题,请知道我可以帮助您。