def registration_should_get_verification_email(context: Context, actor_alias: str): """Will check if the Exporter received an email verification message.""" logging.debug("Searching for an email verification message...") actor = get_actor(context, actor_alias) link = get_verification_link(actor.email) update_actor(context, actor_alias, email_confirmation_link=link)
def visit_page(context: Context, actor_alias: str, page_name: str): """Will visit specific page. NOTE: In order for the retry scheme to work properly you should have the webdriver' page load timeout set to value lower than the retry's `wait_fixed` timer, e.g `driver.set_page_load_timeout(time_to_wait=30)` """ def is_special_case(page_name: str) -> bool: parts = page_name.split(" - ") return len(parts) == 3 if not get_actor(context, actor_alias): add_actor(context, unauthenticated_actor(actor_alias)) page = get_page_object(page_name) has_action(page, "visit") if is_special_case(page_name) and hasattr(page, "SubURLs"): subpage_name = page_name.split(" - ")[1].lower() special_url = page.SubURLs[subpage_name] logging.debug( f"{actor_alias} will visit '{page_name}' subpage using: '{special_url}" ) page.visit(context.driver, page_name=subpage_name) else: logging.debug( f"{actor_alias} will visit '{page_name}' page using: '{page.URL}'") page.visit(context.driver) take_screenshot(context.driver, f"visit page {page_name}") accept_all_cookies(context.driver) check_for_errors(context.driver.page_source, context.driver.current_url) update_actor(context, actor_alias, visited_page=page)
def generic_pick_random_radio_option_and_submit(context: Context, actor_alias: str, ignored: str): ignored = [item.strip().lower() for item in ignored.split(",")] page = get_last_visited_page(context, actor_alias) has_action(page, "pick_random_radio_option_and_submit") new_page = page.pick_random_radio_option_and_submit( context.driver, ignored) update_actor(context, actor_alias, visited_page=new_page)
def generic_get_verification_code(context: Context, actor_alias: str, *, resent_code: bool = False): """Will check if the Exporter received an email verification message.""" logging.debug("Searching for an email verification message...") actor = get_actor(context, actor_alias) code = get_email_verification_code(actor.email, resent_code=resent_code) update_actor(context, actor_alias, email_confirmation_code=code)
def domestic_open_random_market(context: Context, actor_alias: str): if not get_actor(context, actor_alias): add_actor(context, unauthenticated_actor(actor_alias)) driver = context.driver domestic.markets_listing.visit(driver) take_screenshot(driver, domestic.markets_listing.NAME) check_for_errors(driver.page_source, driver.current_url) market_name = domestic.markets_listing.open_random_marketplace(driver) domestic.market_country_guide.should_be_here(driver) update_actor( context, actor_alias, visited_page=domestic.market_country_guide, article_url=driver.current_url, visited_articles=market_name, )
def registration_submit_form_and_verify_account(context: Context, actor_alias: str, *, fake_verification: bool = True ): actor = get_actor(context, actor_alias) generic_fill_out_and_submit_form(context, actor_alias, custom_details_table=context.table) if fake_verification: sso.common.verify_account(actor.email) else: registration_should_get_verification_email(context, actor_alias) registration_open_email_confirmation_link(context, actor_alias) sso.confirm_your_email.submit(context.driver) update_actor(context, actor_alias, registered=True)
def domestic_open_random_advice_article(context: Context, actor_alias: str): if not get_actor(context, actor_alias): add_actor(context, unauthenticated_actor(actor_alias)) driver = context.driver domestic.advice_landing.visit(driver) take_screenshot(driver, domestic.advice_landing.NAME) check_for_errors(driver.page_source, driver.current_url) advice_name = domestic.advice_landing.open_any_article(driver) article_name = domestic.advice_article_list.open_any_article(driver) domestic.advice_article.should_be_here(driver) update_actor( context, actor_alias, visited_page=domestic.advice_article, article_url=driver.current_url, article_category=advice_name, visited_articles=article_name, )
def should_be_on_page(context: Context, actor_alias: str, page_name: str): page = get_page_object(page_name) # revisit_page_on_access_denied(context.driver, page, page_name) take_screenshot(context.driver, f"should be on {page_name}") check_for_errors(context.driver.page_source, context.driver.current_url) has_action(page, "should_be_here") if hasattr(page, "SubURLs"): special_page_name = page_name.split(" - ")[1].lower() if signature(page.should_be_here).parameters.get("page_name"): page.should_be_here(context.driver, page_name=special_page_name) else: raise TypeError( f"{page.__name__}.should_be_here() doesn't accept 'page_name' keyword " f"argument but it should as this Page Object has 'SubURLs' attribute." ) else: page.should_be_here(context.driver) update_actor(context, actor_alias, visited_page=page) logging.debug( f"{actor_alias} is on {page.SERVICE} - {page.NAME} - {page.TYPE} -> " f"{page}")
def generic_open_any_tag(context: Context, actor_alias: str): page = get_last_visited_page(context, actor_alias) has_action(page, "open_any_tag") tag = page.open_any_tag(context.driver) update_actor(context, actor_alias, last_tag=tag)
def articles_open_any(context: Context, actor_alias: str): page = get_last_visited_page(context, actor_alias) has_action(page, "open_any_article") article_name = page.open_any_article(context.driver) update_actor(context, actor_alias, visited_articles=article_name) logging.info(f"{actor_alias} opened article: {article_name}")
def generic_pick_radio_option_and_submit(context: Context, actor_alias: str, option: str): page = get_last_visited_page(context, actor_alias) has_action(page, "pick_radio_option_and_submit") new_page = page.pick_radio_option_and_submit(context.driver, option) update_actor(context, actor_alias, visited_page=new_page)