def test_rendering_ios_simulator(driver, batch_info, vg_runner):
    driver.get("http://applitools.github.io/demo")
    eyes = Eyes(vg_runner)
    eyes.set_configuration(
        Configuration(
            app_name="Eyes SDK",
            test_name="UFG Mobile Web Happy Flow",
            batch=batch_info,
        )
        .add_browser(
            IosDeviceInfo(IosDeviceName.iPhone_XR, ScreenOrientation.LANDSCAPE)
        )
        .add_browser(
            IosDeviceInfo(IosDeviceName.iPhone_XR, ios_version=IosVersion.LATEST)
        )
        .add_browser(
            IosDeviceInfo(
                IosDeviceName.iPhone_XR, ios_version=IosVersion.ONE_VERSION_BACK
            )
        )
        .set_save_diffs(False)
        .set_save_new_tests(False)
    )
    eyes.open(driver, viewport_size=RectangleSize(800, 600))
    eyes.check_window()
    eyes.close_async()
    assert len(vg_runner.get_all_test_results()) == 3
def test_mobile_web_happy_flow(driver, batch_info, vg_runner):
    driver.get("https://applitools.github.io/demo")
    eyes = Eyes(vg_runner)
    eyes.set_configuration(
        Configuration(
            app_name="Eyes SDK",
            test_name="UFG Mobile Web Happy Flow",
            batch=batch_info,
        ).add_browser(
            IosDeviceInfo(IosDeviceName.iPhone_12,
                          ScreenOrientation.LANDSCAPE)))
    eyes.open(driver, viewport_size=RectangleSize(800, 600))
    eyes.check_window()
    eyes.close()
def test_inferred_layout_breakpoints_with_small_devices(driver, batch_info, vg_runner):
    driver.get("https://applitools.github.io/demo/TestPages/JsLayout")
    eyes = Eyes(vg_runner)
    eyes.set_configuration(
        Configuration(
            app_name="Eyes SDK",
            test_name="UFG Layout Breakpoints inferred small screen device",
            batch=batch_info,
        )
        .add_browser(
            IosDeviceInfo(IosDeviceName.iPhone_12, ScreenOrientation.LANDSCAPE)
        )
        .add_browser(IosDeviceInfo(IosDeviceName.iPhone_12, ScreenOrientation.PORTRAIT))
        .add_browser(1024, 768, BrowserType.CHROME)
        .set_layout_breakpoints(True)
    )
    eyes.open(driver, viewport_size=RectangleSize(800, 600))
    eyes.check_window()
    eyes.close()
def test_inferred_layout_breakpoints(driver, batch_info, vg_runner):
    driver.get("https://applitools.github.io/demo/TestPages/JsLayout")
    eyes = Eyes(vg_runner)
    eyes.set_configuration(
        Configuration(
            app_name="Eyes SDK",
            test_name="UFG Layout Breakpoints inferred chrome",
            batch=batch_info,
        )
        .add_browser(500, 400, BrowserType.CHROME)
        .add_browser(800, 400, BrowserType.CHROME)
        .add_browser(800, 600, BrowserType.CHROME)
        .add_browser(1024, 768, BrowserType.CHROME)
        .add_browser(1200, 800, BrowserType.CHROME)
        .set_layout_breakpoints(True)
    )
    eyes.open(driver, viewport_size=RectangleSize(800, 600))
    eyes.check_window()
    eyes.close()
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
def test_viewport_size_trafaret():
    expected_red = RectangleSize(400, 400)
    res = ViewPortTrafaret().check({"width": 400, "height": 400})
    assert res == expected_red
    res = ViewPortTrafaret().check("[400 400]")
    assert res == expected_red