1. Kostya Marchenko
  2. Test Automation Framework

Source

Test Automation Framework / test-automation-framework / target / test-results / com / sqanta / testautomation / framework / pages / Pages.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 Objects</title>
    <link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>

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

<p>
    To make tests easier to write, easier to understand and cheaper to maintain tests should be written using OOP
    principles, should operate with decoupled objects which incapsulate behaviour and use Domain-Specific Language
    (DSL). PageObject concept is simple yet very powerful way to write tests that examine page- or screen-based systems
    like web applications.
</p>

<p>
    Each page or screen of System Under Test (SUT) is represented as separate class and each method of that class
    provide an interface for the service which real page implements.
</p>

<div class="example">
    <h3>Example</h3>

    <p>
        Consider real web application like Google Search Engine. It has number of pages such as Search page, Search
        Results page and others.
    </p>


    <img src="PageObjects.png" alt="PageObjects" />

    <p>
        SearchPage.java is a class which represents Google Search page and it has methods:
    </p>
    <ul>
        <li><code>searchWeb(String query)</code> — method will check that Web search is enabled, will
            populate search field with search query and press Search button
        </li>
        <li><code>searchImages(query)</code> — similar to searchWeb method but will switch to image search
            mode first
        </li>
        <li><code>navigate() —</code> method inherited from BasePage, will open Google Search page in the
            browser
        </li>
        <li><code>verify()</code> — method inherited from BasePage, will verify that Google Search page is
            currently opened
        </li>
    </ul>

    <p>
        As you may noticed pages in SUT share common elements, in this example it's top menu. To avoid duplication
        of logic in page objects common elements can be defined as separate classes: both SearchPage and
        SearchResultsPage are children of BaseGooglePage and BaseGooglePage contain an instance of GoogleMenu. So
        menu logic is extracted in separate class and provides methods:
    </p>
    <ul>
        <li><code>switchToWeb()</code> — enables web search</li>
        <li><code>switchToImage()</code> — enables image search</li>
        <li>...</li>
    </ul>
    <p>
        Those methods are available in all classes that are children of BaseGooglePage or if they have instance of
        GoogleMenu page module.
    </p>

    <p>
        Reusable page modules can extend
        <code>BasePageModule</code> class which provides some basic functionality like access to page module definition and WebDriver object.
    </p>

    <p>
        SearchResultsPage class inherits both <code>navigate()</code> and <code>verify()</code> methods from
        BasePage. However <code>navigate()</code> method without parameters doesn't make much sense for that page as
        it's impossible to navigate to that page directly. So <code>navigate()</code> method is marked as deprecated and
        <code>navigate(String query)</code> method is defined which allows to navigate to Search Results page for given
        query directly.
    </p>


</div>

<h3>Further Information</h3>
<ul>
    <li><a href="BasePage.html">Base Page</a> provides number of useful methods and makes it easier to work with Page
        Objects
    </li>
    <li>Page Objects are created by <a href="PageFactory.html">Page Factory</a></li>
    <li>Information about page, it's layout and location of elements is defined in <a href="PageDefinition.html">Page
        Definition</a> files
    </li>
    <li>In <b>automated-tests</b> module you can find real working examples of a tests that use features of test
        automation framework
    </li>
</ul>


<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 11 ms on 21-Sep-2011 at 14:29:20 MSD</div></div></body>
</html>