Exemplo n.º 1
0
def generic_fill_out(
    context: Context,
    actor_alias: str,
    *,
    custom_details_table: Table = None,
    retry_on_errors: bool = False,
    go_back: bool = False,
    form_name: str = None,
    check_captcha_dev_mode: bool = True,
):
    if check_captcha_dev_mode:
        assert_catcha_in_dev_mode(context.driver)
    actor = get_actor(context, actor_alias)
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "generate_form_details")
    has_action(page, "fill_out")
    if form_name:
        error = f"generate_form_details() in {page} should accept 'form_name' but it doesn't"
        assert signature(
            page.generate_form_details).parameters.get("form_name"), error
        error = f"fill_out() in {page} should accept 'form_name' but it doesn't"
        assert signature(page.fill_out).parameters.get("form_name"), error
    if custom_details_table:
        custom_details_table.require_column("field")
        custom_details_table.require_column("value")
        value_mapping = {"unchecked": False, "checked": True, "empty": None}
        custom_details = {}
        for row in custom_details_table.rows:
            key = row["field"].lower()
            value = row["value"]
            custom_details[key] = value_mapping.get(value, value)
        if form_name:
            details = page.generate_form_details(actor,
                                                 custom_details=custom_details,
                                                 form_name=form_name)
        else:
            details = page.generate_form_details(actor,
                                                 custom_details=custom_details)
    else:
        if form_name:
            details = page.generate_form_details(actor, form_name=form_name)
        else:
            details = page.generate_form_details(actor)
    logging.debug(f"{actor_alias} will fill out the form with: {details}")

    update_actor_forms_data(context, actor, details)

    if form_name:
        page.fill_out(context.driver, details, form_name=form_name)
    else:
        page.fill_out(context.driver, details)

    if hasattr(page, "get_form_details"):
        logging.debug(f"Getting form details from filled out form: {page}")
        form_data = page.get_form_details(context.driver)
        if form_data:
            update_actor_forms_data(context, actor, form_data)
    else:
        if details:
            update_actor_forms_data(context, actor, details)
Exemplo n.º 2
0
def actor_decides_to_enter_email_address_and_click_login(
        context, actor_alias, email_address, password):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "login")
    email_address = str(email_address).strip()  # trimming
    password = str(password).strip()  # trimming
    page.login(context.driver, email_address=email_address, password=password)
Exemplo n.º 3
0
def promo_video_watch(context: Context,
                      actor_alias: str,
                      *,
                      play_time: int = None):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "play_video")
    page.play_video(context.driver, play_time=play_time)
    logging.debug("%s was able to play the video", actor_alias)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def language_selector_open(context: Context,
                           actor_alias: str,
                           *,
                           with_keyboard: bool = False):
    logging.debug("%s decided to go open language selector", actor_alias)
    page = get_last_visited_page(context, actor_alias)
    common_language_selector.open(context.driver,
                                  page=page,
                                  with_keyboard=with_keyboard)
Exemplo n.º 6
0
def actor_decides_to_enter_email_address_and_click_sign_up(
        context, actor_alias, email_address, password):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "sign_up")
    email_address = email_address.replace("xxxx",
                                          str(random.randint(6666, 9999)))
    page.sign_up(context.driver,
                 email_address=email_address,
                 password=password)
Exemplo n.º 7
0
def domestic_search_result_has_more_than_one_page(context: Context,
                                                  actor_alias: str,
                                                  min_page_num: int):
    should_be_on_page(
        context,
        actor_alias,
        f"{domestic.search_results.SERVICE} - {domestic.search_results.NAME}",
    )
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "has_pagination")
    page.has_pagination(context.driver, min_page_num)
Exemplo n.º 8
0
def domestic_search_finder_should_see_page_number(context: Context,
                                                  actor_alias: str,
                                                  page_num: int):
    should_be_on_page(
        context,
        actor_alias,
        f"{domestic.search_results.SERVICE} - {domestic.search_results.NAME}",
    )
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "should_see_page_number")
    page.should_see_page_number(context.driver, page_num)
