Solution to download pdf files automatically in firefox 20+ version using Selenium webdriver or Watir webdriver

Description:

I have tried to save PDF files automatically using the below link — http://watirwebdriver.com/browser-downloads/ and I have followed the same as per the mentioned page and reference website. But still the firefox browser not downloaded PDF files automatically.

Reason:

In Firefox latest versions, They have added new function called as ‘Portable Document Format’ which causes the issue

Note: The latest version 1.3.0. have some issues with rasta. So please install the version 1.2.9

What is Rasta ?

Rasta is a keyword-driven test framework using spreadsheets to drive testing.
It’s loosely based on FIT, where data tables define parmeters and expected
results. The spreadsheet can then be parsed using your test fixtures.

Rasta with Watir:

you’re more likely to use Rasta with another tool like Watir so let’s start
with an example doing some automation with Google’s web site.

Let’s say we wanted to create test cases for testing a search phrase to see if
it qualifies as a Googlewhack. Googlewhacks are two word queries on Google
that produce one and only one result. The best place would be to start
with your spreadsheet.

search_term

is_googlewhack?()

cornball logocentrisms

squirreling dervishes

quantum quizzer

despotism fluidics

megalomaniacal dipsomaniac

So now we have a few data elements and we’re ready to create the test fixture.
Let’s call the class ‘Googlewhack’ so name the tab in your spreadsheet
should also be ‘Googlewhack’ – that’s how Rasta knows which class to call.
First we’ll put in the watir plumbing.

When you include the Rasta fixture in a class you can use before_all(),
after_all(), before_each() and after_each() to do any setup or teardown you
need. Just for grins, let’s go ahead and run our script and see what we get.
I’m assuming here that you have a directory examples\fixtures where you
placed googlewhack.rb.

rasta -f examples\fixtures googlewhack.xls

The IE browser starts like we’d expect and you can see it go to the Google
home page with each row, but we got an error in the cells for the search terms. To
see the error, run your mouse over the cell and it should show something like:

So no tests were run. That must be because we never created the is_googlewhack?()
method. We’ll add support for the search box and hitting the button first.
To know how to call the HTML elements you can either view the source or use the
handy IE Developer Toolbar.

Still no tests run. One thing to remember is that if there is no data in the
spreadsheet (or if the cell is italicized) then nothing happens. The fixture
is correctly setting the attributes, in this case setting search_term, but
there’s no method being called. We need a return value for is_googlewhack?().
It’s not clear that the method returns anything so for now put ‘nil’ in one
of the cells.

search_term

is_googlewhack?()

cornball logocentrisms

nil

squirreling dervishes

quantum quizzer

despotism fluidics

megalomaniacal dipsomaniac

If you run it again, we’re closer. Now the function is getting run for the
first row but the test is still failing because the button click is
returning a decimal instead of nil. That’s OK because we still need to
check the results and give a good return.

Running the script now should look a lot better. It’s very likely that none of
these pass because googlewhacks don’t stay that way for long but you can visit the
site to see some current phrases that should qualify. In addition to the spreadsheet,
the commandline output should show you the details for any failures and how the
test run went.

10 examples? That’s odd because we only set up 5 tests. What’s happening here
is that every test case actually creates two tests. One to run the method,
and the other to report any exceptions found while the command was run. This
is more apparent when you look at the RSpec html output in
rasta_test_results\results.html.

What’s probably a better test though is to instead have the method return the
number of results found so that when the test fails we can have a little more
information on why it failed. You could instead create a method like google_hits()
and parse the results to return the number of hits. Something like this should
work and you can change the spreadsheet from true/false to reflect the number
of hits you expect.