ropensci / RSelenium

An R client for Selenium Remote WebDriver
https://docs.ropensci.org/RSelenium
341 stars 81 forks source link

Unable to open firefox #96

Closed rouseguy closed 8 years ago

rouseguy commented 8 years ago

I have RSelenium version 1.4.5. Firefox version is 49.0. I am on Mac OSX 10.11.6

I tried running the following three commands:

startServer()
myBrowser = remoteDriver()
myBrowser$open()

But I got the following error:

> myBrowser$open()
[1] "Connecting to remote server"

Selenium message: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
285-3208198ce6fd}","syncGUID":"psphqt4vctjx","location":"app-global","version":"49.0","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"/Applications/Firefox.app/Contents/Resources/browser/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1474452959000,"updateDate":1474452959000,"applyBackgroundUpdates":1,"skinnable":true,"size":7134,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"49.0","maxVersion":"49... <truncated>
1476030688545   addons.xpi  DEBUG   getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
1476030688546   DeferredSave.extensions.json    DEBUG   Save changes
1476030688546   addons.xpi  DEBUG   Updating database with changes to installed add-ons
1476030688546   addons.xpi-utils    DEBUG   Updating add-on states
1476030688551   addons.xpi-utils    DEBUG   Writing add-ons list
1476030688555   addons.xpi  DEBUG   Registering manifest for /Applications/Firefox.app/Contents/Resources/browser/features/e10srollout@mozilla.org.xpi
1476030688556   addons.xpi  DEBUG   Calling bootstrap method startup on e10srollout@mozilla.org version 1.2
1476030688556   addons.xpi  DEBUG   Registering manifest for /Applications/Firefox.app/Contents/Resources/browser/features/firefox@getpocket.com.xpi
1476030688556   addons.xpi  DEBUG   Calling bootstrap method startup on firefox@getpocket.com version 1.0.4
1476030688557   addons.xpi  DEBUG   Registering manifest for /Applications/Firefox.app/Contents/Resources/browser/features/webcompat@mozilla.org.xpi
1476030688557   addons.xpi  DEBUG   Calling bootstrap method startup on webcompat@mozilla.org version 1.0
1476030688559   addons.manager  DEBUG   Registering shutdown blocker for XPIProvider
1476030688559   addons.manager  DEBUG   Provider finished startup: XPIProvider
1476030688559   addons.manager  DEBUG   Starting provider: LightweightThemeManager
1476030688559   addons.manager  DEBUG   Registering shutdown blocker for LightweightThemeManager
1476030688559   addons.manager  DEBUG   Provider finished startup: LightweightThemeManager
1476030688560   addons.manager  DEBUG   Starting provider: GMPProvider
1476030688567   addons.manager  DEBUG   Registering shutdown blocker for GMPProvider
1476030688567   addons.manager  DEBUG   Provider finished startup: GMPProvider
1476030688567   addons.manager  DEBUG   Starting provider: PluginProvider
1476030688567   addons.manager  DEBUG   Registering shutdown blocker for PluginProvider
1476030688568   addons.manager  DEBUG   Provider finished startup: PluginProvider
1476030688568   addons.manager  DEBUG   Completed startup sequence
1476030689011   addons.manager  DEBUG   Starting provider: <unnamed-provider>
1476030689011   addons.manager  DEBUG   Registering shutdown blocker for <unnamed-provider>
1476030689011   addons.manager  DEBUG   Provider finished startup: <unnamed-provider>
1476030689014   DeferredSave.extensions.json    DEBUG   Starting write
1476030689105   addons.repository   DEBUG   No addons.json found.
1476030689105   DeferredSave.addons.json    DEBUG   Save changes
1476030689109   DeferredSave.addons.json    DEBUG   Starting timer
1476030689151   addons.manager  DEBUG   Starting provider: PreviousExperimentProvider
1476030689151   addons.manager  DEBUG   Registering shutdown blocker for PreviousExperimentProvider
1476030689151   addons.manager  DEBUG   Provider finished startup: PreviousExperimentProvider
1476030689159   DeferredSave.extensions.json    DEBUG   Write succeeded
1476030689160   addons.xpi-utils    DEBUG   XPI Database saved, setting schema version preference to 17
1476030689165   DeferredSave.addons.json    DEBUG   Starting write
1476030689184   DeferredSave.addons.json    DEBUG   Write succeeded

Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: org.openqa.selenium.firefox.NotConnectedException
     Further Details: run errorDetails method
