def test_registered_strategy_can_be_used_as_prefix(): _verify_parse_locator("registered=no", "default", "registered=no") _verify_parse_locator("registered:no", "default", "registered:no") finder = ElementFinder(None) finder.register("registered", lambda *args: None, persist=True) _verify_parse_locator("registered=yes!!", "registered", "yes!!", finder) _verify_parse_locator("registered:yes!!", "registered", "yes!!", finder)
def test_registered_strategy_can_be_used_as_prefix(): _verify_parse_locator('registered=no', 'default', 'registered=no') _verify_parse_locator('registered:no', 'default', 'registered:no') finder = ElementFinder(None) finder.register('registered', lambda *args: None, persist=True) _verify_parse_locator('registered=yes!!', 'registered', 'yes!!', finder) _verify_parse_locator('registered:yes!!', 'registered', 'yes!!', finder)
class ParseLocatorTests(unittest.TestCase): def setUp(self): self.finder = ElementFinder(None) def test_implicit_xpath(self): self._verify_parse_locator('//foo', 'xpath', '//foo') self._verify_parse_locator('(//foo)', 'xpath', '(//foo)') self._verify_parse_locator('//id=bar', 'xpath', '//id=bar') def test_no_separator(self): self._verify_parse_locator('foo', 'default', 'foo') self._verify_parse_locator('', 'default', '') def test_equal_sign_as_separator(self): self._verify_parse_locator('class=foo', 'class', 'foo') self._verify_parse_locator('id=foo=bar', 'id', 'foo=bar') def test_colon_as_separator(self): self._verify_parse_locator('class:foo', 'class', 'foo') self._verify_parse_locator('id:foo:bar', 'id', 'foo:bar') def test_use_first_separator_when_both_are_used(self): self._verify_parse_locator('id:foo=bar', 'id', 'foo=bar') self._verify_parse_locator('id=foo:bar', 'id', 'foo:bar') def test_preserve_trailing_whitespace(self): self._verify_parse_locator('//foo/bar ', 'xpath', '//foo/bar ') self._verify_parse_locator('class=foo ', 'class', 'foo ') def test_remove_whitespace_around_prefix_and_separator(self): self._verify_parse_locator('class = foo', 'class', 'foo') self._verify_parse_locator('class : foo', 'class', 'foo') self._verify_parse_locator(' id = foo = bar ', 'id', 'foo = bar ') self._verify_parse_locator(' id : foo : bar ', 'id', 'foo : bar ') def test_separator_without_matching_prefix_is_ignored(self): self._verify_parse_locator('no=match', 'default', 'no=match') self._verify_parse_locator('no:match', 'default', 'no:match') def test_registered_strategy_can_be_used_as_prefix(self): self._verify_parse_locator('registered=no', 'default', 'registered=no') self._verify_parse_locator('registered:no', 'default', 'registered:no') self.finder.register('registered', lambda *args: None, persist=True) self._verify_parse_locator('registered=yes!!', 'registered', 'yes!!') self._verify_parse_locator('registered:yes!!', 'registered', 'yes!!') def _verify_parse_locator(self, locator, prefix, criteria): parse_locator = self.finder._parse_locator self.assertEqual(parse_locator(locator), (prefix, criteria))