/Selenium_Documentation

Page 97

Selenium Documentation, Release 1.0

You might consider trying the UI-Element extension in this situation. http://wiki.openqa.org/display/SIDE/Contributed+Extensions+and+Formats#ContributedExtensionsandFormatsUIElementLocator

7.4.3 Performance Considerations for Locators 7.4.4 Custom Locators This section is not yet developed.

7.5 Testing Ajax Applications We introduced the special characteristics of AJAX technology earlier in this chapter. Basically, a page element implemented with Ajax is an element that can be dynamically refreshed without having to refresh the entire page.

7.5.1 Waiting for an Ajax Element For an Ajax element using Selenium’s waitForPageToLoad wouldn’t work since the page is not actually loaded to refresh the Ajax element. Pausing the test execution for a specified period of time is also not good because the web element might appear later than expected leading to invalid test failures (reported failures that aren’t actually failures). A better approach is to wait for a predefined period and then continue execution as soon as the element is found. Consider a page which brings a link (link=ajaxLink) on click of a button on page (without refreshing the page) This could be handled by Selenium using a for loop. // Loop initialization. for (int second = 0;; second++) { // If loop is reached 60 seconds then break the loop. if (second >= 60) break;

// Search for element "link=ajaxLink" and if available then break loop. try { if (selenium.isElementPresent( "link=ajaxLink" )) break; } catch (Exception e) // Pause for 1 second. Thread.sleep(1000); }

This certainly isn’t the only solution. Ajax is a common topic in the user group and we suggest searching previous discussions to see what others have done along with the questions they have posted.

7.6 UI Mapping A UI map is a mechanism that stores Identifiers, or in our case, locators, for an application’s UI elements. The test script then uses the UI Map for locating the elements to be tested. Basically, a UI map is a repository of test script objects that correspond to UI elements of the application being tested. 7.5. Testing Ajax Applications

91


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.