예제 #1
0
def eyes_vg(vg_runner, sel_config, batch_info, driver, request, test_page_url):
    app_name = request.node.get_closest_marker("app_name")
    if app_name:
        app_name = app_name.args[0]
    test_name = request.node.get_closest_marker("test_name")
    if test_name:
        test_name = test_name.args[0]
    viewport_size = request.node.get_closest_marker("viewport_size")
    if viewport_size:
        viewport_size = viewport_size.args[0]
    else:
        viewport_size = None

    eyes = Eyes(vg_runner)
    eyes.server_url = "https://eyes.applitools.com/"
    eyes.configuration = sel_config
    eyes.configuration.batch = batch_info
    app_name = app_name or eyes.configuration.app_name
    test_name = test_name or eyes.configuration.test_name
    viewport_size = viewport_size or eyes.configuration.viewport_size

    driver.get(test_page_url)
    eyes.open(driver, app_name, test_name, viewport_size)
    yield eyes
    logger.debug("closing WebDriver for url {}".format(test_page_url))
    eyes.close()
예제 #2
0
def driver(request, browser_config, webdriver_module):
    # type: (SubRequest, dict, webdriver) -> typing.Generator[dict]
    test_name = request.node.name
    test_page_url = request.node.get_closest_marker("test_page_url")
    test_page_url = test_page_url.args[-1] if test_page_url else None

    force_remote = bool(os.getenv("TEST_REMOTE", False))
    if "appiumVersion" in browser_config:
        force_remote = True

    if force_remote:
        sauce_url = "https://{username}:{password}@ondemand.saucelabs.com:443/wd/hub".format(
            username=os.getenv("SAUCE_USERNAME", None),
            password=os.getenv("SAUCE_ACCESS_KEY", None),
        )
        selenium_url = os.getenv("SELENIUM_SERVER_URL", sauce_url)
        logger.debug("SELENIUM_URL={}".format(selenium_url))

        desired_caps = browser_config.copy()
        desired_caps["build"] = os.getenv("BUILD_TAG", None)
        desired_caps["tunnelIdentifier"] = os.getenv("TUNNEL_IDENTIFIER", None)
        desired_caps["name"] = test_name

        browser = webdriver_module.Remote(command_executor=selenium_url,
                                          desired_capabilities=desired_caps)
    else:
        # Use local browser. Use ENV variable for driver binary or install if no one.
        driver_manager_class, webdriver_class, options = BROWSERS_WEBDRIVERS.get(
            browser_config["browserName"])
        if options:
            headless = strtobool(os.getenv("TEST_BROWSER_HEADLESS", "True"))
            options = options()
            options.headless = bool(headless)
        if driver_manager_class:
            browser = webdriver_class(
                executable_path=driver_manager_class().install(),
                options=options)
        else:
            browser = webdriver_class()

    if browser is None:
        raise WebDriverException("Never created!")

    if test_page_url:
        browser.get(test_page_url)
        logger.info("navigation to URL: {}".format(test_page_url))

    yield browser

    # report results
    try:
        browser.execute_script("sauce:job-result=%s" %
                               str(not request.node.rep_call.failed).lower())
    except WebDriverException:
        # we can ignore the exceptions of WebDriverException type -> We're done with tests.
        logger.info(
            "Warning: The driver failed to quit properly. Check test and server side logs."
        )
    finally:
        browser.quit()
예제 #3
0
def test_viewports_test(driver, batch_info):
    runner = VisualGridRunner(30)
    eyes = Eyes(runner)

    sconf = Configuration()
    sconf.batch = batch_info
    sconf.test_name = "Viewport Size Test"
    sconf.app_name = "Visual Grid Viewports Test"
    sconf.hide_scrollbars = True
    sconf.stitch_mode = StitchMode.CSS
    sconf.force_full_page_screenshot = True
    sconf.match_level = MatchLevel.STRICT

    sconf.add_browser(800, 600, BrowserType.CHROME)
    sconf.add_browser(700, 500, BrowserType.CHROME)
    sconf.add_browser(1200, 800, BrowserType.CHROME)
    sconf.add_browser(1600, 1200, BrowserType.CHROME)
    sconf.add_browser(800, 600, BrowserType.FIREFOX)
    sconf.add_browser(700, 500, BrowserType.FIREFOX)
    sconf.add_browser(1200, 800, BrowserType.FIREFOX)
    sconf.add_browser(1600, 1200, BrowserType.FIREFOX)
    sconf.add_browser(800, 600, BrowserType.EDGE)
    sconf.add_browser(700, 500, BrowserType.EDGE)
    sconf.add_browser(1200, 800, BrowserType.EDGE)
    # sconf.add_browser(1600, 1200, BrowserType.EDGE)
    sconf.add_browser(800, 600, BrowserType.IE_11)
    sconf.add_browser(700, 500, BrowserType.IE_11)
    sconf.add_browser(1200, 800, BrowserType.IE_11)
    # sconf.add_browser(1600, 1200, BrowserType.IE_11)
    sconf.add_browser(800, 600, BrowserType.IE_10)
    sconf.add_browser(700, 500, BrowserType.IE_10)
    sconf.add_browser(1200, 800, BrowserType.IE_10)
    # sconf.add_browser(1600, 1200, BrowserType.IE_10)
    eyes.set_configuration(sconf)

    eyes.open(driver)
    driver.get("https://www.applitools.com")
    eyes.check("Test Viewport", Target.window().fully())
    eyes.close_async()

    all_results = runner.get_all_test_results(False)
    assert len(sconf.browsers_info) > len(BrowserType)
    assert len(all_results) == len(sconf.browsers_info)

    results = defaultdict(set)
    for trc in all_results:
        assert trc
        session_results = None
        try:
            session_results = get_session_results(eyes.api_key, trc.test_results)
        except Exception as e:
            logger.exception(e)

        if session_results is None:
            logger.debug("Error: session_results is null for item {}".format(trc))
            continue

        env = session_results["env"]
        browser = env["hostingAppInfo"]
        if browser is None:
            logger.debug("Error: HostingAppInfo (browser) is null. {}".format(trc))
            continue

        sizes_list = results[browser]
        display_size = RectangleSize.from_(env["displaySize"])
        if display_size in sizes_list:
            assert (
                False
            ), "Browser {} viewport size {} already exists in results.".format(
                browser, display_size
            )
        sizes_list.add(display_size)
    assert len(results) == 5