QA/Execution/Web Testing/Docs/Automation/Testcases/AMO POM Overview: Difference between revisions

(Created page with "= <span style="font-weight: bold;">Overview</span> = As suggested by the name Page Object Model, methods and static values specific to web pages is organized by the web page. F...")
 
 
Line 1: Line 1:
= <span style="font-weight: bold;">Overview</span>  =
= <span style="font-weight: bold;">Overview</span>  =


As suggested by the name Page Object Model, methods and static values specific to web pages is organized by the web page. For example, getting the number of themes displayed in the header of a themes landing page might include code that looks similar to this:<br>
As suggested by the name, the Page Object Model organizes class methods and static values around individual web pages. The following snippet of code gets the theme count that's displayed in the header of the themes landing page:  
<pre># Create objects for the AMO home page and themes landing page
<pre># Create objects for the AMO home page and themes landing page
amo_home = AmoHomePage.amo_home_page(self.selenium)  
amo_home = AmoHomePage.amo_home_page(self.selenium)  
Line 13: Line 13:
...
...
# Get the themes count from the page header
# Get the themes count from the page header
themes_count = themes_landing.get_themes_count_from_header_as_integer()&lt;span style="font-family: sans-serif;" /&gt;</pre>  
themes_count = themes_landing.get_themes_count_from_header_as_integer()
The ''amo_home'' object has methods related to the AMO home page.&nbsp; Similarly ''themes_landing'' has methods related to the themes landing page.<br>  
</pre>  
The ''amo_home'' object, an instance of the AMO&nbsp;home page class, has methods related to that page.&nbsp; Similarly ''themes_landing'' object, an instance of the themes landing page class, has methods for the themes landing page.<br>  


''open_base_page''( ) calls selenium.open("/"), which opens the base page set in the selenium instance.<br>  
''open_base_page''( ) calls selenium.open("/"), which opens the base page set in the selenium instance.<br>  


''go_to_themes_landing''( ) clicks on the link to the themes landing page.&nbsp;&nbsp;It checks that the themes landing page opened successfully using a method from the ''themes_landing'' parameter.&nbsp; If the themes landing page was not opened an exception is thrown.  
''go_to_themes_landing''( ) clicks on the link to the themes landing page.&nbsp; The method is called with the AMO home page object since that is the current page.&nbsp; ''go_to_themes_landing( )'' checks that the themes landing page opened successfully using a method in the themes landing page class, which is passed via the ''themes_landing'' parameter.&nbsp; If the themes landing page was not opened an exception is thrown.  


''get_themes_count_from_header_as_integer''( ) returns the add-on count, as an integer, found in the header.&nbsp; If a count cannot be returned it throws an exception. Errors could include the element not being present, the expected accompanying text not found in the element, or the count being a negative number.  
''get_themes_count_from_header_as_integer''( ) returns the add-on count, as an integer, displayed in the header.&nbsp; If a count cannot be returned it throws an exception. Errors could include the element not being present, the expected accompanying text not found in the element, or the count being a negative number.  


=== Getting and verifying data<br>  ===
=== Getting and verifying data<br>  ===


To get data from a page a test case uses a method defined in a page class. - The method may checks the element for any expected text that labels the data. - The data is converted to an appropriate data type (ex: integer, date) - Data range constraints are checked (ex: a "count" is not negative; text matches the standardized pattern)
A test case gets data from a page using methods defined in page classes.  


Page classes might have methods to verify complex elements which contain related attributes or sub-elements to faciliate keeping test case logic simpler by simplying calling verify_element_x.&nbsp; For example, a list of links that are expected to have a common pattern in their URLs; a Star Rating element has multiple attributes which refer to the same 'star count' value.  
*The methods may check that the element has any expected text that labels the data.
*The data is converted to an appropriate data type (ex: integer, date)
*Data range constraints are checked (ex: a "count" is not negative; text matches standard patterns)
 