Exemplo n.º 9
0
def generic_product_name_to_fill_country_and_click_on_continue(
        context, actor_alias, element_name, form_name):
    generic_fill_out(
        context,
        actor_alias,
        custom_details_table=context.table,
        form_name=form_name,
        check_captcha_dev_mode=False,
    )
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "searchcontinue")
    page.searchcontinue(context.driver)
Exemplo n.º 10
0
def click_on_link_element_in_page(context: Context,
                                  actor_alias: str,
                                  element_name: str,
                                  *,
                                  page_name: str = None):
    if page_name:
        page = get_page_object(page_name)
    else:
        page = get_last_visited_page(context, actor_alias)
    # logging.debug(page)
    has_action(page, "find_and_click")
    page.find_and_click(context.driver, element_selector_name=element_name)
Exemplo n.º 11
0
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()
Exemplo n.º 12
0
def click_on_page_element(context: Context,
                          actor_alias: str,
                          element_name: str,
                          *,
                          page_name: str = None):
    if page_name:
        page = get_page_object(page_name)
    else:
        page = get_last_visited_page(context, actor_alias)
    logging.debug(page)
    find_and_click_on_page_element(context.driver, page.SELECTORS,
                                   element_name)
    logging.debug("%s decided to click on '%s' on '%s' page", actor_alias,
                  element_name, page.NAME)
Exemplo n.º 13
0
def actor_select_random_data_click_continue_until_composition_page(
        context, actor_alias, max_number_pages):
    landed_on_composition_page = False
    counter = 0
    while counter < int(max_number_pages):
        counter += 1

        current_page_url = str(context.driver.current_url)
        # logging.debug(f"actor_select_random_data_click_continue_until_composition_page:current_page_url -> {current_page_url}")

        try:
            page = get_last_visited_page(context, actor_alias)
            has_action(page, "find_and_select_random_radio_and_click_continue")
            page.find_and_select_random_radio_and_click_continue(
                context.driver)
            # page = get_last_visited_page(context, actor_alias)
            # logging.debug(
            #     f"actor_select_random_data_click_continue_until_composition_page:get_last_visited_page ->  {page.NAME}")
            # should_be_on_page(context, actor_alias, f"Search - {page.NAMES[1]}")
            composition_text_element = context.driver.find_element_by_xpath(
                "//*[@id=\"composition_message\"]")
            composition_text = str(composition_text_element.text)
            # logging.debug(
            #     f"actor_select_random_data_click_continue_until_composition_page:composition_text ->  {composition_text}")

            if "The numbers need to add up to 100." in composition_text:
                landed_on_composition_page = True
                # logging.debug(
                #     f"actor_select_random_data_click_continue_until_composition_page:Reached Composition page!")
        except NoSuchElementException:
            logging.debug(
                f"actor_select_random_data_click_continue_until_composition_page:Couldn't reach Composition page after {counter} attempts!"
            )

        if landed_on_composition_page:
            break

    if not landed_on_composition_page:
        error = f"Couldn't reach Composition page after {max_number_pages} attempts!"
        assert False, error
Exemplo n.º 14
0
def actor_should_be_on_appropriate_page(context, actor_alias):
    page = get_last_visited_page(context, actor_alias)
    current_page_url = str(context.driver.current_url)
    # logging.debug(f"actor_should_be_on_appropriate_page:current_page_url -> {current_page_url}")
    is_refinement_page = False
    is_tradedata_page = False
    is_check_answers_page = False
    if "refine/?interaction" in current_page_url:
        is_refinement_page = True
    if "tradedata/?code" in current_page_url:
        is_tradedata_page = True
    if "check-your-answers" in current_page_url:
        is_check_answers_page = True

    if is_refinement_page:
        should_be_on_page(context, actor_alias,
                          "Search - Refinement interaction")
        return
    if is_tradedata_page:
        should_be_on_page(context, actor_alias, "Search - Tradedata Codes")
        return
    error = f"Landed on unrecognized page"
    assert False, error
