Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get WebDriver working on a Mac from Haskell?

So (in my ongoing attempts to try and be a Haskell programmer) I thought I'd try using Haskell to automate control of Firefox on a mac. Went to https://github.com/kallisti-dev/hs-webdriver, installed webdriver, installed the standalone java selenium server and tried running the simple Hello World test (after fixing the syntax error, the 'config' argument to runSession should be (I assume) 'myConfig')

Looked like Firefox opened for a moment, then disappeared. The Java based selenium server produced tons of error messages. See below.

Anyone know what's wrong?

For what it's worth, after trying this, I installed the python bindings and had a python version working in about 10 seconds flat!

dhjmacpro:~/bin $ java -jar selenium-server-standalone-2.42.2.jar
Jul 25, 2014 12:32:28 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
12:32:28.052 INFO - Java: Apple Inc. 20.65-b04-462
12:32:28.053 INFO - OS: Mac OS X 10.9.4 x86_64
12:32:28.061 INFO - v2.42.2, with Core v2.42.2. Built from revision 6a6995d
12:32:28.125 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: MAC
12:32:28.153 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
12:32:28.154 INFO - Version Jetty/5.1.x
12:32:28.154 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
12:32:28.155 INFO - Started HttpContext[/selenium-server,/selenium-server]
12:32:28.155 INFO - Started HttpContext[/,/]
12:32:28.185 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@3dbbd23f
12:32:28.185 INFO - Started HttpContext[/wd,/wd]
12:32:28.190 INFO - Started SocketListener on 0.0.0.0:4444
12:32:28.190 INFO - Started org.openqa.jetty.jetty.Server@4ca31e1b
12:32:55.022 INFO - Executing: [new session: Capabilities [{platform=ANY, javascriptEnabled=null, acceptSslCerts=null, firefox_binary=null, browserName=firefox, rotatable=null, locationContextEnabled=null, unexpectedAlertBehavior=null, version=null, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@45490eb5, firefox_profile=null, databaseEnabled=null, cssSelectorsEnabled=null, handlesAlerts=null, browserConnectionEnabled=null, proxy={proxyType=SYSTEM}, webStorageEnabled=null, nativeEvents=null, applicationCacheEnabled=null, takesScreenshot=null}]])
12:32:55.038 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=null, acceptSslCerts=null, firefox_binary=null, browserName=firefox, rotatable=null, locationContextEnabled=null, unexpectedAlertBehavior=null, version=null, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@45490eb5, firefox_profile=null, databaseEnabled=null, cssSelectorsEnabled=null, handlesAlerts=null, browserConnectionEnabled=null, proxy={proxyType=SYSTEM}, webStorageEnabled=null, nativeEvents=null, applicationCacheEnabled=null, takesScreenshot=null}]
12:32:57.851 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'dhjmacpro', ip: '192.168.0.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.java:83)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:176)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:112)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:89)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:110)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:57)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:112)
    at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:173)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:200)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:162)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:128)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    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.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'dhjmacpro', ip: '192.168.0.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:69)
    at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:53)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:54)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:215)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:59)
    ... 10 more
Caused by: org.openqa.selenium.WebDriverException: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIPrefBranch.setCharPref]
Command duration or timeout: 181 milliseconds
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'dhjmacpro', ip: '192.168.0.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    ... 15 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIPrefBranch.setCharPref]
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'dhjmacpro', ip: '192.168.0.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Driver info: driver.version: unknown
12:32:57.857 WARN - Exception: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIPrefBranch.setCharPref]
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'dhjmacpro', ip: '192.168.0.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.6.0_65'
Driver info: driver.version: unknown
like image 879
David Avatar asked Nov 01 '22 19:11

David


1 Answers

Okay so it seems that the library has not been updated in about a year but here are my suggestions:

  • Use homebrew to install selenium-standalone-server and chromedriver. Then use the config to select the standard Chrome configuration.
  • Beware that the 0.6.1 version of the library is lagging behind the current master that has important fixes to work with the latest selenium-server-standalone. You will find that it is mostly compatible but I ran into one issue: https://github.com/kallisti-dev/hs-webdriver/issues/60

From there you should be able to get the tests up and running. I know that I have it successfully running on my machine. If you have more questions about this approach just ask.

like image 72
Robert Massaioli Avatar answered Nov 15 '22 06:11

Robert Massaioli