AMOfunctions

From MozillaWiki
Jump to: navigation, search

The AMOfunctions module contains functions related to elements on AMO pages.

Contents

Constants

data formats

  • RE_LONG_DATE - regular expression for a long date, ex: January 12, 2000.
  • RE_MMDDYYYY - regular expression for a date of the format mm/dd/yyyy.
  • STRF_LONG_DATE - formator for strptime to parse text into datetime object.
  • RE_COUNT - regular expression for a count including zero.
  • RE_NON_ZERO_COUNT - regular expression for a count greater that zero.

regular expressions for specific fields

  • WEEKLY_DOWNLOADS_PATTERN - a count followed by "weekly downloads". numeric part in a regex group
  • UPDATED_LONG_DATE_PATTERN - a long date preceded by "updated". date part is in a regex group.

All AMO Pages - Layout

verifyPageHeader_Quick(appName, sel)

Verifies the existence of high level elements in any page header.

  • appName - the application expected in teh page header
  • sel - current selenium instance
  • returns a list of exceptions, or a null list if no errors

Checks for the presence of various high level elements, such as title and auxillary-navigation menu. A separate exception is returned for each missing element.

verifyPageFooter_Quick(sel)

Verifies the existence of high level elements in any page footer.

  • sel - current selenium instance
  • returns null list if no problems, otherwise returns a list of exceptions as strings

A separate exception is returned for each missing element.

pageTitlePattern(part1Name, appName)

returns the regular expression pattern for a page title

  • part1Name - the page name (ex: category name, add-on name) in the first segment.
  • appName - the application name

The pattern has an anchor at the beginning. If part1Name is not null the pattern has two segments separated by the delimiter '::'. if part1Name is null the pattern has only the appName segment.

pageBreadcrumb1Pattern(appName)

returns the pattern for a single breadcrumb

  • appName - application name in the breadcrumb

regular express has an anchor at the beginning and the end, which verifies the entire breadcrumb string.

pageBreadcrumb2Pattern(appName, catName)

returns the pattern for a two breadcrumb pattern

  • appName - application name in the first breadcrumb
  • catName - name in the second breadrumb

regular expression has an anchor at the beginning and the end, which verifies the entire breadcrumb string. The pattern expectesthe delimiter '>' between the breadcrumbs

All AMO Pages - Actions

login(userType, sel)

logon to an AMO user.

  • userType - a user from the list of userType defined in configurationAMO
  • sel - current selenium instance
  • returns functionPass if login was successful, otherwise returns an error message in a string .

Function first checks if a user is logged-in. If yes then it logs out that user and logs-in this new user. Uses the links in the page header to initiate log out (if required) and log in.

logout(sel)

Logs out of the current user

  • sel - current selenium instance
  • returns functionPass if log out was successful, other returns an error as a string.

Logs out of the current user using the Log out link in the page header. Success is defined as the presence of the Log in link.

gotoAppHomePage(appName, sel)

Open the home page of a Mozilla application

  • appName - application to open it's home page
  • sel - current selenium instance
  • returns null string if home page for appName is launched, other returns error message in a string

Based on the current page:

  • if already on the appName home page it does nothing
  • if on any other appName page, as per the URL, it will click on the home page link in the page header
  • if on a page in another application it will select from the Other Applications menu on the page header the link for appName

submitPageHeaderSearchPanelQuery(resultsItemLocator, noResultsMsgLocator, sel, queryValues):

submit a search using the page header search panel

  • resultsItemLocator - locator of first item in search results.
  • noResultsMsgLocators - locator of 'no results' message, in place of search results
  • sel - current selenium instance.
  • queryValues - parameter names with values for fields in search panel. The following parameters are recogized by the function:
    • queryText - text typed into query form search value
    • categoryOption - option locator to select category element, such as 'index=1'
    • sortOption - option locator to select category element, such as 'value=weeklydownloads'
    • see selenium API documentation for more infomation on select() and option locators.
  • Returns:
  • null string if at least one search result exists, determined by is_element_present(resultsItemLocator)
  • the 'No results' message, as returned by get_text(noResultsMsgLocator)
  • an error message regarding an element that was not found.

Note that the results themselves are not returned. Examining the results is left to the script after the function returns.

  • Usage:
    • the first three parameters are required and positional.
    • the query value parameters are optional. They are supplied by as individual paremeters in the normal 'paramName=paramValue' format.
    • the *Option parameter values are used as-is. Any desired option locator used by the selenium select() function, such as 'value=', must be included in the parameter value.
  • Example
    • submitPageHeaderSearchPanelQuery(resultsItem_Loc, noResultsMsg_Loc, sel, queryText='abc', categoryOption='value=all' )
    • The string 'abc' is entered in the search text field
    • The category with the value attribute of 'all' is selected.
    • the locator resultsItem_Loc is used to determine if any search results were determined
    • the locator noResultsMsg_Loc is used to retrieve a message from the page if the search returned no results.

Cross-category type - Layout

userURLpattern()

Return the pattern of a URL to a user profile

