def _test_read_gives_expected_results(client, system_dir): # Get the values for this client: read_devices = [] for device in client.devices.connected_devices: name = device.__class__.__name__ values = {} for value in device.fields([Mode.R, Mode.RW]): values[value.field.name] = { "implemented": value.implemented, "scale_factor": None if value.scale_factor is None else value.scale_factor.value, "raw_value": value.raw_value if value.raw_value is None or isinstance(value.raw_value, (str, int, float)) else repr(value.raw_value), "value": value.value if value.value is None or isinstance(value.value, (str, int, float)) else repr(value.value), } read_devices.append({"name": name, "address": device.address, "values": values}) # Compare them with what we expect: with open(system_dir / "expected.json") as f: expected_devices = json.load(f) assert check_objects(expected_devices, read_devices)
def test_send_DOM_full_window(dom_intercepting_eyes, driver, batch_info, expected_json): config = ( Configuration().set_batch(batch_info).set_app_name( "Test Send DOM").set_test_name("Full Window").set_viewport_size( RectangleSize(1024, 768)) # TODO: Remove this when default options get in sync for java and python SDK .set_hide_scrollbars(True)) dom_intercepting_eyes.set_configuration(config) driver.get("https://applitools.github.io/demo/TestPages/FramesTestPage/") dom_intercepting_eyes.open(driver, "Test Send DOM", "Full Window") dom_intercepting_eyes.check("Window", Target.window().fully()) results = dom_intercepting_eyes.close(False) actual = json.loads(dom_intercepting_eyes.captured_dom_json) received_back = get_step_DOM(dom_intercepting_eyes, results) # Make next asserts script-version independent del expected_json["scriptVersion"] del actual["scriptVersion"] del received_back["scriptVersion"] assert get_has_DOM(dom_intercepting_eyes.api_key, results) assert check_objects(actual, expected_json) assert check_objects(received_back, expected_json)
def _test_read_gives_expected_results(client, system_dir): # Get the values for this client: read_devices = [] for device in client.devices.connected_devices: name = device.__class__.__name__ values = {} for value in device.fields([Mode.R, Mode.RW]): values[value.field.name] = value.to_dict() read_devices.append({"name": name, "address": device.address, "values": values}) # Compare them with what we expect: with open(system_dir / "expected.json") as f: expected_devices = json.load(f) assert check_objects(expected_devices, read_devices)
def test_known_system(subtests, system_dir): # Read it (which is a test in itself) with Mate3Client( host=None, cache_path=system_dir / "modbus.json", cache_only=True, cache_writeable=False ) as client: with subtests.test("Reading gives expected results"): _test_read_gives_expected_results(client, system_dir) with subtests.test("Writing the same values back gives the same results"): # ... 'cos if that isn't the case, it implies we're serialising/deserialising incorrectly. cache = {k: v for k, v in client._client._cache.items()} for device in client.devices.connected_devices: # NB: ignoring Mode.W as we can't read the value to be able to write it back i.e. we don't know what to # write. for value in device.fields(modes=[Mode.RW]): if value.implemented: value.write(value.value) new_cache = client._client._cache assert check_objects(cache, new_cache)
def test_send_dom_cors_iframe(dom_intercepting_eyes, driver, batch_info, expected_json, caplog): del expected_json["scriptVersion"] config = ( Configuration().set_batch(batch_info).set_app_name("Test Send DOM"). set_test_name("test_send_dom_cors_iframe").set_viewport_size( RectangleSize(1024, 768)) # TODO: Remove this when default options get in sync for java and python SDK .set_hide_scrollbars(True)) dom_intercepting_eyes.set_configuration(config) driver.get("https://applitools.github.io/demo/TestPages/CorsTestPage") dom_intercepting_eyes.open(driver, "Test Send DOM", "test_send_dom_cors_iframe") dom_intercepting_eyes.check("Window", Target.window().fully()) dom_intercepting_eyes.close(False) actual = json.loads(dom_intercepting_eyes.captured_dom_json) del actual["scriptVersion"] assert check_objects(actual, expected_json) assert "ERROR" not in caplog.text