[aida] Testing Ajaxified Aida Apps with Selenium

Herbert König herbertkoenig at gmx.net
Mon Jul 23 16:02:46 CEST 2012

Am 23.07.2012 12:15, schrieb Janko Mivšek:

Hi Janko,

yes I think we don't want selenium because it is a lot of manual work 
each time one changes the site. I use it anyway because it helps a lot 
but I don't want to write a second selenium script.

So a question:

is there something like a Web client in Swazoo?

Because I've dusted off my recording of HTTP requests and responses and 
can save them to disk.  I'm hesitant to just fire the recorded requests 
at Aida from within the image.  I want to fire them from a second image 
and compare the responses to the recorded HTTP responses.

Squeak has a WebClient package but using that wouldn't be portable.



> Hi Herbert,
> It seems that Selenium has a problem because ids of elementes inside
> updated element are changing and it lost the 'thread'. Specially WebGrid
> filter field, they are recreated with new ids after each search, because
> a whole grid is updated.
> How to put the  filter row outside the whole grid is the question. It
> will namely be desirable not to update filters, but they are part of a
> whole grid table which column widths are automatically adjusted at every
> update ..
> Best regards
> Janko
> Dne 13. 07. 2012 20:58, piše Herbert König:
>> Hi Janko, Robert,
>> JM> 3. Selenium is quite popular testing tool among Smalltalkers too, maybe
>> JM> it is an opportunity to build a support (or at least write a small
>> JM> tutorial) for Selenium testing Aida apps?
>> testing AIDA apps using a lot of Ajax is tedious with Selenium. At
>> least compared to my expectations.
>> The easy part:
>> Install Selenium ide from the Selenium website into firefox.
>> Press Crtl Alt S to fire up the Selenium Dialog.
>> Top right press the record button (if it's not already pressed by
>> default).
>> Do your thing in your web application and see the Selenium script fill
>> in their dialogue.
>>     I start via a login (even for guests). This gives every user a
>>     fresh model with its app. In the model I upload some data to have
>>     something to play with. This ensures repeatability compared to
>>     having some data in a database which may be changed over time and
>>     will break your tests. Then I recorded about a quarter of an hour's
>>     work in the app. Mainly browsing the data (which gives the highest
>>     server load), adding some data, modifying some and have the model
>>     do some calculations (the main purpose of the app). Then I download
>>     the modified data.
>> When done press the record button of the Selenium dialog again and
>> save the script via the file menu.
>> Now comes the tedious part:
>> Click on the first line of the script and press the run button. The
>> Selenium website has real good documentation. Logging in, uploading
>> data, clicking all tabs (ViewTabs) on my App works just fine.
>> For all these Selenium recorded a ClickAndWait command because they
>> all refresh the whole page.
>> Clicking on the first element of a WebGrid which Ajax updates half of
>> the page works fine, clicking on the second element of the same
>> WebGrid fails because of "Element not found" error and the script
>> stops. In this case Selenium recorded a Click. So I thought I just
>> replace the Click with ClickAnd wait.. Well no good.
>> My click fires three of Prototypes Ajax.Updater's. You cannot just
>> WaitForElementPresent of the next element you want to click on, you
>> have to WaitForElementPresent of the last element updated by the last
>> Ajax.Updater. I identified these via Firebug. Once you know which
>> element this is Selenium is helpful. You set a breakpoint on the fatal
>> click, run the script to the halt. Then in the web browser right click
>> on the element you want to wait for and select the
>> WaitForElementPresent from the context Menu which inserts the command
>> with the right parameters into the script. Great feature! Other than
>> my first assessment in an earlier post you want your web elements id's
>> created automatically, otherwise your waitForElementPresent will find
>> the old element with the same id and your click will fail again.
>> The next problem arises when entering data into inputs. Mine post to
>> the server on blur. So after each Selenium "Type..." you will have to
>> insert a fireEvent blur command. But the post request fired by the
>> onBlur event has to be processed by the server (usually changing an
>> ivar of the model). Selenium can be faster than that if you type into
>> several input fields and then click a button to change the data. So
>> every now and then you will want to waitForValuePresent to check that
>> the change has been accepted. Also I sometimes focused some elements
>> just to give Aida time to process some requests which have no reply
>> making a change in the browser. Al in all Selenium is very helpful
>> just like you expect from a modern IDE just a bit different, but
>> Smalltalkers should be tolerant against being different :-)).
>> So in the course of these my 131 lines script blew up to 500 lines.
>> As selenium saves its script as HTML I just attach it, you can open it
>> in any web browser. Type, Click, ClickAndWait and Open have been
>> recorded by Selenium the rest is from me.
>> Regarding writing a Smalltalk support for Selenium like many lanuages
>> have: IMO we don't want that. You add one element to your page and
>> everything will fail, because all the subsequent id's have changed and
>> you redo the whole script. And running Aida and the browser on a 4
>> core machine Selenium can use around 30% of Aida. So running two or
>> three browsers will fully load Aida. I run Aida on an old machine and
>> the browser(s) on newer machines.
>> What we want for Aida (tell me if this is a stupid idea):
>> In 2009 during the onClickDo:andUpdateMany: discussions here I
>> captured every HTTPRequest and every HTTPResponse of an interaction
>> with my webapp to see if the correct Ajax requests were sent and if
>> they got the correct responses.
>> One would have to save this collection of HTTPRequests and ..Responses
>> (JSON comes to mind) replay the requests to the server and collect all
>> the responses and compare them in whatever meaningful way to the
>> expected responses. This will save us all the manual verification we
>> need to do with Selenium. If the webapp changes just record the next
>> interactive session and be done.
>> Only thing I don't know is how to setup a Swazoo client to resend the
>> requests and collect the responses.
>> Janko, if you find anything useful in this, edit it and put it on Aida
>> site.
>> Cheers,
>> Herbert                            mailto:herbertkoenig at gmx.net
>> _______________________________________________
>> Aida mailing list
>> Aida at aidaweb.si
>> http://lists.aidaweb.si/mailman/listinfo/aida

More information about the Aida mailing list