AJAX testing in iTest2

Posted by Zhimin Zhan on December 29, 2009|
Comments

Web 2.0 sites such as GMail grow rapidly, which brings big challenges to web test automation. Different from traditional web sites with “synchronous request/response model”, new web sites handle requests asynchronously using AJAX. For example, in GMail, clicking ‘Send’ button does not land you on ‘Email Sent’ page, instead you see a ‘Sending…’ banner appears and replaced with ‘Email sent successfully’ later. The difficulty of testing AJAX web sites are not knowing when the request is processed and verify dynamic updated page contents.

The approach used iTest2 is simple, after AJAX call, keep trying next operation with specific time. During that time frame, operation error will be ignored (and try again after interval),

    button(:value,"Transfer").click
    # try up to 10 seconds, waiting receipt date 'showing up'
    try(10) { label_with_id("date").should == today }

    # try up to 60 seconds every 10 seconds.
    try (60, 10) { click_button('Next') }

To assert specific HTML element is shown or hidden

    assert_hidden(:div, "info")  # <div id='info'>...</div> is hidden
    assert_visible(:div, "info")

To assert specific HTMl element is added or removed in a web page


assert_exists(“label”, “email_sent”) #

blog comments powered by Disqus