Professional Documents
Culture Documents
Repairing Selenium Test Cases: An Industrial Case Study About Web Page Element Localization
Repairing Selenium Test Cases: An Industrial Case Study About Web Page Element Localization
Abstract—This poster presents an industrial case study about used to model the web pages involved in the test process as
test automation and test suite maintenance in the context of objects, employing the same programming language used to
Web applications. The Web application under test is a Learning write the test cases. In this way, the functionalities offered
Content Management System (eXact learning LCMS). We
analysed the costs associated with the realignment of four by a web page become “services” (i.e., methods) offered
equivalent Selenium WebDriver test suites, implemented using by the corresponding page object and can be easily called
the page object pattern and different methods to locate web within any test case. Thus, all the details of the web page
page elements, to a subsequent release of eXact learning LCMS. are encapsulated inside the page object. This allows the test
In our study, the two ID-based test suites required significantly developer to work on a higher level of abstraction and helps
less maintenance effort than the XPath-based ones.
to reduce the coupling between test cases and web pages.
Keywords-Web Application Testing, Test Automation, Sele-
nium WebDriver, Test Suite Maintainability. II. T HE C ASE S TUDY
Time (Minutes)
WAUT - Release N+1 24
22
Username: 20
Password: Test’ 18
16
Login Now! 14
12
10
driver.findElement(By.linkText("Login")).click();
8
6
driver.findElement(By.linkText("Login Now!")).click(); 4
2
Figure 1. “Login” link changes in “Login Now!” ⇒ Realignment required 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Test Cases
page objects, we have 131 web page element localization
Figure 2. Time of test cases realignment
lines (i.e., the point in the code where a page object calls
the driver to find a web page element). Each test case of of the time required for realigning the test cases is similar
our test suite for eXact learning LCMS is composed by for all the four test suites (high for the first test cases and low
several actions such as: navigating a web page, clicking a for the subsequent ones, see the regression curves in Fig. 2).
link, filling a form and finally, evaluating a set of assertions. The first test cases required more time to be realigned than
They were implemented using conditional statements, loops, the subsequent ones since the page object pattern has been
logging functionality and exception handling; all of them are adopted. Indeed, to realign the first test cases of each test
parameterized (a.k.a. data-driven) test cases. When the test suite (e.g., test cases 1, 2, 3 and 4), we modified the page
suite is executed, 336 test case instances are run (each test objects they use. But, these modifications were also useful
cases is parameterized) in about 3,5 hours. for the subsequent test cases (e.g., 5, 6, and 7), thus they
Research Question: we compared the four test suites trying required less time to be realigned.
to answer to the following RQ: Which is the more effec- The answer to our research question can be easily deduced
tive localization method among “search by ID”, “search by Fig. 3 that shows some comparative data about the four
by XPath”, “search by ID+LinkText” and “search by implemented test suites: ID-based test suites have required
XPath+LinkText” for reducing the effort to realign a test the lowest maintenance effort, while the XPath-based test
suite when a new version of the WAUT is created?. In suites have required a higher effort (about 4 times more for
other words, we are interested to determine whether one what concerns the time and 10 times more for the number
(or more) of the proposed methods for locating web page of LOCs to modify). In both cases the combined use of ID
elements is clearly better than the other ones. We measured and XPath with LinkText has slightly improved the results.
Time Code
the realignment effort in terms of time (minutes) and number Test Suites Minutes Difference LOCs Difference
of LOCs to change for all the four considered test suites. ID 43 9
ID+LinkText 36 - 16 % 8 - 11 %
XPath 183 + 326 % 96 + 967 %
III. S UMMARY OF THE R ESULTS XPath+LinkText 135 + 214 % 86 + 856 %
As a first step, we ran the four test suites against the new Figure 3. Effort required using different Web Page localization methods.
The difference is computed considering ID as baseline
release of eXact learning LCMS (M10), observing that all
the 25 test cases composing the four test suites failed. Then, IV. C ONCLUSION
we realigned each test case composing the test suites (see The main result of our case study is that, from the point of
the example in Fig. 1), noting down the time required for view of realignment effort, ID-based methods for locating
repairing it and recording the number of LOCs modified. web page elements are better than XPath methods. These
During the realignment, we discovered that the changes results are not conclusive, but this work compares for the
made in eXact learning LCMS (M10) did not affect the logic first time in a real industrial context, four Selenium test
of the test cases. For this reason, we modified only the page suites built using different methods for locating web page
objects to realign the four test suites (more precisely, we elements.
modified only a subset of the 131 localization lines). R EFERENCES
Fig. 2 shows, by means of a scatter-plot, the time required
[1] S. Berner, R. Weber, and R. Keller. Observations and lessons
to realign the test cases belonging to the four test suites to learned from automated testing. In Proc. of ICSE 2005, pages
the new release of eXact learning LCMS3 . It is evident that 571–579. IEEE, 2005.
the time spent for realigning XPath-based test cases goes [2] B. Haugset and G. Hanssen. Automated acceptance testing:
beyond the time for realigning the ID-based ones in almost A literature review and an industrial case study. In Proc. of
all the cases. Moreover, it is interesting to note that the trend AGILE 2008, pages 27–38. IEEE, 2008.
[3] M. Leotta, D. Clerissi, F. Ricca, and C. Spadaro. Improving
3 The four regression curves have been computed using the distance- test suites maintainability with the page object pattern: An
weighted least squares method. industrial case study. In Proc. of ICSTW 2013. IEEE, 2013.
488