johndharrison commented 8 years ago

Firefox 49 requires the beta 4 server and the latest version of geckodriver https://github.com/mozilla/geckodriver/releases see https://github.com/ropensci/RSelenium/issues/81

rouseguy commented 8 years ago

Thanks. This has introduced a new error now.

(I tried both - running it from the directory having the deckodriver and adding it to the system path)

I ran the following commands

library(RSelenium)
selServ <- RSelenium::startServer(javaargs = c("-D webdriver.gecko.driver='C:/Users/username/Downloads/geckodriver '"))
remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE))
remDr$open

And this resulted in the following error:

> remDr$open()
[1] "Connecting to remote server"

Selenium message: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from https://github.com/jgraham/wires
Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: java.lang.IllegalStateException
     Further Details: run errorDetails method
johndharrison commented 8 years ago

There is no space between -D and webdriver....

so it would be -Dwebdriver.gecko.driver=.....

rouseguy commented 8 years ago

Tried the following commands and these still resulted in an error:

> library(RSelenium)
> selServ <- RSelenium::startServer(javaargs = c("-Dwebdriver.gecko.driver='/Users/rouseguy/Downloads/geckodriver'"))

Warning message:
startServer is deprecated.
Users in future can find the function in file.path(find.package("RSelenium"), "example/serverUtils").
The sourcing/starting of a Selenium Server is a users responsiblity.
Options include manually starting a server see vignette("RSelenium-basics", package = "RSelenium")
and running a docker container see  vignette("RSelenium-docker", package = "RSelenium")

> remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE))
> remDr$open()
[1] "Connecting to remote server"

Selenium message: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from https://github.com/jgraham/wires
Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: java.lang.IllegalStateException
     Further Details: run errorDetails method
johndharrison commented 8 years ago

Can you run

unlink(file.path(find.package("RSelenium"), "bin"),
       recursive = TRUE, force = TRUE)
RSelenium::checkForServer(beta = TRUE)

then

selServ <- RSelenium::startServer(javaargs = c("-Dwebdriver.gecko.driver=\"/Users/rouseguy/Downloads/geckodriver\""))
remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE))
remDr$open()
rouseguy commented 8 years ago

The same issue persists. Here's the command log:

> unlink(file.path(find.package("RSelenium"), "bin"),
+        recursive = TRUE)

> RSelenium::checkForServer(beta = TRUE)

DOWNLOADING STANDALONE SELENIUM SERVER. THIS MAY TAKE SEVERAL MINUTES
trying URL 'http://selenium-release.storage.googleapis.com/3.0-beta4/selenium-server-standalone-3.0.0-beta4.jar'
Content type 'application/java-archive' length 21673022 bytes (20.7 MB)
==================================================
downloaded 20.7 MB

Warning message:
checkForServer is deprecated.
Users in future can find the function in file.path(find.package("RSelenium"), "example/serverUtils").
The sourcing/starting of a Selenium Server is a users responsiblity.
Options include manually starting a server see vignette("RSelenium-basics", package = "RSelenium")
and running a docker container see  vignette("RSelenium-docker", package = "RSelenium")

> selServ <- RSelenium::startServer(javaargs = c("-Dwebdriver.gecko.driver='/Users/rouseguy/Downloads/geckodriver'"))
Warning message:
startServer is deprecated.
Users in future can find the function in file.path(find.package("RSelenium"), "example/serverUtils").
The sourcing/starting of a Selenium Server is a users responsiblity.
Options include manually starting a server see vignette("RSelenium-basics", package = "RSelenium")
and running a docker container see  vignette("RSelenium-docker", package = "RSelenium")

