QA/Execution/Web Testing/Docs/Automation/StyleGuide: Difference between revisions

Jump to navigation Jump to search
added page region
(added page region)
Line 94: Line 94:
     def report_length(length)
     def report_length(length)
</pre>
</pre>
== Advanced: Page Regions ==
In some circumstances, for example where a header/navigation is common across the website, we will use a page region. The page region is a child class of the base Page Object, which is inherited by all page objects. This means that the navigation can be reached from any page object and herein lies the DRY!
A brief example:
<pre class="brush:py;toolbar:false;">
class BasePage(Page):
    @property
    def header(self):
        return BasePage.HeaderRegion(self.testsetup)
   
    class HeaderRegion(Page):
        _login_link = (By.ID, "home")
        @def click_login(self):
            self.selenium.find_element(*self._login_link).click()
</pre>
Referring to this page region with a property makes it very readable and concise from within the test. Clicking home during a test would be performed like this:
<pre class="brush:py;toolbar:false;">
    page_obj.header.click_login()
</pre>
Another example where this might be used is on a search results page, the page region being the search results element.


= Tests =
= Tests =
Confirmed users
137

edits

Navigation menu