Exemplo n.º 15
0
def actor_select_random_data_click_continue_until_tradedata_or_checkanswers_page(
        context, actor_alias, max_number_pages, is_trade_data_page,
        is_check_your_answers_page):
    landed_on_tradedata_page = False
    landed_on_checkanswers_page = False
    counter = 0
    while counter < int(max_number_pages):
        counter += 1
        page = get_last_visited_page(context, actor_alias)
        has_action(page, "find_and_select_random_radio_and_click_continue")
        page.find_and_select_random_radio_and_click_continue(context.driver)
        # time.sleep(1)
        current_page_url = str(context.driver.current_url)
        # logging.debug(f"actor_select_random_data_click_continue_until_tradedata_page:current_page_url -> {current_page_url}")
        if "tradedata/?code" in current_page_url and is_trade_data_page:
            landed_on_tradedata_page = True
            break
        if "check-your-answers" in current_page_url and is_check_your_answers_page:
            landed_on_checkanswers_page = True
            break

    if not landed_on_tradedata_page and not landed_on_checkanswers_page:
        error = f"Couldn't reach Tradedata or CheckYourAnswers page after {max_number_pages} attempts!"
        assert False, error
Exemplo n.º 16
0
def generic_select_dropdown_option(context: Context, actor_alias: str,
                                   dropdown: str, option: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "select_dropdown_option")
    page.select_dropdown_option(context.driver, dropdown, option)
Exemplo n.º 17
0
def office_finder_find_trade_office(context: Context, actor_alias: str,
                                    post_code: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "find_trade_office")
    page.find_trade_office(context.driver, post_code)
Exemplo n.º 18
0
def generic_unfold_elements_in_section(context: Context, actor_alias: str,
                                       section_name: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "unfold_elements_in_section")
    page.unfold_elements_in_section(context.driver, section_name)
Exemplo n.º 19
0
def generic_search_for_phrase(context: Context, actor_alias: str, phrase: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "search")
    page.search(context.driver, phrase)
Exemplo n.º 20
0
def soo_look_for_marketplace(context: Context, actor_alias: str, country: str,
                             category: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "search")
    page.search(context.driver, country, category)
Exemplo n.º 21
0
def generic_click_on_random_marketplace(context: Context, actor_alias: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "open_random_marketplace")
    page.open_random_marketplace(context.driver)
Exemplo n.º 22
0
def generic_click_on_random_industry(context: Context, actor_alias: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "open_any_article")
    page.open_any_article(context.driver)
Exemplo n.º 23
0
def generic_open_news_article(context: Context, actor_alias: str,
                              ordinal_number: str):
    ordinals = {"first": 1, "second": 2, "third": 3}
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "open_news_article")
    page.open_news_article(context.driver, ordinals[ordinal_number.lower()])
Exemplo n.º 24
0
def generic_download_all_pdfs(context: Context, actor_alias: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "download_all_pdfs")
    context.pdfs = page.download_all_pdfs(context.driver)
Exemplo n.º 25
0
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)
Exemplo n.º 26
0
def actor_should_be_able_to_click_on_i_have_exported_in_the_last_12_months(
        context, actor_alias):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "click_on_i_have_exported_in_the_last_12_months")
    page.click_on_i_have_exported_in_the_last_12_months(context.driver)
Exemplo n.º 27
0
def domestic_search_for_phrase_on_page(context: Context, actor_alias: str,
                                       phrase: str, page_name: str):
    visit_page(context, actor_alias, page_name)
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "search")
    page.search(context.driver, phrase)
Exemplo n.º 28
0
def generic_submit_form(context: Context, actor_alias: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "submit")
    page.submit(context.driver)
Exemplo n.º 29
0
def generic_visit_current_page_with_lang_parameter(context: Context,
                                                   actor_alias: str,
                                                   preferred_language: str):
    page = get_last_visited_page(context, actor_alias)
    url = urljoin(page.URL, f"?lang={preferred_language}")
    context.driver.get(url)
Exemplo n.º 30
0
def generic_report_problem_with_page(context: Context, actor_alias: str):
    page = get_last_visited_page(context, actor_alias)
    has_action(page, "report_problem")
    page.report_problem(context.driver)