Code libraries for AMO pages: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 49: Line 49:
*Could use with is_element_present to check if a list contains any items.<br>
*Could use with is_element_present to check if a list contains any items.<br>
</blockquote>  
</blockquote>  
*
*<br>
*..._List_Item['item'] refers to the item node with an index. &nbsp;To access a particular element on the n-th item, the mnemonic key for that element is generally used rather than appending to this locator.<br>
*..._List_Item['item'] refers to the item node with an index. &nbsp;To access a particular element on the n-th item, the mnemonic key for that element is generally used rather than appending to this locator.<br>


'''name'''<br>  
'''name'''<br>  


*element with the item name.<br>  
*Locator to a node with the item name.<br>  
*Suitable for sel.get_text(&nbsp;)<br>  
*Suitable for sel.get_text(&nbsp;)<br>  
*Example: addonName = get_text( addonBrowsePage_List_Item['''name''']&nbsp;% idx ) retrieves the text for the name on the ''idx''-th add-on in the list on the browse page.<br>
*Example: addonName = get_text( addonBrowsePage_List_Item['''name''']&nbsp;% idx ) retrieves the text for the name on the ''idx''-th add-on in the list on the browse page.<br>
Line 60: Line 60:
'''*Link'''<br>  
'''*Link'''<br>  


*Refers to a link. The last element in the locator is an &lt;a&gt;.&nbsp; Key name may simply be ''link ''for an item with only a few elements, or may be prefixed with the link destination or the element containing the link.  
*Locator for a link. The last element in the locator is an &lt;a&gt;.&nbsp; Key name may simply be ''link ''for an item with only a few elements, or may be prefixed with the link destination or the element containing the link.  
*Suitable for sel.click( )  
*Suitable for sel.click( )  
*Example: sel.click( AMOlocator.addonBrowsePage_List_Item['detail''Link''']&nbsp;% idx ) clicks on the detail page link for the idx-th add-on listed in the browse page.  
*Example: sel.click( AMOlocator.addonBrowsePage_List_Item['detail''Link''']&nbsp;% idx ) clicks on the detail page link for the idx-th add-on listed in the browse page.  
Line 68: Line 68:
<span style="font-weight: bold;">*</span>'''Select'''<br>  
<span style="font-weight: bold;">*</span>'''Select'''<br>  


*Refers to a select control. The last node in the locator is a &lt;select&gt;.  
*Locator for a select control. The last node in the locator is a &lt;select&gt;.  
*Suitable for sel.select( )  
*Suitable for sel.select( )  
*Example: sel.select( AMO_locators.addonsSearchResults['sortSelect'], 'value=' + sortOption) selects from the add-ons search results page the sort option with the 'value' attribute specified by sortOption.<br>
*Example: sel.select( AMO_locators.addonsSearchResults['sortSelect'], 'value=' + sortOption) selects from the add-ons search results page the sort option with the 'value' attribute specified by sortOption.<br>
Line 74: Line 74:
'''*Option''' <br>  
'''*Option''' <br>  


*Refers to options in a select control. The last node in the locator is an &lt;option&gt;.
*Locator to an option in a select control. The last node in the locator is an &lt;option&gt;.


and many more
'''starsRating'''
 
*Locator to the node containing the rating (i.e. "4 out of 5 stars")&nbsp;elements.
 
and many more  


<br>
<br>

Revision as of 03:21, 15 March 2010

AMOlocators

The module groups locators into dictionaries named for a page or a list. The keys into the dictionares are mnemonics for the element it locates.

Benefits:

  • Provide scripts writers a quick reference for time-consuming process of establishing a working locator.
  • Changes to web pages which could break many scripts could be resolved by updating the module.
  • Centralize 'best practices' for locator definition and 'tricks' to address complicated situations.


Naming convention of dictionaries

..._List[ ] references elements that appear once on a list, such as headers or sort selectors.

..._List_Item[ ] references elements on a particular item in a list. All keys require an index value into the list.

Example:

  • addonCategoryLandingPage_RecentList['title'] is a locator to the title of the Recent list on the add-on category landing page
  • addonCategoryLandingPage_RecentList_Item['name'] is a locator to the name on an add-on to the same list


Locators that require an index value

