From: Robert Klemme Date: 2006-03-01T00:58:36+09:00 Subject: Re: Using assert() in a loop Toby wrote: > Hello everybody > > I hope this question isn't answered somewhere else, but the search was > disabled so i hope that excuses me. > > I have been introducted to Ruby thorugh the need to write Watir tests > to do functional testing. I have an array of URLs that i wish to > check and a loop to go through them. I use the assert() function to > find out whether a particular link has scrolled to the correct > position. If the test fails (ie assert(false)) ruby breaks out of the > loop and doesn't check the rest of the urls. > > I have added a begin/rescue statement which stops ruby breaking out > the loops but Watir then reports zero failures. > > Code looks like this: > > [code] > def test_href_Exists > > href_start = > "http://localhost/fc_codebase/_web/?urn=com.firstconsult/1/101/1010022" > > link_arr = { > "Description" => "198" > } > > href_addr = [ > "%23ah_70002::th_unused", > "%23ah_70089::th_", > "#ah_70002::th_unused", > "%23ah_70002::", > "#ah_70002::", > "%23ah_70002::", > "#ah_70002::", > "%23ah_70002::t)(*&^%$", > "#ah_70002::t)(*&^%$", > "%23ah_70002::%23tyh_888", > "#ah_70002::#tyh_888", > "%23ah_70567::th_unsed", > "%23ah_70567::th_70002", > "%23ah_70567::th_unused", > "%23ah_unused::th_unused", > "#ah_unused::th_unused", > "#ah_70567::th_", > "%23ah_70567::th_", > "%23ah_70567::th_70002&%", > "#ah_70567::th_70002%%", > ] > > $ie.goto(href_start) > > link_arr.each do |key, value| > href_addr.each do |href_arr_val| > > href_complete = href_start + href_arr_val > $ie.text_field(:name, "id_href").set(href_complete) > $ie.link(:text, key).click > puts $ie.text_field(:name, "id_href").getContents() + " " + > href_arr_val > > begin > > assert(result); > > rescue => e > > puts "*FAILED*." + e.message > end > > end > end > [/code] > > I am fairly sure there is a simple explaination but nothing i have > tried works so far this week. > > Any help would be gratfully recieved Well, the test fails as soon as a single URL fails. That's the reason for the behavior you're seeing. If you want a single error message that lists all failues the way to go is to collect all failures somehow (Array, Hash) and have it fail only if there is at least one error. HTH Kind regards robert