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

no edit summary
No edit summary
No edit summary
 
Line 43: Line 43:
'''with_option'''( ''option'' )<br>'''with_index'''( ''element_index'' )<br>Inserts a value into a locator using the&nbsp;% operator (e.g string&nbsp;% option). Both methods operate the same.&nbsp;&nbsp;Both are defined to offer better method name when passing an index# vs. an option value. If a locator requires multiple insertions (e.g an indexed element on an item that's in a listing) a tuple that corresponds to the locator's format can be passed to either method.<br> <br>'''is_css_locator'''( )<br>Returns True if begins like a CSS locator, with "css=", otherwise returns False<br> <br>'''is_xpath_locator'''( )<br>Returns True if begins like a Xpath locator, with "/", otherwise returns False  
'''with_option'''( ''option'' )<br>'''with_index'''( ''element_index'' )<br>Inserts a value into a locator using the&nbsp;% operator (e.g string&nbsp;% option). Both methods operate the same.&nbsp;&nbsp;Both are defined to offer better method name when passing an index# vs. an option value. If a locator requires multiple insertions (e.g an indexed element on an item that's in a listing) a tuple that corresponds to the locator's format can be passed to either method.<br> <br>'''is_css_locator'''( )<br>Returns True if begins like a CSS locator, with "css=", otherwise returns False<br> <br>'''is_xpath_locator'''( )<br>Returns True if begins like a Xpath locator, with "/", otherwise returns False  


== <br>SavedExceptions ==
== <br>SavedExceptions ==


The SavedExceptions class provides a holder for exceptions whenever accumulating exceptions is preferred over ending a test case after an exception.  
The SavedExceptions class provides a holder for exceptions whenever accumulating exceptions is preferred over ending a test case after an exception.  


<br>
<br>  


'''ATTRIBUTES'''&nbsp;<br>
'''ATTRIBUTES'''&nbsp;<br>  


'''exceptions_saved''' - a list exceptions, stored as strings. New exceptions are appended to the end of the list. Each string is potentially the concatenation of three parts: 1) the exception title, 2)&nbsp;exception detail, 2)&nbsp;breadcrumbs trail. Only the exception title is essential when an exception is saved <br>'''exceptions_saved_count''' - a dictionary of counts of the exception titles.&nbsp; The attribute is explained further in the save_exception method<br>
'''exceptions_saved''' - a list exceptions, stored as strings. New exceptions are appended to the end of the list. Each string is potentially the concatenation of three parts: 1) the exception title, 2)&nbsp;exception detail, 2)&nbsp;breadcrumbs trail. Only the exception title is essential when an exception is saved <br>'''exceptions_saved_count''' - a dictionary of counts of the exception titles.&nbsp; The attribute is explained further in the save_exception method<br>  


'''breadcrumbs''' - A TestCaseBreadcrumbs data type to simplfy including a breadcrumb trail with saved exceptions. See the TestCaseBreadcrumbs class for methods. <br>
'''breadcrumbs''' - A TestCaseBreadcrumbs data type to simplfy including a breadcrumb trail with saved exceptions. See the TestCaseBreadcrumbs class for methods. <br>  


'''has_exceptions''' - True if exceptions_saved is not null, False if it's a null list.  
'''has_exceptions''' - True if exceptions_saved is not null, False if it's a null list.  


<br>
<br>  


'''METHODS'''
'''METHODS'''  


'''save_exception'''( ''ex_base, ex_detail''&nbsp; )<br>Parameters<br>''ex_base'': First part of string that's the appended to ''exceptions_saved''. It is also the key for the ''exceptions_saved_counts'' entry which is incremented by 1 by the method. Typically the value is a short generic description such as "element X not found" or "element X on pages A and B are different".  
'''save_exception'''( ''ex_base, ex_detail''&nbsp; )<br>Parameters<br>''ex_base'': First part of string that's the appended to ''exceptions_saved''. It is also the key for the ''exceptions_saved_counts'' entry which is incremented by 1 by the method. Typically the value is a short generic description such as "element X not found" or "element X on pages A and B are different".  


''ex_detail'': The second part of the exception which provides more specifics about the error. It may include the locator for a missing element, or the values and/or regular expression of a failed comparason.&nbsp; Although it is a required parameter it may be null. It is expected to be a string or a data type with a string representation. <br>
''ex_detail'': The second part of the exception which provides more specifics about the error. It may include the locator for a missing element, or the values and/or regular expression of a failed comparason.&nbsp; Although it is a required parameter it may be null. It is expected to be a string or a data type with a string representation. <br>  


''include_breadcrumbs'' (optional): If True, the default, the breadcrumbs attribute are included as the third part of the exception string. If False or or the breadcrumbs list is empty then nothing is added for the third part.  
''include_breadcrumbs'' (optional): If True, the default, the breadcrumbs attribute are included as the third part of the exception string. If False or or the breadcrumbs list is empty then nothing is added for the third part.  


<br>


'''print_exceptions_to_stderr'''( ''test_case_name'' )<br>Parameter


'''print_exceptions_to_stderr'''( ''test_case_name'' )<br>Parameter
''test_case_name'': normally the test case's __name__ attribute  
 
