예제 #1
0
def open_any_tag(driver: WebDriver) -> str:
    links = find_elements(driver, TAGS)
    assert len(links) > 0
    link = links[random.randint(1, len(links)) - 1]
    tag = link.text.lower()
    link.click()
    return tag
예제 #2
0
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
예제 #3
0
def open_any_article(driver: WebDriver) -> str:
    article_links = find_elements(driver, ADVICE_ARTICLE_LINKS)
    link = random.choice(article_links)
    link_text = link.text
    check_if_element_is_visible(link, element_name=link_text)
    with wait_for_page_load_after_action(driver):
        link.click()
    return link_text
예제 #4
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()
def enrol_autocomplete_company_name(driver: WebDriver, value: str = None):
    """Value is ignored as we want to choose random company name"""
    autocomplete = Selector(
        By.CSS_SELECTOR, "ul.SelectiveLookupDisplay", is_visible=True
    )
    find_element(driver, autocomplete, element_name="Autocomplete", wait_for_it=True)
    options = find_elements(driver, Selector(By.CSS_SELECTOR, "li[role='option']"))
    option = random.choice(options)
    logging.debug(
        f"Selected company: {option.get_attribute('data-value')} {option.text}"
    )
    option.click()
예제 #6
0
def autocomplete_company_name(driver: WebDriver):
    autocomplete = Selector(
        By.CSS_SELECTOR, "ul.SelectiveLookupDisplay", is_visible=True
    )
    find_element(driver, autocomplete, element_name="Autocomplete", wait_for_it=True)
    options = find_elements(
        driver, Selector(By.CSS_SELECTOR, "li[role='option']", is_visible=True)
    )
    option = random.choice(options)
    logging.debug(
        f"Autocomplete selected country name: {option.get_attribute('data-value')} {option.text}"
    )
    option.click()
예제 #7
0
def click_on_result_of_type(driver: WebDriver, type_of: str):
    results = find_elements(driver, SEARCH_RESULTS)
    results_of_matching_type = [
        result
        for result in results
        if result.find_element_by_css_selector("span.type").text.lower()
        == type_of.lower()
    ]

    with assertion_msg(
        f"Expected to see at least 1 search result of type '{type_of}' but found none"
    ):
        assert results_of_matching_type
    logging.debug(f"Found {len(results_of_matching_type)} results of type '{type_of}'")
    result = random.choice(results_of_matching_type)
    result_link = result.find_element_by_css_selector("a")
    logging.debug(
        f"Will click on {result_link.text} -> {result_link.get_property('href')}"
    )
    result_link.click()
예제 #8
0
def should_see_marketplaces(driver: WebDriver, country: str):
    expected_countries = [country, "Global"]
    markets_selector = Selector(By.CSS_SELECTOR, "div.market-item-inner")
    marketplace_countries = {
        marketplace.find_element_by_tag_name("a")
        .text: marketplace.find_element_by_css_selector(
            "div.market-item-inner p.market-operating-countries"
        )
        .text
        for marketplace in find_elements(driver, markets_selector)
    }

    error = f"Found marketplace without a list of countries it operates in"
    assert marketplace_countries, error

    for marketplace, countries in marketplace_countries.items():
        with assertion_msg(
            f"{marketplace} does not operate in '{country}' or Globally!"
            f"but in '{countries}' instead"
        ):
            assert any(country in countries for country in expected_countries)
            logging.debug(
                f"{marketplace} operates in '{country}' or Globally! -> {countries}"
            )
예제 #9
0
def open_news_article(driver: WebDriver, article_number: int):
    article_links = find_elements(driver, ARTICLES)
    assert len(article_links) >= article_number
    article_links[article_number - 1].click()
예제 #10
0
def open_random_marketplace(driver: WebDriver):
    selector = Selector(By.CSS_SELECTOR, "#random-markets a.card-link")
    links = find_elements(driver, selector)
    random.choice(links).click()
예제 #11
0
def open_random_marketplace(driver: WebDriver):
    selector = Selector(By.CSS_SELECTOR, "div.market-item-inner a.market-header-link")
    link = random.choice(find_elements(driver, selector))
    logging.debug(f"Clicked on {link.text}")
    link.click()