我一直有一些问题,希望有人可以帮助我。我一直在使用3.9.1版本的“standalone-firefox-debug”docker容器,当我尝试在java中运行一些简单的代码时:
Capabilities firefoxCapabilities = DesiredCapabilities.firefox();
WebDriver firefox = null;
try {
firefox = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), firefoxCapabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
// run against firefox
firefox.get("https://www.google.com");
System.out.println(firefox.getTitle());
firefox.quit();
我明白了:
Feb 28, 2018 8:55:18 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload@3d3ab55a
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'chuck-berry-67576fd57-qdmww', ip: '10.60.239.32', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1027-gke', java.version: '1.8.0_151'
Driver info: driver.version: unknown
Command duration or timeout: 24.10 seconds
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.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
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:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
at com.icxmedia.chuckberry.MyRemoteTest.main(MyRemoteTest.java:19)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload@3d3ab55a
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'chuck-berry-67576fd57-qdmww', ip: '10.60.239.32', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1027-gke', java.version: '1.8.0_151'
Driver info: driver.version: unknown
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'chuck-berry-67576fd57-qdmww', ip: '10.60.239.32', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1027-gke', java.version: '1.8.0_151'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:75)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:74)
at java.util.Optional.orElseGet(Optional.java:267)
at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:72)
at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:242)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
我尝试使用这个简单的代码在本地运行:
FirefoxOptions options = new FirefoxOptions();
FirefoxDriver firefox = new FirefoxDriver(options);
firefox.get("https://www.google.com");
System.out.println(firefox.getTitle());
firefox.quit();
我明白了:
1519851277248 geckodriver INFO geckodriver 0.19.1
1519851277348 geckodriver INFO Listening on 127.0.0.1:20541
1519851286351 mozrunner::runner INFO Running command: "/opt/firefox-58.0.1/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.XkiA4TsH5rcO"
1519851295354 Marionette INFO Enabled via --marionette
Exception in thread "main" org.openqa.selenium.WebDriverException: Process unexpectedly closed with status: {unknown}
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'chuck-berry-67576fd57-qdmww', ip: '10.60.239.32', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1027-gke', java.version: '1.8.0_151'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x4edb3c - backtrace::backtrace::trace::hc4bd56a2f176de7e
1: 0x4edb72 - backtrace::capture::Backtrace::new::he3b2a15d39027c46
2: 0x440ac8 - webdriver::error::WebDriverError::new::ha0fbd6d1a1131b43
3: 0x4487ce - geckodriver::marionette::MarionetteHandler::create_connection::hf0532ddb9e159684
4: 0x428570 - <webdriver::server::Dispatcher<T, U>>::run::h2119c674d7b88193
5: 0x4029b9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21d98a9ff86d4c25
6: 0x40be65 - std::panicking::try::do_call::h5cff0c9b18cfdbba
7: 0x5e6a6c - panic_unwind::__rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:99
8: 0x41eb22 - <F as alloc::boxed::FnBox<A>>::call_box::h413eb1d9d9f1c473
9: 0x5df13b - alloc::boxed::{{impl}}::call_once<(),()>
at /checkout/src/liballoc/boxed.rs:692
- 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$0(ProtocolHandshake.java:123)
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:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at com.icxmedia.chuckberry.MyLocalTest.main(MyLocalTest.java:13)`
非常感谢你看一看。
答案 0 :(得分:0)
原来我正在使用的VM需要更多内存。我碰到了这一点,但Firefox仍然无法正常工作。我切换到Chrome,工作正常。希望这有助于某人。