Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
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.º 4
0
def profile_start_registration_as(context: Context, actor_alias: str,
                                  business_type: str):
    if not get_actor(context, actor_alias):
        add_actor(context, unauthenticated_actor(actor_alias))
    profile.enrol_select_business_type.visit(context.driver)
    second_page = profile.enrol_select_business_type.pick_radio_option_and_submit(
        context.driver, name=business_type)
    should_be_on_page(context, actor_alias,
                      f"{second_page.SERVICE} - {second_page.NAME}")
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def sign_in(context: Context, actor_alias: str):
    actor = get_actor(context, actor_alias)
    email = actor.email
    password = actor.password
    sso.sign_in.visit(context.driver)
    take_screenshot(context.driver, sso.sign_in.NAME)
    sso.sign_in.should_be_here(context.driver)
    sso.sign_in.fill_out(context.driver, email, password)
    sso.sign_in.submit(context.driver)
    take_screenshot(context.driver, "after signing in")
    check_for_errors(context.driver.page_source, context.driver.current_url)
Exemplo n.º 7
0
def registration_open_email_confirmation_link(context: Context,
                                              actor_alias: str):
    """Given Supplier has received a message with email confirmation link
    Then Supplier has to click on that link.
    """
    actor = get_actor(context, actor_alias)
    link = actor.email_confirmation_link

    # Step 1 - open confirmation link
    context.driver.get(link)

    # Step 3 - confirm that Supplier is on SSO Confirm Your Email page
    sso.confirm_your_email.should_be_here(context.driver)
    logging.debug("Supplier is on the SSO Confirm your email address page")
Exemplo n.º 8
0
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,
    )
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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,
    )