Automating browser actions on a headless server - ruby

I'm looking for a ruby solution to automate web accions on a headless server (no xwindows).
What I need is to daily export a file from a webapp and import it to other web app in other server.
I've seen Selenium, Capybara, Nokogiri, but I'm confused with their differences/similarities. Selenium seems to require a browser running, which I can't have as there is no X to run it. Nokogiri can use Webkit on a headless server, but can't figure out if it can actually download/upload files.
Any pointer would be appreciated.

I would suggest mechanize. I'm not sure that you need something like selenium for a task like this.
This gem should be able to accomplish what your looking for.

It's not Ruby, but...I'd strongly consider using something like PhantomJS (+ CasperJS, perhaps) or Zombie.js. They're all JavaScript, but...I'd still see if you can make them work.

Related

Any option to use Ruby-Cucumber-selenium scripts for recording Jmeter scripts?

For my functional tests I have Ruby -Cucumber scripts which used selenium webdriver.
For my performance testing instead of manually recording the script for the website navigation, I want to use existing function test automation.
Is there any way to integrate this?
Is there any plug-in or way to integrate them?
Thanks in advance!
Tried before: Have used one jemeyer session, with Blazemeter plugin in this session, started recording, in second Jmeter session opened, in that used simple selenium scripts to execute to open chrome browser, navigation to the website.
But with this approach there was some bizarre error which didn’t go anywhere so looking for altérnate approach.

How to install JSSH firefox plugin on Mac?

Thats basically my question. I have searched the internet and I have no idea!
I read in a tutorial (http://www.layeredthoughts.com/automation/how-to-write-your-first-ruby-web-bot-in-watir-scraping-weather-com) that I need to install JSSH for the tutorial to work, but there are no instructions on how to do this and I cannot find anything on the watir homepage.
You do not need to install the JSSH plugin to drive Firefox.
If I recall correctly, the JSSH plugin was needed several years ago - probably back in 2010 when the article you referenced was written. Driving Firefox, as well as Watir, have come a long way since then.
As a result, you should try following a more recent tutorial. Then go back to the article you were reading if there are additional tips you need, but would like need to adjust.
Željko Filipin's Watirbook has been frequently updated with steps for installing Selenium-Webdriver on various operating systems for various browsers. Note that Watir is simply an API wrapper around Selenium.
The installation steps are simply (for more explicit details/steps see the book):
Install Ruby
Install selenium-webdriver
Install the watir and watir-webdriver gems (this is not listed in the book, but they are required if you want to use the Watir API instead)
Install Firefox (if it is not already)
That is it. The other plugins (Test-Wise Recorder, Firebug, FireXPath) are not needed. The latter two can be replaced by Firefox's built-in developer tools. The usefulness of recorder is often debated.
Once everything is installed you can start off with a script like:
require 'watir'
browser = Watir::Browser.new :firefox
browser.goto 'http://www.weather.com/
Then you can start working on automating the page.

Is there any way to automate the testing of flash within web pages using Watir-Webdriver?

I am attempting to test several web pages built in Flex, and need to automate clicking on several videos through the Flash interface. I'm using Ruby and Watir-Webdriver, but I'm not sure how to interact with Flash using them.
Has anyone figured this out? I've tried using Sikuli, but have found it to be a little clunky and not very fast. Any ideas would be greatly appreciated.
I will quote myself:
It is important to say that Watir CAN NOT control browser plugins like
Java applets, Adobe Flash or Microsoft Silverlight.
From https://github.com/zeljkofilipin/watirbook/blob/master/about.md
There is a way though. You can embed javascript into your ruby watir script.
It has worked for me
browser.execute_script <<-JS
Global.videoPlayer.sendEvent("play")
JS
Similarly you can do a pause or stop based on the controller on the player
Enjoy !!

Automating Web Access and Watir

I'm building a Ruby program that uses several other programs, and while most of them are programs I can download and run on this computer, one has to be accessed and run through a web browser.
I actually have two questions: I've found Watir which looks like a good web automation tool, but it's meant for testing. Is it still okay to use Watir for automation in the main program, not for testing? Or is there something better out there to use?
The other question I have is that I can't get Watir to work. I downloaded the firewatir-1.6.5 gem and installed jssh for Firefox 3.6, but when I run
b = Watir::Browser.start("the_web_page_address")
it just opens a new Firefox window to Google, and I'm given the error:
Unable to connect to machine : foo.bar.baz.blah on port 9997. Make sure that JSSh is properly installed and Firefox is running with '-jssh' option (Watir::Exception::UnableToStartJSShException)
I've run Firefox with -jssh but that doesn't seem to help.
Watir is perfectly suitable for automating browsing tasks. I've personally used it a couple of times for that purpose. However, you might also want to look at other solutions, such as Selenium.
Now, to be honest, I don't have much to say about your second question;
I'm assuming you've set Watir to open firefox by setting
Watir::Browser.default = 'firefox'
If so, things should be running as normal. Did you restart firefox since installing jssh? Did you install Watir and jssh as instructed on the tutorial?
I can suggest running Watir with Internet Explorer, instead of Firefox, but that might be unsuitable for your application. If all else fails, try the other framework I recommended earlier.
You also might want to check out a headless option. Sometimes it's not necessary to install an automation framework like Watir or Selenium when something simple like mechanize would suffice. Really depends on the complexity of what you're trying to automate!
http://mechanize.rubyforge.org/mechanize/EXAMPLES_rdoc.html

How to Programmatically take Snapshot of Crawled Webpages (in Ruby)?

What is the best solution to programmatically take a snapshot of a webpage?
The situation is this: I would like to crawl a bunch of webpages and take thumbnail snapshots of them periodically, say once every few months, without having to manually go to each one. I would also like to be able to take jpg/png snapshots of websites that might be completely Flash/Flex, so I'd have to wait until it loaded to take the snapshot somehow.
It would be nice if there was no limit to the number of thumbnails I could generate (within reason, say 1000 per day).
Any ideas how to do this in Ruby? Seems pretty tough.
Browsers to do this in: Safari or Firefox, preferably Safari.
Thanks so much.
This really depends on your operating system. What you need is a way to hook into a web browser and save that to an image.
If you are on a Mac - I would imagine your best bet would be to use MacRuby (or RubyCocoa - although I believe this is going to be deprecated in the near future) and then to use the WebKit framework to load the page and render it as an image.
This is definitely possible, for inspiration you may wish to look at the Paparazzi! and webkit2png projects.
Another option, which isn't dependent on the OS, might be to use the BrowserShots API.
There is no built in library in Ruby for rendering a web page.
Using Selenium & Ruby is one possibility. You can run Firefox as a headless browser (ie on a server).
Here is the source code for browser shots. http://sourceforge.net/projects/browsershots/files/
If you are using Linux you could use http://khtml2png.sourceforge.net/ and script it via Ruby.
Some paid services to try and automate
http://webthumb.bluga.net/home
http://www.thumbalizr.com
as viewed by.... ie? firefox? opera? one of the myriad webkit engines?
if only it were possible to automate http://browsershots.org :)
Use selenium-rc, it comes with snapshot capabilities.
With jruby you can use SWT's browser library.

Resources