Željko Filipin's Blog on Software and Testing

Test like you do not need the money.

Archive for February, 2007

Testing E-mail: The Code

without comments

Lately I have been testing e-mail functionality of web application. This is the fifth post about that experience. Last week I wrote about lessons learned.

I have written a little framework that helps me with testing e-mail.

To use it, you will have to install Ruby, Tmail and SMTP server.

Then download mail.zip (2,20 KB) and extract it. No installation required. There are even some unit tests (unit_tests.rb) and example code (usage.rb).

Send mail.

SendMail.new(
  "user@domain",
  "application@domain",
  "title",
  "body").send

Check if application sent mail that you have expected.

Mail.received?(
  [Mail.new(
    "application@domain",
    "user@domain",
    "title")])

For now, mail that is sent can only contain from, to, subject and body. While receiving, I only check from, to and subject.

This is code that I am really using every day.

Please understand that I am a tester, not a developer, and I know that this code could be better. Feel free to improve it. Post bug reports and your comments here.

Written by Željko Filipin

February 7th, 2007 at 6:12 pm

Posted in E-mail

Watir: Select Element Using Multiple Attributes

with 2 comments

There are two links in a page that I am testing.

<a href="1">reply</a>
<a href="2">reply</a>

I need to get value of href attribute for the second link.

I can not use :text, because it will return href attribute for the first link.

browser.link(:text, "reply").href
=> "{site}1"

I can use :index, but if anything on that page changes, it could break.

browser.link(:index, 2).href
=> "{site}2"

Bret Pettichord posted posted a solution for this at wtr-general a few months ago.

In 1.5, this syntax works:

browser.div(:name => 'foo', :index => 2).click

This will find the second div with the name ‘foo’.

And it really works.

browser.link(:text => "reply", :index => 2).href
=> "{site}2"

Written by Željko Filipin

February 6th, 2007 at 2:21 pm

Posted in Watir

Tagged with

Watir: Select Element Using HTML

without comments

Bret Pettichord posted this at wtr-general few days ago.

If you have a link that looks like this:

<a href="#" onclick="new Ajax.Request('/data_entry/ajax_add_term/131?contract_id=227', {asynchronous:true, evalScripts:true}); return false;">add a term</a>

you can click it using:

browser.link(:html, /contract_id=227/).click

Written by Željko Filipin

February 1st, 2007 at 11:35 pm

Posted in Watir

Tagged with