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_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_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_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_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_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_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_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_xpath_repr(): path = TargetPath.region(By.XPATH, "//x") assert repr(path) == "TargetPath.region(By.XPATH, '//x')"
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")