tags:

views:

92

answers:

4

I have a rake file which runs few tasks. I want to run my tests on several browsers without hard-coding it on each test. Any suggestions would be great.

A: 

I guess the best way would be to traverse the filesystem based on your current OS and finding the executables of the browsers you want.

Maybe you can take the Launchy code and make it do what you want? :)
http://copiousfreetime.rubyforge.org/launchy/

Launchy is helper class for launching cross-platform applications in a fire and forget manner. Currently only launching a browser is supported.

Launchy.open("http://www.ruby-lang.org/")

ba
A: 

On OS X, this works for me:

`open #{url}`
kejadlen
+2  A: 

Have you considered using Watir? It provides an abstract interface to browsers for testing including interfaces to Internet Explorer (by default), Firefox (firewatir), Chrome (ChromeWatir) and Safari (SafariWatir) - IE only on Windows (obviously) and Safari only on OS X (I'm not sure, I don't think they've made it work with Safari for Windows).

You basically make either a method or a class which takes the browser and the URI you want to load and loads them using the relevant Watir classes. Then you create Rake tasks which call the relevant method. The advantage of this is you aren't having to work out where Firefox is, and call it differently if it's running or not.

I haven't done any Watir stuff for a while - I'm moved to Celerity/Culerity for browser testing - but even if you aren't using it for testing, you should be able to use it for launching browsers from Ruby across at least Windows and Mac, and possibly Linux too.

Tom Morris
@ss, For running your tests, you could add an environment variable to your tests, something like WATIR_BROWSER="firewatir" and a case statement in your code which creates the correct browser using watir.Then have one rake task which calls your main test task with each of the different variables. You'd get multiple pass/fail readouts, but at least you could run it with one rake task.
Tim Snowhite
A: 

@Tim, I was also trying for almost the same solution but what I exactly wanted was to give my browser as a command line argument to the variable instead of defining it in the test file. Also, I have not used Watir before. Is there any way around using Selenium only? Or I have to move for Watir?

ss