[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Watir and Ruby; validate list of expected links

reed.adam@gmail.com

5/16/2006 10:16:00 PM

All,

The most important part of the site I need to test is content. I need
to make sure that specific links exist, and direct to the correct pages
(this is all dynamic content set in a form by a user).

Being new to Watir and having done the scripting 101 test and viewing
examples, one method to test would be the following. Of course, it's
just looking for text not links, but the general purpose is the same:

if ie.contains_text("Home")
puts "Test Passed. Found the test string: 'Home'."
else
puts "Test Failed! Could not find: 'Home'"
end
if ie.contains_text("This Link")
puts "Test Passed. Found the test string: 'This Link'."
else
puts "Test Failed! Could not find: 'This Link'"
end
etc,etc,etc,etc,etc!!!!!

That's 5 lines per link -- there has to be a better way! I researched
the assert commands and such, but there isn't much documentation on how
to use them.

How would a more experienced Watir/Ruby programmer address this issue?
I will be verifying links like this, specific images, body text. . .
believe it or not, the automated functions like logging in and moving
around seem much easier to me!

Thanks in advance,
Adam

8 Answers

uncutstone

5/17/2006 1:49:00 AM

0

reed.adam@gmail.com wrote:

> All,
>
> The most important part of the site I need to test is content. I need
> to make sure that specific links exist, and direct to the correct pages
> (this is all dynamic content set in a form by a user).
>
> Being new to Watir and having done the scripting 101 test and viewing
> examples, one method to test would be the following. Of course, it's
> just looking for text not links, but the general purpose is the same:
>
> if ie.contains_text("Home")
> puts "Test Passed. Found the test string: 'Home'."
> else
> puts "Test Failed! Could not find: 'Home'"
> end
> if ie.contains_text("This Link")
> puts "Test Passed. Found the test string: 'This Link'."
> else
> puts "Test Failed! Could not find: 'This Link'"
> end
> etc,etc,etc,etc,etc!!!!!
>
> That's 5 lines per link -- there has to be a better way! I researched
> the assert commands and such, but there isn't much documentation on how
> to use them.

If what you want is to shorten your code, you can do it this way:

def ie.assert_contains(sth)
if self.contains_text(sth)
puts "Test Passed. Found the test string: #{sth}."
else
puts "Test Failed! Could not find: #{sth}"
end
end
ie.assert_contains('home')
ie.assert_contains('this link')

Best regards.

reed.adam@gmail.com

5/17/2006 4:03:00 AM

0

So, where you put "sth", what exactly does that mean? The rest makes
sense to me -- I was trying to find a way that a variable/string could
be used like that instead of repeating the code. Thank you very much!

Last question, where did you learn to do that? I could not find use of
ie.assert in the documentation that came with Watir.


More replies are always welcome, I'd love to get a few perspectives.

senthil.nayagam@gmail.com

5/17/2006 5:02:00 AM

0

Adam,

I am a great fan of Watir, but I do not use it for all the work, as it
becomes slower.

For my company's new site, which is on rails, I had to do link
validations and also analysis of links, keywords, page size etc.

I used Ruby WWW::Mechanize, to build a custom bot to identify and crawl
all pages, and collect statistics

Results: my site has 120+ pages and 7000+ internal links, 50+ external
links, this includes content from our CMS.

also it found few broken links, which we were able to fix.


webserver logs, website tracking tools are useful for analysis

I use Watir for small testing tasks like authentication, js bugs,
screenshots.

regards
SenthilNayagam

reed.adam@gmail.com

5/17/2006 5:13:00 AM

0

Thank you for the input Senthi -- I am just bringing my company into
the 19th century (no typo) as far as QA/Testing is concerned. We have
3 sites that are no longer going to be updated which I am writing these
simple tasks for while I learn Ruby/Watir.

Over the next 12 months we will have about 7-8 new sites for testing.
At that point hopefully I will know quite a bit more about Ruby and be
able to support those projects.

I know the answer to the question is relative to the person answering
it, but how difficult was it for you to design that bot? Like I said,
I am just getting to know Watir and Ruby -- I have the logic for
scripting, it just hasn't been available to our company until recently.

I am sure something like that would serve us well. Our sites will
require link testing on static pages, and then automated login/action
on the dynamic pages (most likely they will judge those as "too many
links" to test).

And of course, can you share the source for that bot?

senthil.nayagam@gmail.com

5/17/2006 5:39:00 AM

0

getting the bot to work was about an hour,

the difficult part were the analysis stuff, which took 2 days.

can't opensource it now, probably will add it as a service from my
website, will keep you updated

regards
Senthil Nayagam

uncutstone

5/17/2006 6:18:00 AM

0

>Ok, so sth is a variable you created to be able to assign each link name/etc at the >end of that code? That's not ruby-reserver, right? (I'm an idiot)

No, it is't ruby-reserved, it's just a argument name, a argument of a
function.

>>On 5/16/06, uncutstone <uncutstone@sina.com> wrote:

>>reed.adam@gmail.com wrote:
>> So, where you put "sth", what exactly does that mean? The rest makes
> >sense to me -- I was trying to find a way that a variable/string could
> >be used like that instead of repeating the code. Thank you very much!
>>
>>"sth" means something you are searching. :-)

> >Last question, where did you learn to do that? I could not find use of
> >ie.assert in the documentation that came with Watir.

>>That's irrelevant to Watir. It's ruby, its dynamic feature let me do
>>that. Please take a look at "programming ruby".

>>Best regards.

reed.adam@gmail.com

5/17/2006 12:47:00 PM

0

Well, I definitely wasn't expecting you to say "an hour" even just for
the bot section -- that's very encouraging. While I doubt I'll be able
to do it in the same timeframe right now, it's nice to know that it can
eventually be done.

Thanks again for the info!

bpettichord

5/20/2006 3:33:00 AM

0

Your script does not test for links, but rather for text. This will
find links (using Watir):

require 'test/unit/assertions'
assert ie.link(:text, "Home").exists?
assert ie.link(:text, "This Link").exists?

I also like the suggestion to use Mechanize.

Bret