Some locators require an index and must be followed by " % value" (where value is a numeric index) in order to select an entry from a list, such as add-ons in a list or options in a select.

  • Example: addonName = get_text( addonBrowsePage_List_Item[name] % AddonIdx ) retrieves the text for the name for the item # specified by AddonIdx.  The list is on the add-on browse page.

Locators that require an index are:

  • all locators in the ..._List_Item[ ] dictionaries.
  • dictionary keys that end in Indexed.


Naming conventions for element locators and dictionary keys

Locators for controls that have an action will include the tag type at the end of the key. For example: detailLink, sortSelect. Keys for static elements may include the tag type to reference a specific element, such as PreviewImg.

Dictionary keys that don't end with a tag type generally refer to a section of text or a higher level node.

item

  • Dictionaries that reference a list use this key for an entire item (i.e. add-on).
  • ..._List['item'] refers to the item node on the list without an index. 
  • Suitable for: get_xpath_count( )
  • Example: itemCount = sel.get_xpath_count ( AMOlocators.addonBrowsePage_List['item'] )
  • Could use with is_element_present to check if a list contains any items.

  • ..._List_Item['item'] refers to the item node with an index.  To access a particular element on the n-th item, the mnemonic key for that element is generally used rather than appending to this locator.

name

  • Locator to a node with the item name.
  • Suitable for sel.get_text( )
  • Example: addonName = get_text( addonBrowsePage_List_Item[name] % idx ) retrieves the text for the name on the idx-th add-on in the list on the browse page.

*Link

  • Locator for a link. The last element in the locator is an <a>.  Key name may simply be link for an item with only a few elements, or may be prefixed with the link destination or the element containing the link.
  • Suitable for sel.click( )
  • Example: sel.click( AMOlocator.addonBrowsePage_List_Item['detailLink'] % idx ) clicks on the detail page link for the idx-th add-on listed in the browse page.
  • Suitable for sel.get_attribute for href or other attribute in the <a> node.
  • Example 2: sel.get_attribute( AMOlocator.addonCategoryLandingPage_TopRatedList['ViewAllLink'] + "@href" ) retrieves the href attribute from the View All link of the Top Rated list on the category landing page.

*Select

  • Locator for a select control. The last node in the locator is a <select>.
  • Suitable for sel.select( )
  • Example: sel.select( AMO_locators.addonsSearchResults['sortSelect'], 'value=' + sortOption) selects from the add-ons search results page the sort option with the 'value' attribute specified by sortOption.

*Option

  • Locator to an option in a select control. The last node in the locator is an <option>.

starsRating

  • Locator to the node containing the rating (i.e. "4 out of 5 stars") elements.

and many more


AMOfunctions

This is intended as a summary of functions. Refer to the in-line function doc regarding parameters and other information.

login - login to a generic user. The parameter is mnenomic for the user type.

submitHeaderSearch - supplies data to the search panel in the AMO header and submits the search. Only the selenium instance (sel) parameter is required, and other parameter are named and optional. The script does not return the search results, rather it returns one of three strings: null string - at least one item was returned in the search results based on locators defined in AMOlocators. itself. 'no results' - the 'No Result Found' message was returned, based on locators defined in AMOlocators 'unexpected layout' - neither of the above conditions were detected using is_element_present( ) and locators for search results page.


getAdminFeaturedList - returns a dictionary of featured items from the admin control panel. Items are qualified by the application and feature type (ex: extensions, persona) specified by the parameters. The parameter values are the corresponding values found in the admin featured items list. See the in-line function doc for more information on the structure of the dictionary that is returned.

isUserURL - returns True if the parameter is the format of a user profile URL, otherwise False.

getAddonIdFromURL - returns the add-on id segment of a URL for an add-on

userURLpattern - returns the pattern for a user profile URL. defined as a function to allow more extendability.

userURLpatternGroup - returns the pattern for a user profile URL with id in a grouping to allow parsing URL id. defined as a function.

isAddonURL - returns True if the parameter is the format of a add-on URL, otherwise False.

addonURLpattern - returns the pattern for a add-on URL. defined as a function to allow more extendability.

addonURLpatternGroup - returns the pattern for a add-on URL with id in a grouping to allow parsing add-on id. defined as a function.

verifyStarsRating - confirms the stars rating elements are in agreement within the locator specified by the parameter. returns a list of strings describing the exceptions found, or an empty list if no exceptions are found.