def should_see_page_number(driver: WebDriver, page_num: int): scroll_to(driver, find_element(driver, ACTIVE_PAGE)) take_screenshot(driver, NAME) selector = find_element(driver, ACTIVE_PAGE) with assertion_msg(f"Expected to see {page_num} but got {int(selector.text)}"): assert int(selector.text) == page_num
def has_pagination(driver: WebDriver, min_page_num: int): scroll_to(driver, find_element(driver, PAGINATION)) take_screenshot(driver, NAME) selectors = find_elements(driver, PAGES) with assertion_msg( f"Expected to see more that {min_page_num} search results page but got just {len(selectors)}" ): assert len(selectors) > min_page_num
def search(driver: WebDriver, country: str, category: str): form_selectors = SELECTORS["search form"] find_a_marketplace = find_element( driver, SEARCH_BUTTON, element_name="find your marketplace" ) scroll_to(driver, find_a_marketplace) details = generate_form_details(country, category) pick_option(driver, form_selectors, form_details=details) find_a_marketplace.click() take_screenshot(driver, "After submitting the form")
def play_video(driver: WebDriver, *, play_time: int = 5): video_load_delay = 2 video = driver.find_element(by=PROMO_VIDEO.by, value=PROMO_VIDEO.value) scroll_to(driver, video) video.click() play_js = f'document.querySelector("{PROMO_VIDEO.value}").play()' pause = f'document.querySelector("{PROMO_VIDEO.value}").pause()' driver.execute_script(play_js) if play_time: time.sleep(play_time + video_load_delay) driver.execute_script(pause)
def generic_click_on_random_element(context: Context, actor_alias: str, elements_name: str): page = get_last_visited_page(context, actor_alias) selector = find_selector_by_name(page.SELECTORS, elements_name) elements = find_elements(context.driver, selector) element = random.choice(elements) href = f" → {element.get_attribute('href')}" if element.tag_name == "a" else "" logging.debug(f"Will click on: '{element.text.strip()}'{href}") scroll_to(context.driver, element) with wait_for_page_load_after_action(context.driver, timeout=10): with try_alternative_click_on_exception(context.driver, element): element.click()