''test_case_name'': normally the test case's __name__ attribute


Prints the saved exceptions to the stderr channel.&nbsp; The primary steps are:<br>
Prints the saved exceptions to the stderr channel.&nbsp; The primary steps are:<br>  


#Print "test case:" followed by ''test_case_name'' parameter
#Print "test case:" followed by ''test_case_name'' parameter  
#Prints the ''exceptions_saved_count'' dictionary entries using the format of the numeric value is followed by the key value (e.g. ''ex_base'' parameter in save_exception( )).&nbsp; The entries are not printed in any particular order.
#Prints the ''exceptions_saved_count'' dictionary entries using the format of the numeric value is followed by the key value (e.g. ''ex_base'' parameter in save_exception( )).&nbsp; The entries are not printed in any particular order.  
#Prints then entries in the exceptions_saved in the order they appear in the list.
#Prints then entries in the exceptions_saved in the order they appear in the list.  
#Raises an exception.
#Raises an exception.


If the exceptions_saved list is empty the methods print the message "no exceptions saved" and skips steps 2-4.  
If the exceptions_saved list is empty the methods print the message "no exceptions saved" and skips steps 2-4.  


<br>
<br>
== DataFunctions - Data Manipulation  ==
Functions for searching text and converting to other data types.
'''ATTRIBUTES'''
Regular expressions for recurring data <br> '''RE_LONG_DATE''': Regular expression that matches a long date, ex: "January 1, 1999"<br> '''RE_MMDDYYYY''': Regular expression that matches a mm/dd/yyyy date<br> '''RE_COUNT''': Regular expression that matches a positive number or 0, optionally with commas<br> '''RE_NON_ZERO_COUNT''': Regular expression that matches a positive number, optionally with commas<br> '''RE_RATING_STARS_PATTERN''': Regular expression that matches standardized rating text "rated # out of 5 stars"<br> '''RE_PAGE_RESULTS_NUMBERS''': Regular expression that matches "# - # of #"<br>
Other constant values<br> '''STRF_LONG_DATE''': Formator for date.strptime to parse text into a date object<br>
<br>
<br>
'''METHODS'''<br>
'''combos_from_lists'''(''lists'' ) <br> Returns a list of all combinations of values from input ''lists''. Each combination in the list returned is a list. Parameters: <br> ''lists'': list of lists, such as parameter options lists from TCparams <br>
'''clean_non_ascii'''( ''text'' ) <br> Return ''text'' with special characters converted to plain ascii. Non-printable characters are replaced with #&lt;num&gt;; where &lt;num&gt; is their character code.&nbsp; New-line characters are replaced with the literal "\n". <br>
'''encode_for_url'''( ''text, encoding_method, chars_to_replace'' ) <br> Returns a string replacing any characters that considered "special"&nbsp;for a URL. <br> Parameters: <br> ''text'': string to convert <br> ''encoding_method'': how characters are replaced. Recognized values are: <br>
*"HEX_CODE" (default) replaces each special character with its hex code value in the format&nbsp;%dd where 'dd' are digits <br>
*"DASH" replaces each sequence of special characters with a '-'.&nbsp; <br>
*"UNDERSCORE" replaces each sequence of special characters with a '_'.&nbsp; It will return "a_b" for the text "a b" or "a &amp; b".<br>
''chars_to_replace'' (optional): string of characters that should be replaced. Overrides pre-defined special characters in the method.<br>
If encoding_method is "DASH" and chars_to_replace include space and "&amp;", the input ''text'' "a b" or "a &amp; b" will return "a-b".&nbsp; Similarly, for the same input value the encoding_method "UNDERSCORE"&nbsp;will return "a_b"<br> <br>
'''text_long_date_to_date'''( ''text'' ) <br> Returns the date, as a date type, found in the ''text''. Expects the text is in long date format (ex: January 1, 2010). Throws an exception if the conversion fails. <br>
'''find_long_date'''( ''text, leadingRegex, trailingRegex'') <br> Returns the string containing the first long date found.<br> Parameters:<br> ''text'': text toe be searched. <br> ''leadingRegex'' (optional): regular expression for text that must immediately proceed the date, if specified.<br> ''trailingRegex ''(optional):regular expression for text that must immediately follow the date, if specified.<br> Any text that matches leadingRegex or trailingRegex is not returned. An exception is thrown if the string match fails.
<br>'''text_to_integer'''( ''text'' ) <br> Convert text to an integer. Thrown an exception if the conversion fails.<br>
'''find_count'''( ''text, leadingRegex, trailingRegex '') <br>
Returns the string containing the first positive integer or 0.<br> Parameters: text: the string to be searched.<br> leadingRegex (optional): regular expression for text that must immediately proceed the count, if specified. trailingRegex (optional): regular expression for text that must immediately follow the count, if specified.
Any text that matches leadingRegex or trailingRegex is not returned. An exception is thrown if the string match fails. <br> '''find_page_results_tuple'''( ''text'' )<br> Returns a string three-tuple of the three values found in ''text'' that are returned by matching the pattern "# - # of #" where # are positive integers or 0. An exception is thrown if the pattern match fails.
1,072

edits