11.10.06
Tests and How-To Documents
You have a bunch of tests, right? With every build of your application under test, you run them all. If a test fails, application should be fixed, or you test should be fixed. Wouldn’t it be nice to make how-to documents from that tests?
Time for an example (Ruby, Watir):
You run that test, and you get output like this (this is real output from my test):
log in
- go to ‘[application url]/login.aspx’
- (url should be ‘[application url]/login.aspx’)
- (there should be text ‘Please Login’)
- at text field ‘userName’ enter ‘[userName]‘
- at text field ‘password’ enter ‘[password]‘
- click button ‘Login’
- (url should be ‘[application url]/default.aspx’)
- (there should be text ‘Recent Contributions’)
- (there should be text ‘logged in as [first name] [last name]‘)
I posted this at wtr-general list and people recommended to take a look at rSpec and Systir.


Balaji said,
December 20, 2006 at 4:41 pm
I want to click on an image button “IMG SRC=’/images/agent/btn_save_continue.gif’ BORDER=0 STYLE=’cursor: pointer’ onClick=’change_has_been_handled = true; if
(!this.clicked) {document.the_form.submit();; this.clicked = true;}’”
How to do that?
$ie.image(:src,/btn_save_continue/).flash
$ie.button(:src,/btn_save_continue/).click
both didnt worked…..
Željko Filipin said,
December 20, 2006 at 4:52 pm
Hi Balaji,
Try this
ie.image(:src, /btn_save_continue/).click
I see that you have asked that question also at Watir forum, and I have already answered there.
Meena said,
January 5, 2007 at 9:16 am
Will the flash event works for checkboxes,radio buttons and text boxes?
Meena said,
January 5, 2007 at 9:39 am
Balaji,
Instead of giving like this
$ie.button(:src,/btn_save_continue/).click
Try “ie.show_images” this will show all the images in the website.
Take the entire path of the image within double codes and apply the same in your code.This will work for sure.
Format:
ie.show_images
ie.image(:src, “https://…. images/agent/btn_save_continue.gif”).click
Željko Filipin said,
January 5, 2007 at 10:13 am
Meena,
Yes, flash works for all elements.
Meena said,
January 5, 2007 at 10:41 am
Željko Filipin,
What’s the syntax for using flash in checkbox, radio buttons and text boxes.
Željko Filipin said,
January 5, 2007 at 11:32 am
Meena,
ie.checkbox(:how, what).flash
ie.radio(:how, what).flash
ie.text_field(:how, what).flash
Take a look at WATIR User Guide (http://www.openqa.org/watir/watir_user_guide.html), search for flash.
Anonymous said,
January 23, 2007 at 1:04 pm
Is it possible to make a Watir code repeat the same task n number of times?
For ex. repeat opening a website and click on a link n number of times.
If so, how?
Željko Filipin said,
January 23, 2007 at 2:27 pm
I do not want to discourage anybody from posting comments, but Watir related questions will probably get answered quicker at Watir mailing list (http://rubyforge.org/mailman/listinfo/wtr-general or http://forums.openqa.org/forum.jspa?forumID=5). I am monitoring that list, and I will answer your question there if I know the answer.
That said, to answer your question (in the next comment).
Željko Filipin said,
January 23, 2007 at 2:38 pm
If you have a page that has a link that points to itself, like this
<a href=”page.htm”>text</a>
you can click that link five time with this
require ‘watir’
ie = Watir::IE.start(”app.com”)
n = 5
for i in 1..n
ie.link(:text, “text”).click
end
Anonymous said,
February 1, 2007 at 9:12 am
Filipin,
To use ie.refresh(), do we include any package as such?
If so, could you tell the package with a sample code?
Željko Filipin said,
February 1, 2007 at 10:23 am
Anonymous,
I am not sure if I understood your question. You do not have to require any other file (except watir.rb, of course) to use ie.refresh.
Claudio Perrone said,
March 20, 2007 at 12:17 am
Hi Željko,
FYI, to click that link 5 times you may consider ditching the for loop and using the more elegant:
5.times do
ie.link(:text, “text”).click
end
Anonymous said,
May 18, 2007 at 9:34 am
Hi Željko,
Is it possible to do a text search using watir code?
For ex: I have a website. I want to search for a particular word “customer” in that page and if possible the no of occurances of that word.
If it is possible, can u guide me how to do that?
Željko Filipin said,
May 18, 2007 at 10:23 am
Anonymous,
Of course it is possible. It is Ruby feature, not Watir, but you probably do not care.
# put page text to variable t
t = ie.text
=> “customer text customer”
# the counter
i=0
=> 0
# increase i when you find “customer”
t.gsub(”customer”) {i+=1}
=> “1 text 2″
# It works!
i
=> 2
If you post this question at Watir forum somebody may have a better solution.
Željko Filipin’s Blog on Software Testing » Tests and How-To Documents (2) said,
October 12, 2007 at 3:25 pm
[...] I have already written about Tests and How-To Documents. [...]
Pavel said,
April 10, 2008 at 11:12 pm
have to admit very usefull comments. thank you, Željko!