Pattern contains user ID enclosed in a regexp groups, allowing the user ID to be parsed out using this pattern in re.findall() or similar function.

isUserURL(userURL)

Verifies that a string matches the pattern of a user profile URL

  • userURL - string to verify.
  • Returns True if userURL matches the pattern of a user profile URL as defined by userURLpattern(), otherwise False

verifyUserLink(userLinkLoc, sel)

Verify the link for a user

  • userLinkLoc - locator for the link to a user profile. assumed to end with <a> tag
  • sel - selenium instance
  • Returns a list of exceptions as strings, or empty list if no errors

Checks done:

  • checks the format of the URL matches the pattern for user links
  • the link is visible, as determined by selenium.is_visible()

verifyAuthorLink(authorLoc, authorLinkLoc, sel)

Verify an author's text and link.

  • authorLoc - locator to the text in the author node including the 'created by' text
  • authorLinkLoc - locator for the author profile link. assumed to end with <a> tag
  • sel - selenium instance
  • Returns a list of exceptions as strings, or empty list if no errors.

Calls verifyUserLink() and also checks:

  • checks the text of the author element includes 'by' or 'created by'

getAdminFeaturedAddonsList(appName, featureType, sel)

Return a subset of add-ons listed in Admin Control Panel Category Features

  • appName - Mozilla application name which must match a value used in the admin list. Current values include Firefox, Thunderbird, Sunbird
  • featureType - category type which must match a value used in the admin list. Current values include extensions, themes, personas.
  • sel - selenium instance
  • Returns a dictionary of dictionaries of add-ons in the Admin list qualified by appName and featureType. The top-level dictionary is keyed by the category name that's in the list. Each category is a dictionary with entries keyed by addon ID and containing add-on name.

Note: The function logs on as an admin user to build the list and logs out when finished.

Application Home Pages - Layout

appHomePageURLpattern(appName)

Return the pattern for an application's home page

  • appName - Mozilla application name to include in pattern

Add-ons Pages - Layout

addonURLpattern()

Returns the pattern of a URL for an add-on page.

Pattern encloses addon ID segment in a regex group, allowing the pattern to parse the addon ID from the URL with re.findall() or similar function.

addonURLwithAppPattern(appName)

Returns the pattern of a URL for an add-on page.

  • appName - Mozilla application name to include in the pattern

Pattern encloses addon ID segment in a regex group, allowing the pattern to parse the addon ID from the URL with re.findall() or similar function.

isAddonURL(addonURL)

Tests if a string matches the pattern of an add-on URL

  • addonURL - string to verify.
  • Returns True if string matches the pattern of an add-on page URL, otherwise returns False. Pattern is generated by addonURLpattern().

isAddonURLwithApp(addonURL, appName)

Tests if a string matches the pattern of an add-on URL

  • addonURL - string to verify.
  • appName - Mozilla application name included in the URL pattern .
  • Returns True if string matches the pattern of an add-on page URL, otherwise returns False. Pattern is generated by addonURLwithAppPattern().

getAddonIdFromURL(addonURL)

Return add-on id segment from URL.

  • addonURL - string to extract add-on ID from. string is assumed to be an URL to an add-on page.
  • Returns the add-on ID segment from URL, or if URL doesn't match pattern for addon URL

verifyAddonLink(addonLinkLoc, sel)

Verify the link to an add-on page

  • addonLinkLoc - locator for the link. assumed to end with <a> tag
  • sel - selenium instance
  • Returns a list of exceptions as strings, or empty list if no errors.

Checks done:

  • the format of the URL matches the pattern for links to an add-on page
  • the link is visible, as determined by selenium.is_visible()

verifyAddonLinkWithApp(addonLinkLoc, appName, sel)

Verify the link to an add-on page.

  • addonLinkLoc - locator for the link. assumed to end with <a> tag
  • appName - Mozilla application name to include in URL pattern
  • sel - selenium instance

Checks done:

  • the format of the URL matches the pattern for links to an add-on page
  • the link is visible, as determined by selenium.is_visible()

verifyContributeElement(contributeLoc, contributeLinkLoc, appName, addonId, sel)

Verify Contribute bar element on an add-on

  • contributeLoc - locator of contribute/support bar containing text
  • contributeLinkLoc - locator of link within Contribute element for contributing
  • appName - application to include in URL checks
  • addonId - addonId to include in URL check
  • sel - selenium instance
  • Returns a list a exceptions as strings, or empty list if no errors

Checks done:

  • element text contains 'contribute' or 'support'. Text is retrieve3d using the locator contributeLoc
  • URL contains expected pattern for a Contribute element which includes addon ID and appName
  • link is visible, as determined by selenium.is_visible()

verifyStarsRatingAttributes(ratingLocator, notRatedMsgLocator, sel)

Verify that the star ratings sub-elements are in agreement

  • ratingLocator - locator to element containing the rating class and title.
  • nnotRatedMsgLocator - locator to 'not rated yet' message, if it exists
  • sel - is the selenium instance

Returns a list of exceptions as strings, otherwise a null list. Checks:

  • element text is either "not yet rated" or "rated x of 5 stars", and not both.
  • the element text and title are the same.
  • the class name corresponds to the stars rating.

is_rating_sort_descending(ratingStars, reviewCount, prevRatingStars, prevReviewCount)

Compare 'current' and 'previous' ratings, returns True if they are in descending order

  • ratingStars - stars rating of 'current' add-on
  • reviewCount - review count of 'current' add-on
  • prevRatingStars - stars rating of 'previous' add-on
  • prevReviewCount - review count of 'previous' add-on
  • all parameters are assumed to be integers
  • returns True when
    • ratingStars < prevRatingStars, or
    • ratingStars are equal and reviewCount <= prevReviewCount,
  • otherwise it returns an error message as a string

getRatingStarsFromInfo(infoText)

Returns # of stars in rating from text

  • infoText - text searched for the string of the format 'rated # of 5 stars'
  • returns the tuple (returnResult, starsCount) where returnResult is a string and starsCount is an integer
    • if stars count is successfully found and is between 0-5 the function returns null string and the count.
    • if the count is not found and the text 'not yet rated' is found the function returns null string and 0.
    • if the function fails to find the expected text it returns an error message and -1.

getReviewsCountFromInfo(infoText)

Returns reviews count from text

  • infoText - text search for string of the format '# reviews'
  • return the tuple (returnResult, reviewsCount) where resturnResult is a string and reviewsCount is an integer
    • if reviews count is successfully found and converted to an integer the function returns null string and the count.
    • if the count is not found and the text 'not yet rated' is found the function returns null string and 0.
    • if the function fails to find the expected text or cannot convert the number it returns an error message and -1.

getWeeklyDownloadsFromInfo(infoText)

Returns weekly downloads count from add-on info text.

  • infoText - text from "add-on info" element.
  • Returns the tuple ( returnResult, downloadCount )

Function searches for a sequence of integers preceding the string "weekly downloads". If found the returned tuple is a null string and the number converted to an integer. If the function cannot find or convert the integer the returned tuple is an error message string and -1.

getUpdatedLongDateFromInfo(infoText)

Searches add-on info text for the updated date in long format

  • infoText - text from "add-on info" element.
  • Returns the tuple ( returnResult, updatedDate )

Function searches for a date in a long format, for example January 1, 2000, preceded by the string "updated". If found the returned tuple is a null string and the date converted to a datetime data type. If not found the returned tuple is an error message string and the value datetime.min (January 1, 0001)

Add-ons Pages - Actions

goToAddOn(appIndex, nameIndex, sel)

goToAddOnByAddOnId(appName, addOnId, sel)

getRandomAddon(appName, sel)

Gets a add-on from one of the 5 add-ons listed on the recommended list on the homepage. Returns an array containing add-on name & add-on Id.

getRandomAddonVersion2(appName, sel)

Gets a add-on from one of the 5 add-ons listed on the recommended list on the homepage. Returns a dictionary containing add-on name & add-on Id.

postReview(appIndex, nameIndex, reviewTitle, reviewRating, reviewBody, sel)

addTag(tagText, sel)

Adds a search tag to the addon

Collections Pages - Layouts

collectionsHomePagePattern(appName)

return the pattern for a collections home page

  • appName - Mozilla application name to include in URL

collectionURLpattern(appName)

return the pattern of a URL for a collection

  • appName - Mozilla application name to include in URL

isCollectionURL(collectionURL, appName)

tests that a string is a URL to a collection page

  • addonURL - string to verify
  • appName - application to include in the URL pattern
  • Returns True if collectionURL matches the pattern of a collection in the appName application, otherwise False

getCollectionVotes(votesBarometerLocator, sel)

Return the Up and Down votes for a collection

  • votesBarometerLocator - locator to a vote barometer ending with <div class='barometer'>.
  • sel - selenium instance
  • Returns the tuple ( exceptions, up_votes, down_votes )

Locators for vote counts are constructed by appending partial locators from the AMOlocators.Collections.VotesElements class onto votesBarometerLocator. The returned tuple is:

  • exceptions - a list of error messages as string if elements could not be found or values could not be converted to integers
  • up_votes - the 'value' attribute converted to an integer from the upvotes element. Or, -1 if conversion fails, or element or attribute cannot be found.
  • down_votes - the 'value' attribute converted to an integer from the downvotes element. Or, -1 if conversion fails, or element or attribute cannot be found.

verifyVotesBarometer(votesBarometerLocator, sel)

Verify that the votes and bars elements in the votes barometer are in agreement

  • votesBarometerLocator - locator to a vote barometer ending with <div class='barometer'>.
  • sel - selenium instance
  • Returns the tuple ( exceptions, up_votes, down_votes ), the same as getCollectionVotes() function.

Locators for vote counts are constructed by appending partial locators from the AMOlocators.Collections.VotesElements class onto votesBarometerLocator.
In addition to the checks performed in getCollectionVotes():

  • the bars between between the vote counts are verified to be in proportion to the up and down votes values.
  • the presence of the 'no votes' message is checked. an error message is returned if it and votes counts are present, or if neither are present.