Page classes might also have methods to verify complex elements which contain related attributes or sub-elements.&nbsp; The methods allow for simpler test case by moving to the page class the code for retrieving elements and attributes, comparing values, and handling exceptions.&nbsp; Elements which may require verification methods could include: a list of links that are expected to have a common pattern in their URLs; a Star Rating element that has multiple attributes which refer to the same 'star count' value.  


Verfication logic in test cases is normally simple comparasions. For example checking items sort order by comparing the values on two items; checking a search page and browse page contain the same information for the same add-on.  
Verfication logic in test cases is normally simple comparasions. For example checking items sort order by comparing the values on two items; checking a search page and browse page contain the same information for the same add-on.  
Line 32: Line 37:
=== <br> '''Exception handling '''<br>  ===
=== <br> '''Exception handling '''<br>  ===


Many methods in page classes have the option to throw an exceptions immediately, or save exceptions for later reporting. Exceptions are thrown immediately by default, unless a SavedExceptions object is passed to the method in which case the the exception is saved as a string in a list.  
Methods that throw exceptions which are informational will typically have the option the save exceptions for later reporting via a SaveExceptions object (see the utilities class page for more information).&nbsp; The default is to throw exceptions immediately.&nbsp; Informational exceptions are found in methods that verify retrieved data, and while they are errors worth reporting, any exceptions would not affect how the test case operates.&nbsp; By contrast, methods that retrieve data or navigate would normally not have an option to save exceptions and therefore always throw an exception.&nbsp; It would be up to the test case to capture any exceptions with a try-except if it wishes to continue when an element is missing or a navigation appears to fail, and save it using ''save_exception(&nbsp;)'' from the SavedExceptions class. <br>


=== <br>'''Page class hierarchy'''  ===
=== '''Page class hierarchy'''  ===


A page class is a child class of the class below it in the table below.&nbsp; Except for the page.Page class, all page classes define methods to get or verify data, and the elements locators within it's scope.
The class for a web page inherits methods and data from parent classes as described in the table below.<br>


{| cellspacing="1" cellpadding="2" border="1" style="width: 646px; height: 87px;"
{| cellspacing="1" cellpadding="2" border="1" style="width: 646px; height: 87px;"
|-
|-
| page class for an individual page<br>  
| width="25%" | page class for an individual page <br>(ex: personas landing page)
| locators and methods for elements unique to the page.
| width="25%" | child class of an add-on type
| width="50%" | locators and methods for elements unique to the page. <br>(ex: get the title for a theme on the page; click on a theme's detail page link)
|-
|-
| page class for an add-on type (ex: personas)<br>
| page class for an add-on type <br>(ex: personas)  
| locators and methods for elements appears on multiple pages for the add-on type. ex:&nbsp;click on a category from the menu.<br>
| child class of AmoPage class
| locators and methods for elements appears on multiple pages for the add-on type. <br>(ex:&nbsp;click on a category from the sidebar menu.)
|-
|-
| amo_page.AmoPage<br>  
| amo_page.AmoPage<br>  
| locators and methods for elements that appear on all AMO&nbsp;pages or that apply to multiple add-on types.&nbsp; ex: page header and footer elements; submitting a search using the query form in the page header.<br>
| child class of Page
| locators and methods for elements that appear on all AMO pages or that apply to multiple add-on types. <br>(ex: page header and footer elements; submitting a search using the query form in the page header)
|-
|-
| page.Page<br>  
| page.Page<br>  
| methods that call selenium APIs.&nbsp; Many call their selenium counterpart by the same name and might add "good practices"&nbsp;logic, like calling wait_for_page_to_load(&nbsp;) after click( )&nbsp;or open( ).<br>
|
| methods that call selenium APIs. Many call their selenium counterpart of the same name and might add "good practices" logic, such as calling wait_for_page_to_load( ) after click( ) or open( ).<br>
|}
|}


<br> <br>
<br> <br>
1,072

edits