NEO
NEO

Reputation:

Open Firefox browser with Ruby automation script

How is it possible to open FireFox browser by Ruby(for automation script)? I use

 @browser = RSpecSeleniumHelper.connect_browser('/admin/', '*firefox') 

but it doesn't work.

Upvotes: 2

Views: 7248

Answers (4)

johnnygoodman
johnnygoodman

Reputation: 475

I encountered two issues while getting this running:

  1. If you are running your Ruby app from MacOS, the command firefox may not be properly aliased by default and so may fail without errors printed to your Ruby console.

  2. If you already have an instance of Firefox open, you will get a message saying "Close Firefox - A copy of Firefox is already open. Only one copy of Firefox can be open at a time."

This code fixes both problems:

system("open -a /Applications/Firefox.app/Contents/MacOS/firefox-bin http://www.google.com http://www.cpap.com")
  1. open's -a option Opens with the specified application.
  2. The file path list works for me. If it won't load for you, first drop it and try plain "firefox" and failing that try "/Applications/Firefox.app/Contents/MacOS/firefox"
  3. The example above shows two URLs separated by a space. You can use just one URL or as many as you care to following this pattern.

Upvotes: 0

Jirapong
Jirapong

Reputation: 24256

You may have to check if the Selenium Remote Control is start or not, normally it is running at port 4444.

java -jar selenium-server-xxx.jar

then you can use

@browser = Selenium::Client::Driver.new(
    :host => "localhost",
    :port => 4444,
    :browser => "*firefox", #*iexplore, *firefox3, *safari...
    :url => "http://www.google.com/",
    :timeout_in_second => 60)
@browser.start_new_browser_session

Hope this helps, you can find more demo by download Selenium RC

Upvotes: 0

Jimmy Schementi
Jimmy Schementi

Reputation: 1239

You can use Watir, as it supports Firefox also: http://wtr.rubyforge.org/platforms.html

Upvotes: 1

spas
spas

Reputation: 1934

You can start any program in ruby with:

`firefox http://www.google.com`
or
system("firefox http://www.google.com")

Upvotes: 4

Related Questions