Thanks for the reply, Chris.

On 17/03/06, Chris McMahon <[EMAIL PROTECTED]> wrote:
assert_equal is telling you that your code is yielding a single period
and you told it to expect to find "TEST".  That's how all of the
asserts work.  (Except plain old "assert", which always yields the

Okay, that's what I thought it meant, but I couldn't figure out why that was.  Here's the gory details of how I solved this problem.

The HTML page I'm looking at is very simple.  Other than a menu at the top, there's a split screen layout that is really a table with two columns (no border).  In the Left column is a tree-view of a "node" list, and on the right side is just two description labels that give you some information about the selected/highlighted node on the left.  When you first enter this page, the root level item is selected in the tree and the text labels just show a '.' beside them.

My script *before* looked like this:
---
      $ie.span(:index, 108).click
    
      assert_equal("TEST" , $ie.span(:id, /NodeIdentifierLabel/).text )
     
      $ie.button(:name, /Delete/).click
---

If you use the web app, what is *supposed* to happen is that when you click on an item on the left, the right side is supposed to update and show you the correct information.  You even see the IE browser's 'flag' waving in the upper right hand corner of the screen until the information is displayed.

What seems be happening is that right after the click event, Watir is going right to the next line (the assertion) and not waiting for IE to finish retrieving and displaying the information. (unexpected)

I tested this theory by inserting a 'flash' line between the first two:
      $ie.span(:id, /NodeIdentifierLabel/).flash

This *showed* me that right after the click event, the script immediately checked the text label on the right hand side without waiting for the browser to update the page.

Okay, so I need to tell my script to wait a few seconds (however long it takes actually) until the page is refreshed, so I inserted the following sleep command:
---
      $ie.span(:index, 108).click
     
      sleep 1 until $ie.span(:id, /NodeIdentifierLabel/).text != '.'
     
      $ie.span(:id, /NodeIdentifierLabel/).flash
     
      assert_equal("TEST" , $ie.span(:id, /NodeIdentifierLabel/).text )
     
      $ie.button(:name, /Delete/).click
---

NOW, the 'flash' line shows me that the label correctly shows "TEST" and everything proceeds as expected.

So I *was* using the assert_equal command correctly, I just wasn't expecting the script to continue without waiting for the page to finish updating.

I've got these "sleep" lines scattered throughout my scripts because of pages like this.  I haven't been able to figure out the pattern yet, but the scripts seem to be randomly going faster than the web application is returning control to the UI.

 

Pickaxe v.2 has a nice section on unit testing with test/unit along
with all of the forms of 'assert' available.

Good to know.  I'll try to pick this book up soon.  The online version of v.1 is handy, but I really need some of these updates now.

Cheers.  Paul.

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to