1. Kostya Marchenko
  2. Test Automation Framework

Source

Test Automation Framework / test-automation-framework / target / test-results / com / sqanta / testautomation / framework / pages / PageDefinition.html

<?xml version="1.0" encoding="UTF-8"?><html xmlns:c="http://www.concordion.org/2007/concordion">

<head><script type="text/javascript">
function show(id) {
  document.getElementById(id).style.visibility = 'visible';
}

function hide(id) {
  document.getElementById(id).style.visibility = 'hidden';
}
function showScreenshotOn(e) {
  var targ;
  if (!e) var e = window.event;
  if (e.target) targ = e.target
  else if (e.srcElement) targ = e.srcElement
  if (targ.nodeType == 3) // defeat Safari bug
    targ = targ.parentNode;
  if (targ.nodeName == 'P')
    targ = targ.parentNode;
  return (targ.className.indexOf('stackTrace') != 0);
}</script><style>
.screenshot {
  position:absolute;
  visibility:hidden;
  border:solid 1px black;
  z-index:30;
}
</style><style>* {
  font-family: Arial;
}
body {
  padding: 32px;  
}
pre {
  padding: 6px 28px 6px 28px;
  background-color: #E8EEF7;
}
pre, pre *, code, code *, kbd {
  font-family: Courier New, Courier;
  font-size: 10pt;
}
h1, h1 * {
  font-size: 24pt;	
}
p, td, th, li, .breadcrumbs {
  font-size: 10pt;
}
p, li {
  line-height: 140%;
}
table {
  border-collapse: collapse;
  empty-cells: show;
  margin: 8px 0px 8px 0px;
}
th, td {
  border: 1px solid black;
  padding: 3px;
}
td {
  background-color: white;
  vertical-align: top;
}
th {
  background-color: #C3D9FF;
}
li {
  margin-top: 6px;
  margin-bottom: 6px; 
}


.example {
  padding: 2px 12px 6px 12px;
  border: 1px solid #C3D9FF;
  margin: 6px 0px 28px 0px;
  background-color: #F5F9FD;
}
.example h3 {
  margin-top: 8px;
  margin-bottom: 8px;
  font-size: 12pt;
}

p.success {
  padding: 2px;
}
.success, .success * {
  background-color: #afa !important;
}
.success pre {
  background-color: #bbffbb;
}
.failure, .failure * {
  background-color: #ffb0b0;
  padding: 1px;
}
.failure .expected {
  text-decoration: line-through;
  color: #bb5050;
}
.ignored, .ignored * {
  background-color: #f0f0f0 !important;	
}

ins {
  text-decoration: none;	
}

.exceptionMessage {
  background-color: #fdd;
  font-family: Courier New, Courier, Monospace;
  font-size: 10pt;
  display: block;
  font-weight: normal;
  padding: 4px;
  text-decoration: none !important;
}
.stackTrace, .stackTrace * {
  font-weight: normal;
}
.stackTrace {
  display: none;
  padding: 1px 4px 4px 4px;
  background-color: #fdd;
  border-top: 1px dotted black;
}
.stackTraceExceptionMessage {
  display: block;
  font-family: Courier New, Courier, Monospace;
  font-size: 8pt;
  white-space: wrap;
  padding: 1px 0px 1px 0px;
}
.stackTraceEntry {
  white-space: nowrap;
  font-family: Courier New, Courier, Monospace;
  display: block;
  font-size: 8pt;
  padding: 1px 0px 1px 32px;
}
.stackTraceButton {
  font-size: 8pt;
  margin: 2px 8px 2px 0px;
  font-weight: normal;
  font-family: Arial;
}

.special {
  font-style: italic;
}
.missing, .missing * {
  background-color: #ff9999;
}
.surplus, .surplus * {
  background-color: #ff9999;
}
.footer {
  text-align: right;
  margin-top: 40px;
  font-size: 8pt;
  width: 100%;
  color: #999;
}
.footer .testTime {
  padding: 2px 10px 0px 0px;
}

.idea {
  font-size: 9pt;
  color: #888;
  font-style: italic;	
}
.tight li {
  margin-top: 1px;
  margin-bottom: 1px; 
}
.commentary {
  float: right;
  width: 200px;
  background-color: #ffffd0;
  padding:8px;
  border: 3px solid #eeeeb0;	 
  margin: 10px 0px 10px 10px;	 
}
.commentary, .commentary * {
  font-size: 8pt;
}
</style>
    <title>Page Definition</title>
    <link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>

<body><span class="breadcrumbs"><a href="../Framework.html">Framework</a> &gt; <a href="Pages.html">Page Objects</a> &gt;</span>
<h1>Page Definition</h1>

