Chrome kann mit GCE nicht erfolgreich mit Selenium gestartet werden

2068
oligofren

Ich habe eine Debian-basierte Google Compute Engine, um meine Selenium-Skripts auszuführen, ich kann jedoch keine Skripts ausführen, die mit Chrome verbunden sind. Ich habe versucht, sowohl Chrome als auch Chromium - und alle Abhängigkeiten - zu installieren, ohne weiter darüber nachzudenken. Es versagt immer noch

Das webdriverio-Skript: script.js

var webdriverio = require('webdriverio'); var options = { desiredCapabilities: { browserName: 'chrome' } }; var client = webdriverio.remote(options); client .init() .then(()=> { console.log('init ok') }, (err)=> { console.log('init failed', err) }) .url('https://duckduckgo.com/') .getTitle().then(function(title) { console.log('Title is: ' + title); }) .end(); 

Volle Ausgabe von node script.js

Dies ist im Grunde eine Untermenge des Fehlers des Selenium-Prozesses

init failed { Error message: 'unknown error: Chrome failed to start: exited abnormally\n (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c15 31b57),platform=Linux 3.16.0-4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 60.05 s econds\nBuild info: version: \'3.4.0\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'dev-ACME-no\', ip: \'10.132.0.2\', os.name:  \'Linux\', os.arch: \'amd64\', os.version: \'3.16.0-4-amd64\', java.version: \'1.8.0_121\'\nDriver info: driver.version: ChromeDriver', type: 'RuntimeError', seleniumStack:  { status: 13, type: 'UnknownError', message: 'An unknown server-side error occurred while processing the command.', orgStatusMessage: 'unknown error: Chrome failed to start: exited abnormally\n (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291 d320bdf05c1531b57),platform=Linux 3.16.0-4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or time out: 60.05 seconds\nBuild info: version: \'3.4.0\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'dev-ACME-no\', ip: \'10.132.0.2\ ', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.16.0-4-amd64\', java.version: \'1.8.0_121\'\nDriver info: driver.version: ChromeDriver'  } } 

Der Selenprozess

13:26:19.237 INFO - Selenium build info: version: '3.4.0', revision: 'unknown' 13:26:19.237 INFO - Launching a standalone Selenium Server 2017-06-21 13:26:19.256:INFO::main: Logging initialized @248ms to org.seleniumhq.jetty9.util.log.StdErrLog 13:26:19.306 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [] does not match the c urrent platform LINUX 13:26:19.306 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped: registration capabilities Capabilities [] does not match the current platform LINUX 13:26:19.306 INFO - Driver class not found: com.opera.core.systems.OperaDriver 13:26:19.307 INFO - Driver provider com.opera.core.systems.OperaDriver registration is skipped: Unable to create new instances on this machine. 13:26:19.307 INFO - Driver class not found: com.opera.core.systems.OperaDriver 13:26:19.307 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered 13:26:19.308 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped: registration capabilities Capabilities [] does not match the current platform LINUX 2017-06-21 13:26:19.347:INFO:osjs.Server:main: jetty-9.4.3.v20170317 2017-06-21 13:26:19.384:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@55f3ddb1{/,null,AVAILABLE} 2017-06-21 13:26:19.400:INFO:osjs.AbstractConnector:main: Started ServerConnector@1794d431 2017-06-21 13:26:19.400:INFO:osjs.Server:main: Started @393ms 13:26:19.400 INFO - Selenium Server is up and running 13:26:19.685 INFO - SessionCleaner initialized with insideBrowserTimeout 0 and clientGoneTimeout 1800000 polling every 180000 Selenium started 13:26:24.408 INFO - Executing: [new session: Capabilities [}]]) 13:26:24.435 INFO - Creating a new session for Capabilities [}] Starting ChromeDriver 2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57) on port 19256 Only local connections are allowed. 13:27:24.920 WARN - Exception thrown java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'dev-ACME-no', ip: '10.132.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_121' Driver info: driver.version: unknown at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183) at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119) at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95) at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:131) at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59) at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:36) at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111) at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:190) at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:222) at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:184) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:150) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:841) at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:543) at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1228) at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:481) at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1130) at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.seleniumhq.jetty9.server.Server.handle(Server.java:564) at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:320) at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251) at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:112) at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.seleniumhq.jetty9.util.thread.Invocable.invokePreferred(Invocable.java:122) at org.seleniumhq.jetty9.util.thread.strategy.ExecutingExecutionStrategy.invoke(ExecutingExecutionStrategy.java:58) at org.seleniumhq.jetty9.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:201) at org.seleniumhq.jetty9.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:133) at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672) at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590) at java.lang.Thread.run(Thread.java:745) Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'dev-ACME-no', ip: '10.132.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_121' Driver info: driver.version: unknown at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:110) at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:96) at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60) at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222) at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:209) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ... 1 more Caused by: java.lang.reflect.InvocationTargetException 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.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:102) ... 9 more Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.16.0-4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.05 seconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'dev-ACME-no', ip: '10.132.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_121' Driver info: driver.version: ChromeDriver 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:215) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) 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$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.chrome.ChromeDriver.<init>(ChromeDriver.java:184) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:148) ... 14 more 13:27:24.924 WARN - Exception: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.16.0-4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.05 seconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'dev-ACME-no', ip: '10.132.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_121' Driver info: driver.version: ChromeDriver 
0

