def test_create_dom_snapshot_disable_cross_origin_rendering(driver):
    driver = EyesWebDriver(driver, None)
    driver.get("https://applitools.github.io/demo/TestPages/CorsTestPage/")

    dom = create_dom_snapshot(driver, False, [], 10000, False)

    assert len(dom["frames"][0]["frames"]) == 0
Beispiel #2
0
def test_measure_ensure_sync_with_underlying_driver_performance(
    driver,
    eyes,
    page_desc,
    url,
    far_frame_path,
    load_time,
    test_desc,
    driver_frames,
    eyes_frames,
    i,
):
    driver_frames = far_frame_path if driver_frames == "far" else driver_frames
    eyes_frames = far_frame_path if eyes_frames == "far" else eyes_frames
    driver.get(url)
    time.sleep(load_time)
    eyes_driver = EyesWebDriver(driver, eyes)
    for n in eyes_frames:
        eyes_driver.switch_to.frame(n)
    for n in driver_frames:
        driver.switch_to.frame(n)
    ts = time.monotonic()
    eyes_driver.ensure_sync_with_underlying_driver()
    r = time.monotonic() - ts
    with open("ensure_sync_with_underlying_driver_perf.txt", "a") as f:
        f.write("{page_desc}; {test_desc}; {i}; {r:.0f}\n".format(
            page_desc=page_desc, test_desc=test_desc, i=i, r=r * 1000))
def test_execute_script_with_eyes_webelement(driver, eyes):
    elem = driver.find_element_by_tag_name("html")
    e_elem = EyesWebElement(elem, driver)
    driver.execute_script("arguments[0].scrollIntoView();", elem)

    eyes_driver = EyesWebDriver(driver, eyes)
    eyes_driver.execute_script("arguments[0].scrollIntoView();", elem)
    eyes_driver.execute_script("arguments[0].scrollIntoView();", e_elem)
def test_create_dom_snapshot_has_cors_iframe_data(driver):
    driver = EyesWebDriver(driver, None)
    driver.get("https://applitools.github.io/demo/TestPages/CorsTestPage/")

    dom = create_dom_snapshot(driver, False, [], 10000, True)

    assert len(dom["frames"][0]["frames"]) == 1
    assert (dom["frames"][0]["frames"][0]["url"] ==
            "https://afternoon-savannah-68940.herokuapp.com/#")
def test_create_dom_snapshot_with_cors_iframe(driver):
    driver = EyesWebDriver(driver, None)
    driver.get("https://applitools.github.io/demo/TestPages/CorsTestPage/")

    dom = create_dom_snapshot(driver, False, [], 10000, True)

    assert len(dom["frames"][0]["crossFrames"]) == 1
    assert dom["frames"][0]["crossFrames"][0]["index"] == 16
    assert "selector" in dom["frames"][0]["crossFrames"][0]
Beispiel #6
0
def test_iframe_unselected_with_raw_selenium_driver_is_synced(eyes, driver):
    driver.get(
        "https://applitools.github.io/demo/TestPages/CorsTestPage/index.html")
    eyes_driver = EyesWebDriver(driver, eyes)

    eyes_driver.switch_to.frame(0)
    driver.switch_to.default_content()
    eyes_driver.ensure_sync_with_underlying_driver()

    assert eyes_driver.frame_chain.peek is None
def driver_for_class(request, driver):
    viewport_size = request.node.get_closest_marker("viewport_size").args[0]

    driver = EyesWebDriver(driver, MagicMock(Eyes))
    driver.quit = MagicMock()
    if viewport_size:
        eyes_selenium_utils.set_browser_size(driver, viewport_size)
    request.cls.driver = driver

    yield
    driver.quit()
Beispiel #8
0
def driver_for_class(request, driver):
    test_page_url = request.node.get_closest_marker("test_page_url").args[0]
    viewport_size = request.node.get_closest_marker("viewport_size").args[0]

    driver = EyesWebDriver(driver, None)
    if viewport_size:
        eyes_selenium_utils.set_browser_size(driver, viewport_size)
    request.cls.driver = driver

    driver.get(test_page_url)
    yield
Beispiel #9
0
def test_iframe_selected_with_raw_selenium_driver_is_synced(eyes, driver):
    driver.get(
        "https://applitools.github.io/demo/TestPages/CorsTestPage/index.html")
    eyes_driver = EyesWebDriver(driver, eyes)

    driver.switch_to.frame(0)
    driver.switch_to.frame(0)
    eyes_driver.ensure_sync_with_underlying_driver()

    assert (eyes_driver.frame_chain.peek.scroll_root_element.get_attribute(
        "class") == "no-js")