<p>
    One of the key challenges when implementing automated testing is cost of test maintenance and test brittleness.
    When testing web applications page layout and position of elements can change frequently and so it should be easy to
    reflect those changes in automated tests.
</p>

<p>
    To minimize this problem and make it easier to reflect layout changes each page class has associated Page Definition
    file. Page Definition file should be placed in the same package as page class in resource folder, should have
    exactly the same name as class name and should be of Java properties format (*.properties).
</p>

<div class="example">
    <p>
        <b>When</b> page with correct page definition file instantiated<br />
        <b>Then</b> page definition loaded
        <span c:assertTrue="testPageDefinitionLoadedForCorrectPage()" class="success">correctly</span>
    </p>

    <p>
        <b>When</b> page with incorrect page definition file trying to instantiate<br />
        <b>Then</b> <span c:assertTrue="testExceptionThrownForPageWithoutDefinition(#TEXT)" class="success">InstantiationError</span> is thrown
    </p>
</div>

<p>
    Page Definition file has mandatory page properties:
</p>
<ul>
    <li><b>URL</b> — page URL by which page can be accessed. If page can't be accessed directly by URL it should
        have empty value.
    </li>
    <li><b>Title</b> — page title. Used by page verification methods to check that correct page is opened.</li>
</ul>

<div class="example">
    <p>
        <b>When</b> page definition missing mandatory properties<br />
        <b>Then</b> <span c:assertTrue="testMandatoryPropertiesCheck(#TEXT)" class="success">InstantiationError</span> is thrown
    </p>
</div>

<p>
    Page Definition contains information about page elements location and has<br />
    <code>getElementLocator(String elementName)</code>
    method to retrieve locator for specified page element.
    Element location data should be stored in format
    <code>elementName = locatorType~LocatorValue</code> where locatorType is not case sensitive and can be:
</p>

<ul>
    <li><b c:assertTrue="testIdLocator()" class="success">id</b> — element should be found using element ID</li>
    <li><b c:assertTrue="testNameLocator()" class="success">name</b> — element should be found using element name</li>
    <li><b c:assertTrue="testXpathLocator()" class="success">xpath</b> — element should be found using
        <a href="http://en.wikipedia.org/wiki/XPath">XPath</a></li>
    <li><b c:assertTrue="testCSSLocator()" class="success">css</b> — element should be found using
        <a href="http://www.w3.org/TR/CSS2/selector.html">CSS Selector</a></li>
    <li>
        <b c:assertTrue="testTagNameLocator()" class="success">tagName</b> — element should be found by it's HTML tag name, e.g. "h1", "a", "p"
    </li>
    <li><b c:assertTrue="testLinkTextLocator()" class="success">linkText</b> — link should be found by it's text value</li>
    <li>
        <b c:assertTrue="testPartialLinkTextLocator()" class="success">partialLinkText</b> — link should be found by it's partial text value
    </li>


</ul>
<p>Locator types are ordered according to their speed in finding elements on page from quickest to slowest.</p>

<p>
    If element locator is incorrect or element definition is missing
    <span c:assertTrue="testExceptionThrownForIncorrectLocator(#TEXT)" class="success">IllegalArgumentException</span> will be thrown.
</p>


<p>When actual page layout changes then only page definition file needs to be be updated and no need to modify page
    or test itself.
</p>

<h3>Code examples</h3>

<p>
    All pages that extend BasePage will automatically get access to loaded <code>pageDefinition</code> object.<br />
    Pages that do not extend BasePage but implement Page interface can access page definition by creating instance of
    <code>PageDefinition</code> class.
</p>

<p>
    <code>getElementLocator(String elementName)</code> method is available for all pages inherited from BasePage or can be used directly from
    <code>PageDefinition</code> object.
</p>


<p>
    See <code>PageDefinition</code> class javadoc for more usage examples.
</p>

<h3>Further Information</h3>

<p>
    You can read more about locator strategies in
    <a href="http://release.seleniumhq.org/selenium-core/0.8.0/reference.html">official Selenium documentation</a> or in
    <a href="http://saucelabs.com/docs/quickstart#locators">Sauce Labs Quick Start Guide</a>.
    <br />
    Also take a look at
    <a href="http://saucelabs.com/blog/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/">intriguing post</a> with comparison of locator strategies performance.
</p>
<div class="footer">Results generated by <a href="http://www.concordion.org"><img src="../../../../../image/concordion-logo.png" alt="Concordion" border="0" /></a><div class="testTime">in 111 ms on 21-Sep-2011 at 14:29:10 MSD</div></div></body>
</html>