Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headless driver on Windows/JRuby?

I'm using watir-webdriver on Windows/JRuby. My development has been with firefox.

Watir::Browser.new :firefox

For deployment I need a headless browser, JavaScript support is needed. What options do I have for a headless browser?

like image 617
Craig Anderson Avatar asked Sep 24 '26 19:09

Craig Anderson


2 Answers

I am not quite sure of your requirements for deployment with a headless browser, but my team is using phantomjs along with the jasminerice gem to automate our JavaScript testing on a headless browser with WebKit.

We are using JRuby 1.6.7 and Rails 3.2.3. In our project we are using CoffeeScript, and we wanted to leverage the Rails asset pipeline to do the compiling of CoffeeScript to JavaScript, which is what jasminerice does. If my understanding is correct, this will work for tests and code written in plain ol' JavaScript as well.

The set-up is a bit involved, and you might find wildly varying and probably out-dated accounts of other people getting this to work, but here is a quick guide (gist on Github) that is working for me right now:

  1. Add jasminerice to your Gemfile (gist is here)

  2. Get the latest static build for phantomjs on Windows at http://code.google.com/p/phantomjs/downloads/list

  3. Drop that phantomjs.exe executable somewhere on your PATH. We have this in our Rails project's bin folder, and we have updated our PATH to include that folder.

  4. Create a spec/javascripts folder in your project directory, and create the following spec.js file that will pull into scope any required libraries or folders (gist here)

  5. Create a spec/javascripts/support folder in your project directory, and create the following phantomjs-runner file that will be used to invoke phantomjs to execute your JavaScript test files under spec/javascripts. (gist is here)

  6. Kick up your development Rails server and see jasminerice run your tests by going to http://localhost:5555/jasmine

  7. Alternately, you can create a Rake task that will execute everything for you and return the results to the command line (gist is here).

And those are the hoops we had to jump through in order to get jasminerice and phantomjs to compile and run our CoffeeScript tests headless on Win/JRuby. Hope that helps!

like image 55
buruzaemon Avatar answered Sep 27 '26 18:09

buruzaemon


If you want to run your stuff on a headless linux server, then see this page on the watir-webdriver blog

With Watir-Webdriver you get the same headless options that Webdriver has (since we use webdriver to drive the browser). This has has been written up a few places such as these articles on Alister's WatirMelon blog. Otherwise just do a google search for watir-webdriver headless and you will see a number of useful results.. I would however stick to stuff from the last year or so, earlier things may be a bit out of date by now.

like image 29
Chuck van der Linden Avatar answered Sep 27 '26 17:09

Chuck van der Linden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!