import logging import allure from appium.webdriver.common.touch_action import TouchAction from ui_automation_framework.utils import logger as cl from app.mysql_db_client_custom import MySqlClient from app.src.pages.navigation_page import Navigation from app.src.pages.search_page import SearchPage from app.src.ui_elements.button_ui_element import ButtonUIElement from app.src.ui_elements.label_ui_element import LabelUIElement class OnBoardingPage(Navigation): log = cl.Logger(logging.DEBUG) def __init__(self, driver, api_client): super().__init__(driver) self.api = api_client self.driver = driver self.onboarding_locators = self.get_page_locators("OnBoardingPage", "onboarding_elements.json") self.sql_client = MySqlClient() @property def bn_set_profile(self): return ButtonUIElement(self.driver, self.locator(self.onboarding_locators, "set_profile_btn")) @property def bn_next(self): return ButtonUIElement(self.driver, self.locator(self.onboarding_locators, "next_btn")) @property def bn_start(self): return ButtonUIElement(self.driver, self.locator(self.onboarding_locators, "start_btn")) @property def lb_1_slide_copy(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "1st_slide_copy")) @property def lb_2_slide_copy(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "2nd_slide_copy")) @property def lb_3rd_slide_copy(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "3rd_slide_copy")) @property def lb_4_th_slide_copy(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "4th_slide_copy")) @property def lb_country_copy(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "country_copy")) @property def lb_location_copy(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "location_copy")) @property def lb_location_header(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "location_header")) @property def lb_location_footer(self): return LabelUIElement(self.driver, self.locator(self.onboarding_locators, "location_footer")) def skip_on_boarding(self): while not self.bn_set_profile.is_visible(): self.click_next() self.bn_set_profile.click() self.bn_start.click() return self @allure.step("Clicking next button") def click_next(self): self.bn_next.click() return self @allure.step("Clicking back on set profile page") def click_back_on_set_profile(self): size = self.driver.get_window_size() self.log.info(size) TouchAction(self.driver).tap(x=size["width"] * 0.088, y=size["height"] * 0.08).perform() return self @allure.step("Clicking start button") def click_start(self): self.bn_start.click() return SearchPage(self.driver, self.api) @allure.step("Clicking set profile button") def click_set_profile(self): self.bn_set_profile.click() return self @allure.step("Swiping slides right") def swipe_next(self): scroll_object = {} scroll_object.update({"direction": "left"}) scroll_object.update({"xpath": "(//XCUIElementTypeImage)[3]"}) self.driver.execute_script("mobile: swipe", scroll_object) return self @allure.step("Swiping slides left") def swipe_previous(self): scroll_object = {} scroll_object.update({"direction": "right"}) scroll_object.update({"xpath": "(//XCUIElementTypeImage)[3]"}) self.driver.execute_script("mobile: swipe", scroll_object) return self def set_on_boarding_flow(self, userid, value): self.sql_client.set_on_boarding_flow(userid, value) return self def get_user_market(self, userid): return self.sql_client.get_user_market(userid) @allure.step("Verifying onboarding flow is displayed") def is_onboarding_displayed(self): return self.lb_1_slide_copy.is_visible() @allure.step("Verifying 2nd slide is displayed") def is_2nd_slide_displayed(self): return self.lb_2_slide_copy.is_visible() @allure.step("Verifying 3rd slide is displayed") def is_3rd_slide_displayed(self): return self.lb_3rd_slide_copy.is_visible() @allure.step("Verifying 4th slide is displayed") def is_4th_slide_displayed(self): return self.lb_4_th_slide_copy.is_visible() @allure.step("Verifying country confirmation screen is displayed") def is_country_confirmation_displayed(self): return self.lb_country_copy.is_visible() and self.lb_location_copy.is_visible() and self.lb_location_header.is_visible() and self.lb_location_footer.is_visible() @allure.step("Verifying proper user's market is dsiplayed") def is_user_market_displayed(self, market): locator = f'**/XCUIElementTypeStaticText[`label == "{market}"`]' return self.is_element_displayed(locator, "class-chain")