Code libraries for AMO pages: Difference between revisions

Line 8: Line 8:
*Changes to web pages which could break many scripts could be resolved by updating the module.  
*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.
*Centralize 'best practices' for locator definition and 'tricks' to address complicated situations.


'''Naming convention of dictionaries'''  
'''Naming convention of dictionaries'''  


...'''_List[ ]''' references elements that appear once on a list, such as headers or sort selectors.  
...'''_List[ ]''' references elements that appear once on a list, such as headers or sort selectors.  
<blockquote>...'''_List['item']''' references the item node on the list ''without'' an index, unlike the _List_Item[ ] locators described below. Could be used with an is_element_present to check if a list contains any items.
 
*Suitable for: get_xpath_count()
*Example: itemCount = sel.get_xpath_count ( AMOlocators.addonBrowsePage''_List['item']'' )
</blockquote>
...'''_List_Item[ ]''' references elements on a particular item in a list. All keys require an index value into the list.  
...'''_List_Item[ ]''' references elements on a particular item in a list. All keys require an index value into the list.  


*Suitable for: get_text(), get_attribute()
*Example 1: addonName = get_text( addonBrowsePage_''List_Item['name']''&nbsp;% idx ) retrieves the text for the name on the ''idx''-th add-on in the list.
*Example 2: addonHref = sel.get_attribute ( AMOlocator.addonCategoryLandingPage_TopRated''List_Item['link']''&nbsp;% idx + "@href" ) retrieves the href attribute in the link for the idx-th item on the Top Rated list on the add-on category landing page.
<blockquote>...'''_List_Item['item']''' references an item node on the list using an index. </blockquote>
<br>'''Locators that require an index value'''


Some locators require an index and must be followed by ''% value'' where ''value'' is the index required for them item in the list, such as add-ons in a list or options in a select.


Locators that require an index are named as followed:  
'''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 item in a list, such as add-ons in a list or options in a select.
 
Locators that require an index are named as follows:  


*all locators in the ..._List_Item[ ] dictionaries.  
*all locators in the ..._List_Item[ ] dictionaries.  
Line 35: Line 31:
Locators&nbsp;include the tag type at the end of the key for controls that have an action . For example: detailLink, sortSelect. Keys for static elements may use the tag type to reference a specific element, such as PreviewImg.  
Locators&nbsp;include the tag type at the end of the key for controls that have an action . For example: detailLink, sortSelect. Keys for static elements may use 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 high level node.<br>
Dictionary keys that don't end with a tag type generally refer to a section of text or a higher level node.<br>  


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


*element with the item name.<br>
*Dictionaries that reference a list use this key for an entire item (i.e. add-on).<br>
**_List['item'] refers tp the item node on the list without an index.&nbsp; Could be used with an is_element_present to check if a list contains any items.
<blockquote>
*Suitable for: get_xpath_count( )
*Example: itemCount = sel.get_xpath_count ( AMOlocators.addonBrowsePage_List['item'] )
</blockquote>
**_List_Item['item'] refers to the item node using an index. &nbsp;To access a particular element on the n-th item, generally the mnemonic key for that element is used, rather than appending to this locator.<br>
 
<br>
 
'''name'''<br>
 
*element 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'''] % idx ) retrieves the text for the name on the ''idx''-th add-on in the list on the browse page.


'''*Link'''<br>


*<span style="font-weight: bold;" />Refers to a link. The last element in the locator is an &lt;a&gt;.&nbsp; Key name may be simply ''link ''for an item with only a few elements.&nbsp; Key name may be prefixed with the link destination or the element containing the link.  
 
'''*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.  
*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.  
*Suitable for sel.get_attribute for href or other attribute in the &lt;a&gt; node.<br>
*Suitable for sel.get_attribute for href or other attribute in the &lt;a&gt; node.<br>  
*Example 2: sel.get_attribute( AMOlocator.addonCategoryLandingPage_TopRatedList['ViewAllLink'] +&nbsp;"@href" ) retrieve the href attribute from the View All link of the Top Rated list on the category landing page.<br>
*Example 2: sel.get_attribute( AMOlocator.addonCategoryLandingPage_TopRatedList['ViewAllLink'] +&nbsp;"@href" ) retrieves the href attribute from the View All link of the Top Rated list on the category landing page.<br>
 
 


<span style="font-weight: bold;">*</span>'''Select'''<br>
<span style="font-weight: bold;">*</span>'''Select'''<br>  


*efers to select controls. The last node in the locator is a &lt;select&gt;.  
*Refers to 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.
*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>
 
 


*'''Option''' <br>
'''*Option''' <br>


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

edits