import allure import pytest from assertpy import assert_that, soft_assertions from ui_automation_framework.utils import CoreConfig from waiting.exceptions import TimeoutExpired from app.src.api.models.auth_model import AuthData from app.src.helpers.images_helper import are_images_equal from app.src.helpers.waiting_wrapper import wait from app.src.pages.constants import AL, ALBANIA, CANCEL, CHECKED_GLOBAL, DONE, FIND_A_MARKET, GL, MALTA, MARKETS, MARKETS_SELECTED_BUTTON_TEXT, MARKETS_SELECTED_COUNT_PATTERN, NOTIFICATION_SETTINGS_MARKETS_TITLE, NOTIFICATIONS_SETTINGS_HELPER_TEXT, NOTIFICATIONS_TITLE, RESET_BUTTON @pytest.fixture() def api_user1(): return AuthData(CoreConfig.NOTIFICATIONS_EMAIL, CoreConfig.NOTIFICATIONS_PASSWORD) @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Notification is clickable") @allure.description("User should be able to open track page from the notifications screen") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-796") @pytest.mark.smoke def test_notification_clickable(login_page, notifications_page, track_page, playlist_page): login_page.login_as_notifications_user().select_notifications_tab() track_position, _ = next((e for e in enumerate(notifications_page.lt_notifications.elements) if "Chart" in e[1].label), (None, None)) if track_position: track_position += 1 track_title = notifications_page.get_notification_text(track_position=track_position).split(" – ")[1] # get only track name playlist_position, _ = next((e for e in enumerate(notifications_page.lt_notifications.elements) if "Chart" not in e[1].label), (None, None)) if playlist_position: playlist_position += 1 playlist_title = notifications_page.get_notification_text(playlist_position=playlist_position) if playlist_position: notifications_page.click_on_notification(playlist_position) assert_that(playlist_page.is_playlist_page_opened_for_name(playlist_title)).described_as("The proper playlist wasn't opened").is_true() playlist_page.click_back_button() if track_position: try: notifications_page.click_on_notification(track_position) except TimeoutExpired: notifications_page.scroll_down() notifications_page.click_on_notification(track_position) finally: assert_that(track_page.is_track_page_opened(track_title)).described_as("The proper track wasn't opened").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Notifications scroll") @allure.description("User should be able to scroll notifications") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-789") @pytest.mark.smoke def test_notifications_scroll(login_page, notifications_page): login_page.login_as_notifications_user().select_notifications_tab() # we cannot use strict numbers like 20 because vendor can give us invalid notifications that will not be rendered num_of_all_elements_before_pagination = len(notifications_page.lt_notifications.elements) notification_title = notifications_page.get_notification_text(position=num_of_all_elements_before_pagination) notifications_page.scroll_notifications() num_of_all_elements_after_pagination = len(notifications_page.lt_notifications.elements) assert_that(num_of_all_elements_after_pagination).is_greater_than(num_of_all_elements_before_pagination) new_notification_title = notifications_page.get_notification_text(position=num_of_all_elements_after_pagination) assert_that(notification_title).described_as("Notifications list isn't scrolled").is_not_equal_to(new_notification_title) @allure.story("https://data-analytics.atlassian.net/browse/AG-6785") @allure.severity(allure.severity_level.CRITICAL) @allure.title("No starred tracks message") @allure.description("Info about disabled notification is not shown but there is a placeholder about tracks starring") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-1099") @pytest.mark.regression def test_no_starred_tracks(login_page, starred_page, notifications_page): login_page.login_as_regular_user().select_starred_tracks_tab() starred_page.unstar_all().select_notifications_tab() assert_that(notifications_page.lb_disabled_notifications.is_visible()).described_as("Message about disabled notifications isn't shown").is_false() assert_that(notifications_page.is_star_track_placeholder_displayed()).described_as("Star your first track placeholder is not displayed").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-7447") @allure.severity(allure.severity_level.NORMAL) @allure.title("Notifications API/UI integration") @allure.description("API and UI data for notifications should match") @pytest.mark.regression def test_charts_data_api_integration_apple(login_page, notifications_page, authorized_api): api_data = authorized_api.apollo.get_push_notifications()["body"]["items"] api_data = sorted(api_data, key=lambda x: x["is_new"]) login_page.login_as_regular_user().select_notifications_tab() for api_item, ui_item in zip(api_data, wait(lambda: notifications_page.lt_notifications.elements)): assert_that(ui_item.text).described_as("Positions").contains(str(api_item["position"])).described_as("Targets").contains(api_item["target"]) # assert_that(ui_item.text.lower()).described_as("Artists names").contains(api_item["artist_name"].lower()).described_as("Track names").contains(api_item["track_name"].lower()) @allure.story("https://data-analytics.atlassian.net/browse/AG-8458") @allure.severity(allure.severity_level.NORMAL) @allure.title("Navigation to settings") @allure.description("User should be able to open global notifications settings from notifications screen") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8398") @pytest.mark.smoke @pytest.mark.usefixtures("with_default_settings") def test_notifications_settings(login_page, profile_page, notifications_page): login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened) profile_page.click_notifications_toggle() wait(profile_page.are_settings_hidden, waiting_for="Settings weren't hidden") profile_page.click_back_button().select_notifications_tab() assert_that(notifications_page.bn_settings_widget.is_visible()).described_as("Settings widget wasn't displayed").is_true() notifications_page.bn_settings_widget.click() assert_that(profile_page.is_notifications_settings_opened()).described_as("Settings screen isn't opened").is_true() profile_page.click_back_button() assert_that(notifications_page.bn_settings_widget.is_visible()).described_as("Settings widget wasn't displayed").is_true() notifications_page.bn_settings_widget.click() assert_that(profile_page.is_notifications_settings_opened()).described_as("Settings screen isn't opened").is_true() profile_page.click_notifications_toggle().click_back_button() assert_that(notifications_page.bn_settings_widget.is_visible()).described_as("Settings widget wasn't displayed").is_false() notifications_page.select_profile_tab() profile_page.open_notification_settings() assert_that(profile_page.is_notifications_settings_opened()).described_as("Settings screen isn't opened").is_true() profile_page.click_notification_settings_reset_button() assert_that(profile_page.are_settings_in_default_state()).described_as("Settings aren't in default state").is_true() @allure.title("Market page elements") @allure.severity(allure.severity_level.NORMAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8400") @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_notification_settings_market_page(login_page, profile_page, faker, authorized_api): login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) profile_page.open_notification_markets_settings() assert_that(profile_page.lb_markets_header.text).is_equal_to(NOTIFICATION_SETTINGS_MARKETS_TITLE) assert_that(profile_page.bn_markets_settings_done.text).is_equal_to(DONE) assert_that(profile_page.bn_markets_cancel.text).is_equal_to(CANCEL) assert_that(profile_page.in_markets_search.text).is_equal_to(FIND_A_MARKET) profile_page.lt_search_results.select_by_text(ALBANIA) assert_that(profile_page.markets_selected).matches(MARKETS_SELECTED_COUNT_PATTERN) assert_that(profile_page.get_market_code_element(GL).text).is_equal_to(GL) assert_that(profile_page.get_market_code_element(AL).text).is_equal_to(AL) profile_page.in_markets_search.send_text(faker.pystr(3, 10)) assert_that(profile_page.bn_clear.text).is_not_empty() @allure.title("Select market without confirmation") @allure.severity(allure.severity_level.TRIVIAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8397") @pytest.mark.parametrize("back_method", [0, 1]) @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_select_market_without_confirmation(login_page, profile_page, back_method): markets_to_select = range(2, 5) login_page.login_as_regular_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) profile_page.open_notification_markets_settings() wait(profile_page.is_notifications_market_settings_opened, timeout=5) before = profile_page.markets_selected for market_position in markets_to_select: profile_page.select_market_from_list_by_position(market_position) assert_that(profile_page.markets_selected).is_equal_to("4 OF 10 SELECTED") (profile_page.swipe_back, profile_page.click_cancel_on_market_settings)[back_method]() wait(profile_page.is_notifications_settings_opened, timeout=5) profile_page.open_notification_markets_settings() assert_that(profile_page.markets_selected).is_equal_to(before) @allure.title("Notification page elements when off") @allure.severity(allure.severity_level.NORMAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8360") @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_notification_settings_off(login_page, profile_page): login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) profile_page.click_notifications_toggle() with soft_assertions(): assert_that(profile_page.lb_notifications.text).is_equal_to(NOTIFICATIONS_TITLE) # assert_that(profile_page.lb_notifications_settings_sub_header.text).is_equal_to(NOTIFICATIONS_SUB_HEADER) assert_that(profile_page.lb_notifications.is_visible()).is_true() assert_that(profile_page.bn_markets_notification_settings.is_visible()).is_false() assert_that(profile_page.lb_notification_settings_text_helper.is_visible()).is_false() assert_that(profile_page.lb_notification_settings_charts_and_playlists.is_visible()).is_false() assert_that(profile_page.lb_spotify_dsp.is_visible()).is_false() assert_that(profile_page.lb_apple_dsp.is_visible()).is_false() assert_that(profile_page.bn_reset_notifications.is_visible()).is_false() @allure.title("Notification page elements when on") @allure.severity(allure.severity_level.NORMAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8360") @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_notification_settings_on(login_page, profile_page): login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) with soft_assertions(): # TODO: Need to be updated assert_that(profile_page.lb_notifications.is_visible()).is_true() assert_that(profile_page.lb_notifications.text).is_equal_to(NOTIFICATIONS_TITLE) # assert_that(profile_page.lb_notifications_settings_sub_header.text).is_equal_to(NOTIFICATIONS_SUB_HEADER) assert_that(profile_page.bn_markets_notification_settings.text).is_equal_to(MARKETS_SELECTED_BUTTON_TEXT) assert_that(profile_page.lb_notification_settings_text_helper.text).is_equal_to(NOTIFICATIONS_SETTINGS_HELPER_TEXT) # assert_that(profile_page.lb_notification_settings_charts_and_playlists.text).is_equal_to(CHART_N_PLAYLISTS_TEXT) # assert_that(profile_page.lb_spotify_dsp.text).is_equal_to(DSP_SPOTIFY_TEXT) # assert_that(profile_page.lb_apple_dsp.text).is_equal_to(DSP_APPLE_MUSIC_TEXT) assert_that(profile_page.bn_reset_notifications.text).is_equal_to(RESET_BUTTON) @allure.title("Markets search clearing") @allure.severity(allure.severity_level.NORMAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-5165") @pytest.mark.parametrize("clear_method", [0, 1]) @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_market_clear_search(login_page, profile_page, clear_method): search_query = "Al" expected_search_result = [m for m in MARKETS + [CHECKED_GLOBAL] if search_query.lower() in m or search_query in m] login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) profile_page.click_notifications_toggle().open_notification_markets_settings() wait(profile_page.is_notifications_market_settings_opened, timeout=5) before = profile_page.lt_search_results.texts profile_page.in_markets_search.send_text(search_query) assert_that(profile_page.lt_search_results.texts).contains_only(*expected_search_result) (profile_page.bn_clear.click, profile_page.in_markets_search.clear_text)[clear_method]() wait(lambda: profile_page.in_markets_search.text == "", timeout=2) assert_that(profile_page.lt_search_results.texts).is_equal_to(before) @allure.title("Market search no results") @allure.severity(allure.severity_level.NORMAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-5153") @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_settings_market_no_search_results(login_page, profile_page, faker): login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) profile_page.open_notification_markets_settings() profile_page.in_markets_search.send_text(faker.pystr(12)) assert_that(profile_page.lb_markets_no_result.is_visible()).is_true() @allure.title("Markets search cancel button functionality") @allure.severity(allure.severity_level.NORMAL) @allure.testcase("https://data-analytics.atlassian.net/browse/AG-5149") @pytest.mark.regression @pytest.mark.usefixtures("with_default_settings") def test_settings_market_cancel_button_functionality(login_page, profile_page): login_page.login_as_notifications_user().select_profile_tab() profile_page.open_notification_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) before = profile_page.bn_markets_notification_settings.image profile_page.open_notification_markets_settings() wait(profile_page.is_notifications_market_settings_opened, timeout=5) profile_page.lt_search_results.select_by_text(MALTA) assert_that(profile_page.lt_search_results.get_item_by_text(MALTA).text).contains("") profile_page.click_cancel_on_market_settings() wait(profile_page.is_notifications_settings_opened, timeout=5) assert_that(are_images_equal(before, profile_page.bn_markets_notification_settings.image)).is_true() profile_page.open_notification_markets_settings() assert_that(profile_page.lt_search_results.get_item_by_text(MALTA).text).does_not_contain("")