Não é possível iniciar o Chrome com sucesso usando o Selenium no GCE

0

Eu tenho um Google Compute Engine baseado no Debian para executar meus scripts do Selenium, mas não posso, durante minha vida, executar scripts que interfiram com o Chrome. Eu tentei instalar o Chrome e o Chromium - e todas as dependências - sem precisar ir mais longe. Ainda falha

O script do webdriverio: 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();

Saída completa de node script.js

Este é basicamente um subconjunto do erro do processo Selenium

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' 
} }

O processo de selênio

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 [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] 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 [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] 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 [{browserName=safari, version=, platform=MAC}] 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{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
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 [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.L
oggingPreferences@71d24c0f, browserName=chrome, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.6.2, url=ht
tp://webdriver.io}}]])
13:26:24.435 INFO - Creating a new session for Capabilities [{rotatable=true, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging
.LoggingPreferences@71d24c0f, browserName=chrome, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.6.2, url=
http://webdriver.io}}]
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
    
por oligofren 21.06.2017 / 15:42

1 resposta

0

O caminho para a iluminação começou ao tentar reduzir o problema.

Pelo menos, essas partes devem estar funcionando para que os scripts sejam executados:

  1. Selênio e amigos ( webdriverio , ChromeDriver, etc)
  2. O Chrome e as dependências devem ser instalados
  3. O Xvfb deve funcionar
  4. O Chrome deve ser executado no Xvfb
  5. O Chrome deve, de alguma forma, ser executado no Xvfb quando acionado por meio do Selenium

Para trabalhar com isso: O selenium-standalone start parecia funcionar sem erros, portanto, 1 estava OK. 2, 3 e 4 pareciam funcionar como xvfb-run google-chrome --disable-gpu funcionou bem. Não tenho certeza sobre 5 ...

Um ponteiro apontado na direção da combinação do Chrome + Selenium não funcionou foi uma linha na saída:

Chrome failed to start: exited abnormally

Sabemos que o Chrome funciona se X estiver em vigor. Sabemos que o Chrome falha se X não estiver em vigor.

Bem, para obter 5 execuções, eu precisei injetar o Xvfb no mix de alguma forma, o que me deixou duas opções. Enrole o processo do nó ou o processo de selênio. O primeiro não funcionou, mas o segundo fez!

Em um terminal:

xvfb-run selenium-standalone start

No segundo terminal:

node /tmp/script.js 

E finalmente recebi a resposta certa

init ok
Title is: DuckDuckGo

Alguma ajuda adicional de depuração para configurar isso

Vale a pena examinar os rastreamentos de pilha de exceção do Selenium ao tentar depurar o que está errado.

Você pode ter certeza de que está faltando o Google Chrome ou não está instalado quando obtiver isso

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)

Se você não tem a versão correta do Chrome para o Chromedriver, por exemplo, se você instalou apenas o Chromium (meu caso!), você verá este erro:

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)

Assegure-se de que google-chrome-stable esteja no $PATH e que você possa executá-lo com sucesso em um sistema sem cabeçalho.

Outras dicas sobre configuração Confira esta configuração automatizada . Muitos bons indicadores.

    
por 21.06.2017 / 15:42