As the others have indicated you need to pass the values into the
method, and then do the equivalency test once you are inside.
I defined something like this to do validations for some of my early
scripts where I didn't like using assert or should because they would
stop, and I wanted to run the other checks in that section. I also
defaulted the expected value to 'true' so I could call it with
something that just returned true or false (like .exists?) for the
actual value, which is also why the parameters are in that order.
Mine looked like this (it's using the HTML reporting class from the
examples on the wiki, to which I added a blocked status.. I really
ought to update that example)
def validate(test_title, actual_value, expected_value=true)
if actual_value == expected_value
$results.addtoReport($testReport, test_title, 'PASSED', Found: #
{actual_value})
true
else
$results.addtoReport($testReport, test_title, 'FAILED', Expected:
#{expected_value} Found: #{actual_value})
false
end
end #end of validate function
Here's some examples of how I was using it.
# Is there a Login Button?
unless validate('Page contains Login Button', $browser.button(:id,
'Login').exists?)
$login_page_broken = true #checked by other scenarios that need
login to be working in order to run.
end
# Is there a link for first time users? is it correct?
if validate('Page contains link for first time users',
$browser.link(:id, 'LoginVerification').exists?)
validate('First-time user link has correct url', $browser.link
(:id, 'LoginVerification').href, $ESS_SITE + '/LoginVerification.aspx?
type=LoginVerification')
else
$results.addtoReport($testReport, 'Link for first time users is
correct', 'BLOCKED', 'Cannot Validate, Link not present')
end
Note that I've abandoned this approach for now, and am heading in the
direction of using Watir, + Watircraft framework + Cucumber which I
view as a lot better use of my time than trying to create my own
framework.
Now if we can just enhance things to support the idea of a 'qa mode'
where it will keep going and complete all the 'THEN/AND/AND...'
actions even if one .should fails, so I can report all the test
criteria's status. I suspect that's something I might have to talk to
the Rspec/Cucumber people about however.. Developers want stuff like
this to stop at the first failure (it means they have work to do), but
for QA folks that's bad because it 'masks' the results of following
items that I want to be able to report status on without having to
create atomic level scenarios.
On Apr 7, 10:10 pm, Wesley Chen cjq@gmail.com wrote:
Hi, All,
Suppose I would like to write a method like.
def test(boolean, message)
if boolean
puts message
else
puts boolean.left_value
puts boolean.right_value
end
end
Sometimes, I have to invoke the methods like:
test(arra.include?(arrb), arra includes arrb)
test(arra.eql?(arrb), arra equals to arrb)
When the boolean is not true, I would like to get the info why they don't
match/equal/include.
Any suggestion would be quite appreciated.
Thanks.
Wesley Chen.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Watir General group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines:
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---