def test_check_region_with_by_params(by, method_name="region"): value = "Selector" cs = get_cs_from_method(method_name, [by, value]) assert cs.values.target_selector == TargetPath.region(by, value) cs = get_cs_from_method(method_name, TargetPath.region(by, value)) assert cs.values.target_selector == TargetPath.region(by, value)
def __init__(self, target): # type: (Union[Region, Text, BySelector, Locator]) -> None if isinstance(target, string_types): self.target = TargetPath.region(target) elif is_list_or_tuple(target): self.target = TargetPath.region(*target) else: self.target = target self._hint = None # type: Optional[Text] self._language = "eng" # type: Optional[Text] self._min_match = None # type: Optional[float]
def test_match_regions_with_selectors_input(method_name): css_selector = ".cssSelector" regions = get_regions_from_(method_name, css_selector) assert regions[0]._target_path == TargetPath.region(css_selector) regions = get_regions_from_(method_name, TargetPath.region(css_selector)) assert regions[0]._target_path == TargetPath.region(css_selector) locator = [By.XPATH, "locator"] regions = get_regions_from_(method_name, locator, css_selector) assert regions[0]._target_path == TargetPath.region(By.XPATH, "locator") assert regions[1]._target_path == TargetPath.region( By.CSS_SELECTOR, css_selector)
def test_target_path_region_by_xpath(): path = TargetPath.region(By.XPATH, "//x") assert type(path) is RegionLocator assert path.by is By.XPATH assert path.selector == "//x" assert path.parent is None
def test_target_path_shadow_by_css(): path = TargetPath.shadow(".css") assert type(path) is ShadowDomLocator assert path.by is By.CSS_SELECTOR assert path.selector == ".css" assert path.parent is None
def test_transformed_selector_convert_region_by_css(): converted = TransformedSelector.convert(True, TargetPath.region(".css")) assert converted.type is By.CSS_SELECTOR assert converted.selector == ".css" assert converted.frame is None assert converted.shadow is None
def test_target_path_shadow_by_xpath(): path = TargetPath.shadow(By.XPATH, "//x") assert type(path) is ShadowDomLocator assert path.by is By.XPATH assert path.selector == "//x" assert path.parent is None
def test_target_path_region_by_css(): path = TargetPath.region(".css") assert type(path) is RegionLocator assert path.by is By.CSS_SELECTOR assert path.selector == ".css" assert path.parent is None
def test_match_accessibility_region(): regions = get_regions_from_("accessibility", [By.NAME, "name"], AccessibilityRegionType.BoldText) assert regions[0]._type == AccessibilityRegionType.BoldText assert regions[0]._target_path == TargetPath.region(By.NAME, "name") regions = get_regions_from_("accessibility", "name", AccessibilityRegionType.BoldText) assert regions[0]._type == AccessibilityRegionType.BoldText assert regions[0]._target_path == TargetPath.region( By.CSS_SELECTOR, "name") element = MagicMock(SeleniumWebElement) regions = get_regions_from_("accessibility", element, AccessibilityRegionType.BoldText) assert regions[0]._type == AccessibilityRegionType.BoldText assert regions[0]._element == element
def test_match_floating_region(): regions = get_regions_from_("floating", 5, [By.NAME, "name"]) assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5) assert regions[0]._target_path == TargetPath.region(By.NAME, "name") regions = get_regions_from_("floating", 5, "name") assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5) assert regions[0]._target_path == TargetPath.region("name") regions = get_regions_from_("floating", 5, TargetPath.region("name")) assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5) assert regions[0]._target_path == TargetPath.region("name") element = MagicMock(SeleniumWebElement) regions = get_regions_from_("floating", 5, element) assert regions[0]._bounds == FloatingBounds(5, 5, 5, 5) assert regions[0]._element == element
def test_transformed_selector_convert_target_by_name(): converted = TransformedSelector.convert(True, TargetPath.region(By.NAME, "name")) assert converted.type is By.CSS_SELECTOR assert converted.selector == '[name="name"]' assert converted.shadow is None assert converted.frame is None
def test_transformed_selector_convert_target_by_class_name(): converted = TransformedSelector.convert( True, TargetPath.region(By.CLASS_NAME, "class")) assert converted.type is By.CSS_SELECTOR assert converted.selector == ".class" assert converted.shadow is None assert converted.frame is None
def test_transformed_selector_convert_target_by_id(): converted = TransformedSelector.convert(True, TargetPath.region(By.ID, "id")) assert converted.type is By.CSS_SELECTOR assert converted.selector == '[id="id"]' assert converted.shadow is None assert converted.frame is None
def test_appium_transformed_selector_convert_target_by_id(): converted = TransformedSelector.convert(False, TargetPath.region(By.ID, "id")) assert converted.type is By.ID assert converted.selector == "id" assert converted.shadow is None assert converted.frame is None
def test_target_path_frame_by_css_selector(): path = TargetPath.frame(By.CSS_SELECTOR, ".css") assert type(path) is FrameLocator assert path.by is By.CSS_SELECTOR assert path.selector == ".css" assert path.number_or_id_or_name is None assert path.parent is None
def test_target_region_within_frame(): path = TargetPath.frame(1).region(".css") assert type(path) is RegionLocator assert path.by is By.CSS_SELECTOR assert path.selector == ".css" assert type(path.parent) is FrameLocator assert path.parent.number_or_id_or_name == 1
def test_appium_transformed_selector_convert_target_by_name(): converted = TransformedSelector.convert(False, TargetPath.region(By.NAME, "name")) assert converted.type is By.NAME assert converted.selector == "name" assert converted.shadow is None assert converted.frame is None
def test_target_path_frame_by_number(): path = TargetPath.frame(1) assert type(path) is FrameLocator assert path.by is None assert path.selector is None assert path.number_or_id_or_name == 1 assert path.parent is None
def test_target_path_frame_region_eq(): assert TargetPath.frame(1).region(".css") == TargetPath.frame(1).region( ".css") assert TargetPath.frame(1).region(".css") != TargetPath.frame(1).region( "#id") assert TargetPath.frame(1).region(".css") != TargetPath.frame(2).region( ".css")
def test_check_frame(method_name="frame"): frame_reference = "frame-name-or-id" cs = get_cs_from_method(method_name, frame_reference) assert cs.values.frame_chain[0].frame_name_or_id == frame_reference frame_selector = [By.ID, "some-selector"] cs = get_cs_from_method(method_name, frame_selector) assert cs.values.frame_chain[0].frame_selector == TargetPath.frame( By.ID, "some-selector") frame_index = 3 cs = get_cs_from_method(method_name, frame_index) assert cs.values.frame_chain[0].frame_index == frame_index
def test_transformed_selector_convert_shadow_by_xpath_shadow_by_css_region_by_css( ): converted = TransformedSelector.convert( True, TargetPath.shadow(By.XPATH, "//x").shadow("#s").region(".css")) assert converted.type is By.XPATH assert converted.selector == "//x" assert converted.frame is None assert type(converted.shadow) is TransformedSelector assert converted.shadow.type is By.CSS_SELECTOR assert converted.shadow.selector == "#s" assert converted.shadow.frame is None assert type(converted.shadow.shadow) is TransformedSelector assert converted.shadow.shadow.type is By.CSS_SELECTOR assert converted.shadow.shadow.selector == ".css" assert converted.shadow.shadow.frame is None assert converted.shadow.shadow.shadow is None
def test_match_regions_with_by_values(method_name): by_name = [By.NAME, "some-name"] by_id = [By.ID, "ident"] by_class = [By.CLASS_NAME, "class_name"] by_tag_name = [By.TAG_NAME, "tag_name"] by_css_selector = [By.CSS_SELECTOR, "css_selector"] by_xpath = [By.XPATH, "xpath"] regions = get_regions_from_(method_name, by_name, by_id, by_class, by_tag_name, by_css_selector, by_xpath) assert regions[0]._target_path == TargetPath.region(By.NAME, "some-name") assert regions[1]._target_path == TargetPath.region(By.ID, "ident") assert regions[2]._target_path == TargetPath.region( By.CLASS_NAME, "class_name") assert regions[3]._target_path == TargetPath.region( By.TAG_NAME, "tag_name") assert regions[4]._target_path == TargetPath.region( By.CSS_SELECTOR, "css_selector") assert regions[5]._target_path == TargetPath.region(By.XPATH, "xpath")
def test_target_path_region_css_repr(): path = TargetPath.region(".css") assert repr(path) == "TargetPath.region('.css')"
def test_target_path_region_eq(): assert TargetPath.region(".css") == TargetPath.region(".css") assert TargetPath.region(".css") != TargetPath.region("#id")
def test_target_path_frame_shadow_region_repr(): path = TargetPath.frame(1).shadow("#shadow").region(".region") assert repr( path) == "TargetPath.frame(1).shadow('#shadow').region('.region')"
def test_target_path_shadow_css_region_css_repr(): path = TargetPath.shadow("#shadow").region(".region") assert repr(path) == "TargetPath.shadow('#shadow').region('.region')"
def test_target_path_frame_css_repr(): path = TargetPath.frame(By.CSS_SELECTOR, ".css") assert repr(path) == "TargetPath.frame(By.CSS_SELECTOR, '.css')"
def test_target_path_region_xpath_repr(): path = TargetPath.region(By.XPATH, "//x") assert repr(path) == "TargetPath.region(By.XPATH, '//x')"
def test_target_path_shadow_css_repr(): path = TargetPath.shadow(".css") assert repr(path) == "TargetPath.shadow('.css')"
def test_target_path_frame_name_repr(): path = TargetPath.frame("frame") assert repr(path) == "TargetPath.frame('frame')"