Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running the selenium-standalone npm package on an Ubuntu server

I am trying to run selenium-standalone on an Ubuntu server from Digital Ocean. I ssh into the server, then run these commands:

apt-get update
apt-get install nodejs nodejs-legacy npm default-jre
npm install selenium-standalone -g
selenium-standalone install
selenium-standalone start

That leads to a nice message that the selenium standalone server is running! But when I try to connect to it from a simple script on my computer:

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
      .forBrowser('chrome')
      .usingServer('http://XXX.XXX.XXX.XX:4444/wd/hub')
      .build();

I get two huge error messages. On the server, I get:

23:49:09.596 INFO - Executing: [new session: Capabilities [{browserName=chrome}]])
23:49:09.599 INFO - Creating a new session for Capabilities [{browserName=chrome}]
Starting ChromeDriver 2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e) on port 13700
Only local connections are allowed.
23:49:09.644 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ubuntu-nodesele', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
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:124)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:79)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:204)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:166)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:132)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
    at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
    at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ubuntu-nodesele', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:113)
    at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
    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:1)
    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)
    at java.lang.Thread.run(Thread.java:745)
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:103)
    ... 9 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-47-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 23 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ubuntu-nodesele', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.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:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:138)
    ... 14 more
23:49:09.653 WARN - Exception: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-47-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 23 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ubuntu-nodesele', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver

And on my computer, trying to connect to the server, I get:

WebDriverError: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-47-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 23 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'ubuntu-nodesele', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-47-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at WebDriverError (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/lib/error.js:27:5)
    at Object.checkLegacyResponse (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/lib/error.js:505:15)
    at parseHttpResponse (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/lib/http.js:440:13)
    at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebDriver.createSession()
    at Function.createSession (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/lib/webdriver.js:777:24)
    at Function.createSession (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/chrome.js:709:29)
    at createDriver (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/index.js:167:33)
    at Builder.build (/Users/liamgray/webdriverio-test/node_modules/selenium-webdriver/index.js:623:16)
    at new Bot (/Users/liamgray/webdriverio-test/test.js:17:8)
    at Object.<anonymous> (/Users/liamgray/webdriverio-test/test.js:122:11)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

It seems like the errors are saying that Chrome wasn't installed on the server correctly. But I thought that was supposed to happen during the selenium-standalone install command?

Any pointers in the right direction are welcome!

like image 464
fnsjdnfksjdb Avatar asked Mar 10 '23 15:03

fnsjdnfksjdb


1 Answers

The selenium-standalone package installs selenium & it's browser drivers not the browser itself.

Selenium need its browser driver to interact with a specific browser. In your case it needs the chrome driver and it's installed on the server. But you don't have the browser.

You can install chrome by refering to this page. I recommend installing google-chrome-stable

like image 94
Prageeth Saravanan Avatar answered Mar 13 '23 06:03

Prageeth Saravanan