import pytest import allure from assertpy import assert_that from src.data.entities_data import entity_types from src.data.entities_data import entity_ids @pytest.mark.usefixtures("app") class TestEntityHeader: @allure.description("As user I want to see all external links related to the entity") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-220") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-237") @allure.title("[Entity Page] External links section") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_external_links(self, entity_type): self.second_page = self.app.context.new_page() entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] print(f'Tested entity id = {entity_id}') with self.app.page.expect_response( self.artist_page.api_external_links.format(entity_type, entity_id)) as links_response: self.app.go_to(f"/{entity_type}/{entity_id}") links = links_response.value.json() for link in links['header']: link_name = link['name'] print(link_name) resp_link_url = link['items'][0]['url'] print(resp_link_url) ui_icon = 'sndcld' if link_name == 'soundcloud' else link_name page_link_href = self.artist_page.ext_link.get_by(ui_icon).get_attribute('href') print(page_link_href) assert_that(resp_link_url).is_equal_to(page_link_href) if link_name != 'website': assert_that(page_link_href).contains(link_name) self.second_page.goto(page_link_href) self.second_page.wait_for_load_state('domcontentloaded') # open rest external links if there is more than only 'header' in response if len(links) > 1: self.artist_page.btn_rest_ext_link.click() if 'social_media' in links: for link in links['social_media']: link_name = link['name'] print(link_name) resp_link_url = link['items'][0]['url'] print(resp_link_url) link_name = 'youtube' if link_name == 'youtubeforartist' else link_name page_link_href = self.artist_page.ext_social_link.get_by(link_name).get_attribute('href') print(page_link_href) assert_that(resp_link_url).is_equal_to(page_link_href) assert_that(page_link_href).contains(link_name) self.second_page.goto(page_link_href) self.second_page.wait_for_load_state('domcontentloaded') if 'streaming_services' in links: for link in links['streaming_services']: link_name = link['name'] print(link_name) resp_link_url = link['items'][0]['url'] print(resp_link_url) page_link_href = self.artist_page.ext_streaming_link.get_by(link_name).get_attribute('href') print(page_link_href) assert_that(resp_link_url).is_equal_to(page_link_href) assert_that(page_link_href).contains(link_name) self.second_page.goto(page_link_href) self.second_page.wait_for_load_state('domcontentloaded') self.second_page.close() @allure.description("As user I want to see entity's name, label, genre and country") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-126") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-157") @allure.title("[Entity page] - Label, Genre, Country") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_label_genre_country(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] with self.app.page.expect_response( self.artist_page.api_discovery_result.format(entity_type, entity_id)) as response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.check_entity_name(response) self.artist_page.check_entity_label(response) self.artist_page.check_entity_genre(response) self.artist_page.check_entity_country(response) @pytest.mark.usefixtures("app") class TestEntityTracks: @allure.title("[Entity Page] Tracks section - Spotify") @allure.description("As user I want see tracks related to artist") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-226") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-653") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_tracks_spotify(self, entity_type): # Hardcoded ids to have all parameters on the screen entity_id = entity_ids[entity_type] with self.app.page.expect_response( self.artist_page.api_spotify_tracks.format(entity_type, entity_id)) as response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.scope_bar.get_by('spotify').is_active() self.artist_page.check_spotify_tracks(response) # Click track Details and check results page self.artist_page.btn_card_spotify_details.get_by(1).click() self.track_page.is_page_loaded() assert_that(self.app.page.url).contains('track') @allure.title("[Entity Page] Tracks section - SoundCloud") @allure.description("As user I want see tracks related to artist") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-226") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-653") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_tracks_soundcloud(self, entity_type): # Hardcoded ids to have all parameters on the screen entity_id = entity_ids[entity_type] with self.app.page.expect_response( self.artist_page.api_soundcloud_tracks.format(entity_type, entity_id)) as response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.scope_bar.get_by('soundcloud').click() self.artist_page.scope_bar.get_by('soundcloud').is_active() self.artist_page.check_soundcloud_tracks(response) # Click track Details and check results page self.artist_page.btn_card_soundcloud_details.get_by(1).click() self.track_page.is_page_loaded() assert_that(self.app.page.url).contains('track') @pytest.mark.usefixtures("app") class TestEntityVideos: @allure.title("[Entity Page] Videos section - TikTok") @allure.description("As user I want see tracks related to artist") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-227") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-654") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_videos_tiktok(self, entity_type): # Hardcoded ids to have all parameters on the screen entity_id = entity_ids[entity_type] with self.app.page.expect_response( self.artist_page.api_tiktok_videos.format(entity_type, entity_id)) as response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.scope_bar.get_by('tiktok').is_active() self.artist_page.check_tiktok_videos(response) # Click TikTok Video card card_link = self.artist_page.card_tiktok_src.get_by(1).get_attribute('href') self.second_page = self.app.context.new_page() self.second_page.goto(card_link) self.second_page.wait_for_load_state('domcontentloaded') assert_that(self.second_page.url).contains('tiktok') @allure.title("[Entity Page] Videos section - TikTok") @allure.description("As user I want see tracks related to artist") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-227") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-654") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_videos_youtube(self, entity_type): # Hardcoded ids to have all parameters on the screen entity_id = entity_ids[entity_type] with self.app.page.expect_response( self.artist_page.api_youtube_videos.format(entity_type, entity_id)) as response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.scope_bar.get_by('youtube').click() self.artist_page.scope_bar.get_by('youtube').is_active() self.artist_page.check_youtube_videos(response) # Click YouTube Video card card_link = self.artist_page.card_youtube_src.get_by(1).get_attribute('href') self.second_page = self.app.context.new_page() self.second_page.goto(card_link) self.second_page.wait_for_load_state('domcontentloaded') assert_that(self.second_page.url).contains('youtube')