Wednesday, November 30, 2005

“Let the River Run through It”

The first concern we encountered using WATIR was handling modals and pop-ups. I personally spent at least a week trying to figure this issue out. I posted to the users group and read every archived enter on the subject. Nothing seemed to click for my two brain cells.

I tossed the baton over to our crackerjack developers. In a very short period of time we had the modal concern fixed using Winclicker. I had tried this approach, but apparently I was not setting up the Winclicker method in the correct scope.

Here is the syntax we now use to handle modals.

This is a typical modal for our application:









Here is the Winclicker set up method:

def startClicker( button , waitTime = 3)
w = WinClicker.new
longName = @ie.dir.gsub("/" , "\\" )
shortName = w.getShortFileName(longName)
c = "start rubyw #{shortName }\\watir\\clickJSDialog.rb #{button } #{ waitTime} "
puts "Starting #{c}"
w.winsystem(c)
w=nil
#assert_same(expected, actual, [message] ) #Expects expected.equal?(actual)
end

The real key to making this successful is the Winclicker call needs to be made prior to activating the link that leads to the modal.

Like this:

startClicker("OK" , 3)

@ie.link(:text, "Logout").click

Another important note is the value about, which indicates the amount of wait time. The wait time can be very important if there are several modals in a series of events. Timing is everything and you have to work to get WATIR to flow through the modals.

The second hurdle was pop-up utilities. Again the development team lent there expertise and we are able to get the attach method functional. The attach method using a second thread to control the pop-up.

One important thing to note is that when working over a VPN connection the attach method does not seem to work. This is the case for our VPN connection. The script will stop on any attach method over VPN, but runs fine when executed from the office. I have no clue as to why this is the case, but I find it frustrating.

After clicking on the link that exposes a pop-up utility, using the attach method you can then manipulate the data on the pop-up utility.

Example syntax:

@ie.link(:text, "ADD NEW...").click

@ie.link(:text, "CONNECTION").click

ie2 = IE.attach(:title, "Connection")

ie2.selectBox( :name , "connPort1").select("port 1")

ie2.image(:src , /ps_transferto_button/).click

ie2.selectBox( :name , "connPort2").select("port 0")

ie2.selectBox( :name , "connSitesAvailable2").select("002-TX-DAL")

ie2.link(:url, /connSitesAvailable2/).click

All of the input I received from the WATIR community is that there is room for improvement in the mechanisms for handling modals and pop-ups using WATIR, but for now I am running through the application.

One other side note is that supposedly an add-on to WATIR called WET does a better job handling modals and pop-ups. We were not able to get WET to work, but I am sure with more effort this would be an alternative solution.

After overcoming these challenges we have been able to successfully write approximately 80 test scripts, providing 23% automation of our current test cases.

No comments: