def test_more_info_addon_tags(selenium, base_url, variables): extension = variables['detail_extension_slug'] selenium.get(f'{base_url}/addon/{extension}') addon = Detail(selenium, base_url).wait_for_page_to_load() # get the name of one of the tags related to this addon tag_name = addon.more_info.addon_tags[0].text addon.more_info.addon_tags[0].click() # clicking on the tag opens a search results page with addons that share the same tag same_tag_results = Search(selenium, base_url).wait_for_page_to_load() # verifies that the results URL mention the tag name (encoded) assert f'/tag/{urllib.parse.quote(tag_name)}/' in selenium.current_url count = 0 # checking that the first 5 search results do include the tag of the initial addon while count < 5: try: same_tag_results.result_list.click_search_result(count) # the 'click_search_result' function should already wait for the detail page to load # but I also want to check that the page switch occurred; helps with debugging test failures addon.wait_for_current_url('firefox/addon/') tag_name_from_search = [ el.text for el in addon.more_info.addon_tags ] assert tag_name in tag_name_from_search, f'for {addon.name}' selenium.back() same_tag_results.search_results_list_loaded(5) except IndexError: print('There were less than 5 results matching the selected tag') break count += 1
def test_collection_sort_addons_by_popularity(selenium, base_url, variables): public_collection = variables['public_collection'] selenium.get(f'{base_url}/collections{public_collection}') collection = Collections(selenium, base_url).wait_for_page_to_load() # using the Search class to interact with the list of addons present in the collection addons = Search(selenium, base_url).wait_for_page_to_load() sort = Select(collection.collection_detail.sort_addons) sort.select_by_visible_text('Popularity') # waiting for the new addon sorting to take effect addons.wait_for_page_to_load() # making a record of the list of addons after being sorted frontend_addons_list = [el.name for el in addons.result_list.extensions] # there is no way to directly determine that the sorting is correct in the frontend so we need to # take the api request sent by the frontend and compare the results with the api response request = requests.get(variables['public_collection_popularity'], timeout=10) response = request.json() # first, capture the popularity sorting, which is the 'weekly_downloads` property in the api response popularity = [ result['addon']['weekly_downloads'] for result in response['results'] ] # first, check that the api is returning the addons sorted by weekly downloads in descending order assert popularity == sorted(popularity, reverse=True) # second, capture the list of addon names in the order they are returned by the api api_addon_name_list = [ result['addon']['name']['en-US'] for result in response['results'] ] # finally, make sure that the list of addons from the frontend matches the list of addons returned by the api assert api_addon_name_list == frontend_addons_list
def test_extensions_categories(base_url, selenium, count, category): extensions = Extensions(selenium, base_url).open() # clicking through each Category listed on Extensions homepage extensions.categories.category_list[count].click() category_results = Search(selenium, base_url) # checking that category search results are loaded and sorted by users category_results.wait_for_contextcard_update(category) select = Select(category_results.filter_by_sort) assert 'Most Users' in select.first_selected_option.text
def test_filter_themes(base_url, selenium): page = Home(selenium, base_url).open() term = 'fox' page.search.search_for(term) search_page = Search(selenium, base_url) select = Select(search_page.filter_by_type) select.select_by_value('statictheme') search_page.wait_for_contextcard_update('themes') assert len(search_page.result_list.themes) == 25
def test_themes_categories(base_url, selenium, count, category): themes = Themes(selenium, base_url).open() # clicking through each Theme Category themes.categories.category_list[count].click() category_results = Search(selenium, base_url) # checking that search results within that category are sorted correctly category_results.wait_for_contextcard_update(category) select = Select(category_results.filter_by_sort) assert 'Most Users' in select.first_selected_option.text
def test_theme_categories_shelf(base_url, selenium, count, category): page = Home(selenium, base_url).open().wait_for_page_to_load() # verifying the elements present in the homepage Theme Category shelf assert 'Change the way Firefox looks' in page.theme_category.shelf_summary categories = page.theme_category.list categories[count].category_icon.is_displayed() assert category in categories[count].name # checking that search results within that category are loaded categories[count].click() category_results = Search(selenium, base_url) category_results.wait_for_contextcard_update(category)
def test_collection_sort_addons_by_name(selenium, base_url, variables): public_collection = variables['public_collection'] selenium.get(f'{base_url}/collections{public_collection}') collection = Collections(selenium, base_url).wait_for_page_to_load() # using the Search class to interact with the list of addons present in the collection addons = Search(selenium, base_url).wait_for_page_to_load() sort = Select(collection.collection_detail.sort_addons) sort.select_by_visible_text('Name') # waiting for the new addon sorting to take effect addons.wait_for_page_to_load() addons_list = [el.name for el in addons.result_list.extensions] # check that the addons list has been sorted alphabetically assert addons_list == sorted(addons_list)
def test_filter_promoted(base_url, selenium, sort_attr, title): page = Home(selenium, base_url).open() term = '' page.search.search_for(term) search_page = Search(selenium, base_url) select = Select(search_page.filter_by_badging) select.select_by_value(sort_attr) search_page.wait_for_contextcard_update('results found') results = search_page.result_list.extensions for result in results: assert result.promoted_badge if title != 'Reviewed': assert title.title() in result.promoted_badge_label
def test_home_see_more_recommended_themes(base_url, selenium): page = Home(selenium, base_url).open().wait_for_page_to_load() page.recommended_themes.browse_all() assert "type=statictheme" in selenium.current_url search_page = Search(selenium, base_url) for result in search_page.result_list.themes: assert result.promoted_badge
def test_browse_all_recommended_extensions(base_url, selenium): page = Home(selenium, base_url).open().wait_for_page_to_load() page.recommended_extensions.browse_all() assert 'type=extension' in selenium.current_url search_page = Search(selenium, base_url) for result in search_page.result_list.extensions: assert result.promoted_badge
def test_browse_more_trending_themes(base_url, selenium): themes = Themes(selenium, base_url).open() themes.shelves.trending_addons.browse_all() assert 'sort=hotness&type=statictheme' in selenium.current_url search_results = Search(selenium, base_url) # trending add-ons don't have a predictable order so we # check that search results are displayed for this sort type assert len(search_results.result_list.themes) == 25
def test_home_see_more_popular_themes(base_url, selenium): page = Home(selenium, base_url).open().wait_for_page_to_load() page.popular_themes.browse_all() sort = "users" search_page = Search(selenium, base_url).wait_for_page_to_load() # checking that popular themes results are indeed sorted by users results = [getattr(result, sort) for result in search_page.result_list.themes] assert sorted(results, reverse=True) == results
def test_browse_more_top_rated_themes(base_url, selenium): themes = Themes(selenium, base_url).open() themes.shelves.top_rated_addons.browse_all() assert 'sort=rating&type=statictheme' in selenium.current_url search_results = Search(selenium, base_url) ratings = search_results.result_list.themes for rating in ratings: assert rating.rating >= 4
def user_extensions_results(self): items = self.find_elements(*self._user_extensions_results_locator) return [ Search( self.selenium, self.page.base_url ).SearchResultList.ResultListItems(self, el) for el in items ]
def test_browse_more_recommended_extensions(base_url, selenium): extensions = Extensions(selenium, base_url).open() extensions.shelves.recommended_addons.browse_all() assert 'type=extension' in selenium.current_url search_results = Search(selenium, base_url) select = Select(search_results.filter_by_badging) assert select.first_selected_option.text == 'Recommended' for result in search_results.result_list.extensions: assert 'Recommended' in result.promoted_badge_label
def test_user_profile_open_theme_detail_page(base_url, selenium, variables): artist = variables['theme_artist_profile'] selenium.get(f'{base_url}/user/{artist}') theme = Search(selenium, base_url).wait_for_page_to_load() theme_name = theme.result_list.themes[0].name # clicks on a theme in the user profile page theme_detail = theme.result_list.click_search_result(0) # checks that the expected theme detail page is opened assert theme_name in theme_detail.name
def test_user_profile_open_extension_detail_page(base_url, selenium, variables): page = variables['developer_profile'] selenium.get(f'{base_url}/user/{page}') extension = Search(selenium, base_url).wait_for_page_to_load() extension_name = extension.result_list.extensions[0].name # clicks on an extension in the user profile page detail_extension = extension.result_list.click_search_result(0) # checks that the expected extension detail page is opened assert extension_name in detail_extension.name
def test_filter_by_users(base_url, selenium): Home(selenium, base_url).open() term = 'fox' sort = 'users' selenium.get(f'{base_url}/search/?&q={term}&sort={sort}') search_page = Search(selenium, base_url) results = [ getattr(result, sort) for result in search_page.result_list.extensions ] assert sorted(results, reverse=True) == results
def test_filter_default(base_url, selenium, variables): page = Home(selenium, base_url).open() term = variables['search_term'] page.search.search_for(term) search_page = Search(selenium, base_url) select = Select(search_page.filter_by_sort) assert select.first_selected_option.text == 'Relevance' select = Select(search_page.filter_by_type) assert select.first_selected_option.text == 'All' select = Select(search_page.filter_by_badging) assert select.first_selected_option.text == 'Any'
def test_filter_by_rating_and_hotness(base_url, selenium, category, sort_attr): """Test searching for an addon and sorting.""" Home(selenium, base_url).open() addon_name = 'fox' selenium.get(f'{base_url}/search/?&q={addon_name}&sort={sort_attr}') search_page = Search(selenium, base_url) results = search_page.result_list.extensions if sort_attr == 'rating': for result in search_page.result_list.extensions: assert result.rating > 4 else: assert len(results) == 25
def test_more_info_related_categories(selenium, base_url, variables): extension = variables['detail_extension_slug'] selenium.get(f'{base_url}/addon/{extension}') addon = Detail(selenium, base_url).wait_for_page_to_load() # get the name of one of the categories related to this addon category_name = addon.more_info.addon_categories[0].text addon.more_info.addon_categories[0].click() # clicking on the category opens a search results page with addons that share the same category same_category_results = Search(selenium, base_url).wait_for_page_to_load() count = 0 # checking that the search results do include the category of the initial addon # I think it's sufficient to cross-check for the first five add-on in the results list while count <= 4: same_category_results.result_list.click_search_result(count) category_name_from_search = [ el.text for el in addon.more_info.addon_categories ] assert category_name in category_name_from_search selenium.back() same_category_results.wait_for_page_to_load() count += 1
def test_collection_sort_addons_by_date_added(selenium, base_url, variables, wait): collections = Collections(selenium, base_url).open().wait_for_page_to_load() collections.login('collection_user') collections.select_collection(0) collections.collection_detail.click_edit_collection_button() # adding one more addon to the collection search_addon = collections.create.addon_search.search( variables['detail_extension_name']) search_addon[0].name.click() # waits for the new add-on to be added to the collection wait.until( lambda _: len(collections.create.edit_addons_list) == 2, message= f'The list contains {len(collections.create.edit_addons_list)} addons', ) collections.collection_detail.click_back_to_collection() # using the Search class to interact with the list of addons present in the collection addons = Search(selenium, base_url).wait_for_page_to_load() sort = Select(collections.collection_detail.sort_addons) sort.select_by_visible_text('Oldest first') addons.wait_for_page_to_load() # this addon was already in the collection, so it is the older one when sort is applied assert variables['search_term'] in addons.result_list.extensions[0].name sort.select_by_visible_text('Newest first') addons.wait_for_page_to_load() # this is the new addon added to the collection, so it is the most recent when sort is applied assert variables['detail_extension_name'] in addons.result_list.extensions[ 0].name
def search_for(self, term, execute=True): textbox = self.find_element(*self._search_textbox_locator) textbox.click() textbox.send_keys(term) # Send 'enter' since the mobile page does not have a submit button if execute: textbox.send_keys(Keys.ENTER) from pages.desktop.frontend.search import Search return Search(self.selenium, self.page).wait_for_page_to_load() WebDriverWait(self.selenium, 30).until( EC.invisibility_of_element_located( (By.CLASS_NAME, 'LoadingText'))) return self.search_suggestions
def test_browse_more_top_rated_extensions(base_url, selenium): extensions = Extensions(selenium, base_url).open() extensions.shelves.top_rated_addons.browse_all() assert 'sort=rating&type=extension' in selenium.current_url search_results = Search(selenium, base_url) select = Select(search_results.filter_by_badging) assert select.first_selected_option.text == 'Recommended' for result in search_results.result_list.extensions: assert 'Recommended' in result.promoted_badge_label # using a list slice below (normal len is 25) to validate rating ordering # because not all addons in the list have a rating on stage ratings = search_results.result_list.extensions[0:16] for rating in ratings: assert rating.rating >= 4
def search_box(self, value): search_field = self.find_element(*self._search_box_locator) search_field.send_keys(value) # send Enter to initiate search redirection to AMO search_field.send_keys(Keys.ENTER) # AMO search results open in a new tab, so we need to switch windows self.wait.until( EC.number_of_windows_to_be(2), message= f'Number of windows was {len(self.selenium.window_handles)}, expected 2', ) self.selenium.switch_to.window(self.selenium.window_handles[1]) from pages.desktop.frontend.search import Search return Search(self.selenium, self.base_url).wait_for_page_to_load()
def test_add_to_collection_in_addon_detail_page(selenium, base_url, variables, wait): collections = Collections(selenium, base_url).open().wait_for_page_to_load() collections.login('collection_user') # make a note of the collection name to be used for this test collection_name = collections.list[0].name.text # make a note of the collections present in My Collections page my_collections_list = [el.name.text for el in collections.list] extension = variables['non_recommended_addon'] # open an addon detail page selenium.get(f'{base_url}/addon/{extension}') addon = Detail(selenium, base_url).wait_for_page_to_load() # make a note of the addon name to use it later addon_name = addon.name select = Select(addon.add_to_collection.collections_select_field) add_to_collection_list = [ el.text for el in addon.add_to_collection.add_to_collections_list ] # check that the list of user collections matches the list present in Add to collection from detail page; # the detail page displays collections in alphabetical order, so we need to sort the other list to have a match assert sorted(my_collections_list, key=str.lower) == add_to_collection_list # add the addon to the test collection select.select_by_visible_text(collection_name) # verify that a success message is displayed once the collection is selected assert (f'Added to {collection_name}' in addon.add_to_collection.add_to_collection_success_notice) # select the same collection again and check that an error message is displayed select.select_by_visible_text(collection_name) assert ('This add-on already belongs to the collection' in addon.add_to_collection.add_to_collection_error_notice) collections.open().wait_for_page_to_load() # open the collection details and check that the new addon was included collections.select_collection(0) addons_list = Search(selenium, base_url).wait_for_page_to_load() assert addon_name in addons_list.result_list.extensions[0].name
def browse_all(self): self.find_element(*self._browse_all_locator).click() from pages.desktop.frontend.search import Search search = Search(self.selenium, self.page) return search.wait_for_page_to_load()
def click(self): self.root.click() from pages.desktop.frontend.search import Search return Search(self.selenium, self.page.base_url)
def user_themes(self): self.find_element(*self._user_themes_card_locator) return Search(self.selenium, self.page.base_url).wait_for_page_to_load()