import pytest import allure from random import choice from assertpy import assert_that from src.data.entities_data import entity_types from src.data.entities_data import entity_ids from src.helpers.api_helper import api_amplitude @allure.description("Send statistics to amplitude on Discovery actions") @pytest.mark.usefixtures("app") class TestAmplitudeSearch: @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-953") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-954") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1892") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1893") @allure.title("[Amplitude] - Search clicked - Search By Name Full Screen Viewed - Search By Name Launched") @pytest.mark.regression def test_amplitude_search(self): with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to("") self.home_page.is_page_loaded() # Click Search button with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.home_page.bn_search.click() self.search_page.is_page_loaded() amplitude_payload = amplitude_response.value.request.post_data_json events = amplitude_payload['events'] assert_that(events[0]['event_type']).is_equal_to('Search Button Clicked') assert_that(events[0]['event_properties']).is_equal_to({}) assert_that(events[1]['event_type']).is_equal_to('Search By Name Full Screen Viewed') assert_that(events[1]['event_properties']).is_equal_to({}) assert_that(events[2]['event_type']).is_equal_to('Recent Searches Viewed') assert_that(events[2]['event_properties']).is_equal_to({}) # Start Searching with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.search_page.placeholder_search.input_text('A') self.search_page.is_page_loaded() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to('Search By Name Launched') @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-1892") @allure.title("[Amplitude] - Recent searches viewed") @pytest.mark.regression def test_amplitude_recent_search(self): with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to("") self.home_page.is_page_loaded() # Click to Search field in the header with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.home_page.placeholder_search.click() self.search_page.is_page_loaded() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to('Recent Searches Viewed')