QA/Execution/Web Testing/Docs/Automation/Testcases/ConventionsAmoTests: Difference between revisions

(Created page with "= Conventions in AMO test cases = == Element Locators == * Element locators are defined outside of the test case to centralize their definition and simplify test case code. *...")
 
Line 4: Line 4:


* Element locators are defined outside of the test case to centralize their definition and simplify test case code.   
* Element locators are defined outside of the test case to centralize their definition and simplify test case code.   
* Locators may contain %d or %s formatting specifiers to support elements in a list, or a common locator for sibling elements that differ only by a short string.
* Locators may contain %d or %s formatting specifiers to support elements in a list, or a common locator for sibling elements that differ by a short segment.
* Locators are defined in a combination of Xpath and CSS formats.  CSS is the preferred format.
* Locators are defined in a combination of Xpath and CSS formats.  CSS is the preferred format for POM.


=== Locators in Pre-POM test cases ===
=== Locators in Pre-POM test cases ===
Line 12: Line 12:
* Index or option subsitution is done with the % operator.  For example, for the locator to select one of the sort options on the AMO home is:
* Index or option subsitution is done with the % operator.  For example, for the locator to select one of the sort options on the AMO home is:


In AMOlocators a locator is defined for links to sort options on a page (note the %s near the end of the string)


            sortLink_Keyed =
  sortLink_Keyed =
 
    “css=div[class~='featured-inner'] div[class='listing-header'] ul li a[href*='?browse=%s']”
            “css=div[class~='featured-inner'] div[class='listing-header'] ul li a[href*='?browse=%s']”


To click on the ‘popular’ sort option:
To click on the ‘popular’ sort option:


      sort_locator = sortLink_Keyed % ‘popular’
  sort_locator = sortLink_Keyed % ‘popular’
 
  selenium.click(sort_locator)
      selenium.click(sort_locator)


=== Locators in POM test cases ===
=== Locators in POM test cases ===


* Defined in the page classes.  They are defined as strings or a Locator object.   
* Defined in the page classes.  Defined as strings or a Locator object.   
* The POM Locator class is a child class of string which contains methods with_index( ) and with_option( ) for inserting values.  For example:
* The POM Locator class is a child class of string which contains methods with_index( ) and with_option( ) for inserting values.  For example:


In a page class, the locator for items in the themes category list:


  loc = locator.Locator
  theme_category_link =
    loc("css=div[class~='other-categories'] h3:contains('Themes') + ul + ul li:nth-child(%d) > a")


The locator for items in the themes category list:
In a test case, to create a locator for the 2nd category in the list :
 
  loc = locator.Locator
 
  theme_category_link =
 
loc("css=div[class~='other-categories'] h3:contains('Themes') + ul + ul li:nth-child(%d) > a")
 
To create a locator for the 2nd category in the list :
 
        cat_locator = theme_category_link.with_index(2)


* If a list requires an offset to index an element (i.e. the 1st element is accessed by “:nth-child(2)” ) the page class may define an alternate locator class which defines with_index( ) to include the offset.  In the case of the Themes landing page the ThemesLoc class maps a single index into the (row, column) pair the page is implemented in.
  cat_locator = theme_category_link.with_index(2)


If a list requires an offset to index an element (i.e. the 1st element is accessed by “:nth-child(2)” ) the page class may define an alternate locator class which defines with_index( ) to include the offset. 


In the case of the Themes landing page the ThemesLoc class maps a single index into the (row, column) pair the page is implemented in.


== Parameter driven tests ==
== Parameter driven tests ==
1,072

edits