Open Firefox Browser with Ruby Automation Script

How do you open Firefox and multiple tabs from a Ruby script?

Ok, I just tried separating the web addresses by a space in a single system call, and that seems to have solved the problem. I don't know if one is supposed to delete this or not, but I'll leave it in case someone is searching for this.

system("firefox siteone.com/ sitetwo.com/ sitethree.com/")

Ruby browser automation

Selenium / Selenium Ruby is another option and there's Selenium IDE for scripting Firefox.

"It is implemented as a Firefox extension, and allows you to record,
edit, and debug tests."

Watir Changing Mozilla Firefox Preferences

WebDriver uses a clean profile for each browser instance, which is why the preferences appear to be "reset". You can tell it to use your default profile:

Watir::Browser.new :firefox, :profile => "default" 

or tweak profile preferences programatically before launching the browser:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['some.preference'] = true
profile.add_extension "/path/to/some/extension.xpi"

Watir::Browser.new :firefox, :profile => profile

For an example of configuring automatic file downloads, see this section on the Selenium wiki.

How to access Firefox Extension I added in Selenium Webdriver?

It depends on extension. Usually the extension's behaviour can be to some extent controlled by setting appropriate properties (the ones you can find in about:config) when creating an FF profile. For instance to have Firebug window open by default after FF starts I would include the following line in my code:

default_profile["extensions.firebug.allPagesActivation"] = true

The extensions I use usually have some kind of auto-export feature that automatically sends data to server or saves it on disk. I am afraid there is no way of controlling an extension with WebDriver so not all extensions will be usable in automated tests.

firefox not opening - cron, ruby, firewatir

You need to have a DISPLAY environment pointing at a valid X-server. This could either involve setting it to the value ":0.0" (without quotes), such that it refers to your local standard DISPLAY.

There's a few things to keep in mind though:
You could run an X virtual frame buffer (xvfb), so that Firefox simply uses that as it's display. This would mean that Firefox would be able to do all its graphical operations, but that it would be independent of your standard graphical environment. You'll have to set the DISPLAY variable appropriately so that it points to the xvfb instance. For instance, if you invoke xvfb as follows:

Xvfb :1 -screen 0 1600x1200x32

Then you'll be able to use this by setting the DISPLAY variable to :1

You're starting a full-blown firefox instance to simply connect or disconnect your modem. You would most likely be able to use "curl" to send the appropriate HTTP requests to the server, such that it performs a connect or disconnect for you. One way to trivially see what you should recreate would be to install a Firefox plugin such as LiveHTTPHeaders and note down the most important HTTP requests as you perform the actions manually.

There's even a ruby binding for curl:
libcurl for Ruby. The resulting script should be much smaller than your current script.



Related Topics



Leave a reply



Submit