def test_driver_useragent_splits_version(version, major, minor):
    driver_mock, eyes_mock = MagicMock(), MagicMock()
    driver_mock.desired_capabilities = {
        "platformName": "Android",
        "deviceName": "Pixel",
        "platformVersion": version,
        "app": "a.apk",
    }
    webderiver = EyesWebDriver(driver_mock, eyes_mock)

    assert webderiver.user_agent.os_major_version == major
    assert webderiver.user_agent.os_minor_version == minor
def test_driver_and_element_dir(eyes, driver):
    driver.get("https://applitools.com/helloworld/")

    eyes_driver = EyesWebDriver(driver, eyes)
    _dir = dir(eyes_driver)
    assert all(elem in _dir for elem in dir(driver)
               if not elem.startswith("_"))

    element = driver.find_element_by_xpath("//div[@class='demo-page center']")
    eyes_element = eyes_driver.find_element_by_xpath(
        "//div[@class='demo-page center']")
    _dir = dir(eyes_element)
    assert all(elem in _dir for elem in dir(element)
               if not elem.startswith("_"))
def test_find_inside_element(eyes, driver):
    driver.get("file://{}".format(
        get_resource_path("unit/multiple-selects.html")))

    eyes_driver = EyesWebDriver(driver, eyes)
    element = driver.find_element_by_xpath("//select[contains(@id, 'device')]")
    eyes_element = eyes_driver.find_element_by_xpath(
        "//select[contains(@id, 'device')]")
    assert element.find_element_by_xpath(
        '//option[@selected="selected"]'
    ) == eyes_element.find_element_by_xpath('//option[@selected="selected"]')
    assert element.find_elements(By.TAG_NAME,
                                 "options") == eyes_element.find_elements(
                                     By.TAG_NAME, "options")
def test_element_find_element(eyes, driver):
    driver.get("https://applitools.com/helloworld/")
    # Locate element
    element = driver.find_element_by_xpath("//div[@class='demo-page center']")
    element.find_element(By.XPATH, "//a[contains(@href, 'diff1')]").click()

    eyes_driver = EyesWebDriver(driver, eyes)
    # Navigate the browser to the "hello world!" web-site.
    eyes_driver.get("https://applitools.com/helloworld/")

    # Locate element
    element = eyes_driver.find_element_by_xpath(
        "//div[@class='demo-page center']")
    element.find_element(By.XPATH, "//a[contains(@href, 'diff1')]").click()
def test_new_tab(eyes, driver):
    driver.get("https://the-internet.herokuapp.com/windows")
    driver.find_element_by_xpath("//a[contains(@href, 'new')]").click()

    # Switch to other tab / close / switch to the original tab
    driver.switch_to.window(driver.window_handles[1])
    driver.close()
    driver.switch_to.window(driver.window_handles[0])

    # Now use the eyes driver for the same thing...
    eyes_driver = EyesWebDriver(driver, eyes)
    eyes_driver.get("https://the-internet.herokuapp.com/windows")
    eyes_driver.find_element_by_xpath("//a[contains(@href, 'new')]").click()

    eyes_driver.switch_to.window(eyes_driver.window_handles[1])
    eyes_driver.close()
    eyes_driver.switch_to.window(eyes_driver.window_handles[0])
def test_eyes_element_and_element_with_Select(eyes, driver):
    driver.get("file://{}".format(
        get_resource_path("unit/multiple-selects.html")))

    eyes_driver = EyesWebDriver(driver, eyes)

    element = driver.find_element_by_xpath("//select[contains(@id, 'device')]")
    sel_select = Select(element)
    sel_options = sel_select.options
    for index, option in enumerate(sel_options):
        option.click()

    eyes_element = eyes_driver.find_element_by_xpath(
        "//select[contains(@id, 'device')]")
    eyes_select = Select(eyes_element)
    eyes_options = eyes_select.options
    for index, option in enumerate(eyes_options):
        option.click()

    assert sel_options == eyes_options
    assert sel_select.all_selected_options == eyes_select.all_selected_options
    assert sel_select.first_selected_option == eyes_select.first_selected_option
Beispiel #16
0
def test_create_dom_snapshot_retries_on_single_failure(driver, monkeypatch):
    create_dom_snapshot_loop = dom_snapshot_script.create_dom_snapshot_loop

    def failing_once_loop(*args, **kwargs):
        failing_once_loop.call_count += 1
        if failing_once_loop.call_count == 2:
            raise Exception
        else:
            return create_dom_snapshot_loop(*args, **kwargs)

    failing_once_loop.call_count = 0
    monkeypatch.setattr(
        dom_snapshot_script, "create_dom_snapshot_loop", failing_once_loop
    )

    driver = EyesWebDriver(driver, None)
    driver.get("https://applitools.github.io/demo/TestPages/CorsTestPage/")

    dom = create_dom_snapshot(driver, False, [], 1000000, True)

    assert len(dom["frames"][0]["crossFrames"]) == 1
    assert dom["frames"][0]["crossFrames"][0]["index"] == 16
    assert "selector" in dom["frames"][0]["crossFrames"][0]