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.
views:
92answers:
4I 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/")
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.
@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?