1 Antwort auf die Frage

0
oligofren

Der Weg zur Erleuchtung begann mit dem Versuch, das Problem einzugrenzen.

Zumindest müssen diese Teile funktionieren, damit die Skripts ausgeführt werden können:

  1. Selen und Freunde ( webdriverio, ChromeDriver usw.)
  2. Chrome und Abhängigkeiten müssen installiert sein
  3. Xvfb muss funktionieren
  4. Chrome muss auf Xvfb laufen
  5. Chrome muss irgendwie auf Xvfb laufen, wenn es durch Selenium ausgelöst wird

Um es selenium-standalone startdurchzuarbeiten : Der schien fehlerfrei zu funktionieren, also war 1 OK. 2, 3 und 4 schienen gut zu funktionieren xvfb-run google-chrome --disable-gpu. Nicht sicher über 5 ...

Ein Zeiger, der in die Richtung der Kombination von Chrome + Selen zeigte, funktionierte nicht in einer Zeile in der Ausgabe:

Chrome failed to start: exited abnormally 

Wir wissen, dass Chrome funktioniert, wenn X installiert ist. Wir wissen, dass Chrome fehlschlägt, wenn X nicht vorhanden ist.

Um 5 zum Laufen zu bringen, musste ich Xvfb irgendwie in den Mix einspritzen, was mir zwei Möglichkeiten gab. Umschließen Sie entweder den Knotenprozess oder den Selenprozess. Der erste hat nicht funktioniert, der zweite aber!

In einem Terminal:

xvfb-run selenium-standalone start 

Im zweiten Terminal:

node /tmp/script.js 

Und endlich bekam ich die richtige Antwort

init ok Title is: DuckDuckGo 

Einige zusätzliche Debugging-Hilfe beim Einrichten dieses Problems

Es lohnt sich, die Ausnahmestapelspuren von Selenium durchzusehen, wenn Sie versuchen, das zu debuggen, was falsch ist.

Sie können sicher sein, dass Sie Chrome vermissen oder nicht installiert sind, wenn Sie dies erhalten

Caused by: org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.16.0-4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information) 

Wenn Sie nicht über die richtige Version von Chrome für Chromedriver verfügen, wenn Sie beispielsweise nur Chromium installiert haben (mein Fall!), Wird dieser Fehler angezeigt:

Caused by: org.openqa.selenium.SessionNotCreatedException: session not created exception: Chrome version must be >= 58.0.3029.0 (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.16.0-4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information) 

Stellen Sie sicher, dass google-chrome-stablees sich in dem befindet $PATHund dass Sie es erfolgreich auf einem Headless-System ausführen können.

Weitere Tipps zum Setup Schauen Sie sich dieses automatisierte Setup an . Viele nette Hinweise.