> remDr <- RSelenium::remoteDriver(extraCapabilities = list(marionette = TRUE))
> remDr$open()

[1] "Connecting to remote server"

Selenium message: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from https://github.com/jgraham/wires
Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: java.lang.IllegalStateException
     Further Details: run errorDetails method
rouseguy commented 8 years ago

Chrome works though.

I ran this: brew install chromedriver

And then, in R:

library(RSelenium)
startServer()
remDr <- remoteDriver(browserName = "chrome")
remDr$open()

But not working on Firefox.

johndharrison commented 8 years ago

Note the escaping of the webdriver:

selServ <- RSelenium::startServer(javaargs = c("-Dwebdriver.gecko.driver=\"/Users/rouseguy/Downloads/geckodriver\""))

you can try:

selServ <- RSelenium::startServer(javaargs = c('-Dwebdriver.gecko.driver="/Users/rouseguy/Downloads/geckodriver"'))

In other words the shell may expect " rather then a '

rouseguy commented 8 years ago

Unfortunately, neither of them work. Getting the same error.

johndharrison commented 8 years ago

I dont have a MAC to test with. There is http://brewformulas.org/geckodriver which might help:

brew install geckodriver

Then geckodriver should be in your path so you should just need to pass the marionette capability:

selServ <- RSelenium::startServer()
remDr <- RSelenium::remoteDriver(extraCapabilities = list(marionette = TRUE))
remDr$open()
rouseguy commented 8 years ago

Thanks.

I found a solution that works - and another solution that has a new error :)

Solution that works

The problem seems to be the default port on Mac. And starting the selenium server.

So, I downloaded selenium standalone server from here After unzipping it, using Terminal, I navigated to the folder containing that file and executed the following command:

java -jar selenium-server-standalone-3.0.0-beta4.jar -port 5556

If I try running the above command without the port, I am unable to start the server. It gives an error like this:

java.lang.RuntimeException: java.net.BindException: Address already in use
    at org.openqa.selenium.remote.server.SeleniumServer.boot(SeleniumServer.java:144)

My java version details:

java -version

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Now, in R, I ran the following commands:

library(RSelenium)
remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE), port=5556)
remDr$open()

This fires up the Firefox browser window.

Solution that did not work

The above solution has one bottleneck - that of starting the server manually.

I ran the following commands

selServ <- RSelenium::startServer(port=5556)
remDr <- RSelenium::remoteDriver(extraCapabilities = list(marionette = TRUE), port=5556)
remDr$open()

And this resulted in the following error:

[1] "Connecting to remote server"
Undefined error in RCurl call.Error in queryRD(paste0(serverURL, "/session"), "POST", qdata = toJSON(serverOpts)) :

Any thoughts on how to get around this issue ?

johndharrison commented 8 years ago

The port should be passed as follows:

selServ <- RSelenium::startServer(args = c("-port 5556"))

ellipsis is used for passing arguments to system2

rouseguy commented 8 years ago

Awesome. Thank you so much. This works.

Recapping what needs to be done to make RSelenium work with Firefox on Mac

System Config: OS: Mac OSX 10.11 Firefox 49.0 Java Version: 1.8 RSelenium Version: 1.4.5

Download the latest version of Selenium. In R console, run the following commands

unlink(file.path(find.package("RSelenium"), "bin"),
       recursive = TRUE, force = TRUE)
RSelenium::checkForServer(beta = TRUE)

In terminal, run the following command brew install geckodriver

Running selenium at the default port on Mac has an issue. Run the following command in R console

selServ <- RSelenium::startServer(args = c("-port 5556"))
remDr <- RSelenium::remoteDriver(extraCapabilities = list(marionette = TRUE), port=5556)
remDr$open()
johndharrison commented 8 years ago

Thanks I will add this to the geckodriver post. It looks like kerberos uses port 4444 on MAC. I will look to have a different default port for MAC.