예제 #1
0
    def test_unknown_locator(self):
        """Verify that an invalid locator path throws a useful error

        Not only that, but verify that what appears in the error is
        the first part of the locator key that wasn't found.
        """
        expected_error = "locator test:foo.not not found"
        with pytest.raises(KeyError, match=expected_error):
            translate_locator("test", "foo.not.valid")
예제 #2
0
    def test_extra_args(self):
        """Verify extra args are ignored

        Maybe we should be throwing an error, but since `.format()`
        doesn't throw an error, we would have to add our own argument
        checking which I think is more trouble than its worth
        """
        loc = translate_locator("test", "foo.message:testing,one,two,three")
        assert loc == "testing one"
예제 #3
0
 def test_bad_locator(self):
     """Verify a locator that resolves to a non-string raises an error"""
     expected_error = "Expected locator to be of type string, but was <class 'dict'>"
     with pytest.raises(TypeError, match=expected_error):
         translate_locator("test", "foo.bar")
예제 #4
0
 def test_missing_args(self):
     """Verify a friendly exception is thrown for missing arguments"""
     expected_error = "Not enough arguments were supplied"
     with pytest.raises(Exception, match=expected_error):
         translate_locator("test", "foo.bar.hello")
예제 #5
0
 def test_multiple_arguments(self):
     """Verify we support more than a single argument"""
     loc = translate_locator("test", "foo.message:hello,world")
     assert loc == "hello world"
예제 #6
0
 def test_arguments(self):
     """Verify arguments appear in the final locator"""
     loc = translate_locator("test", "foo.bar.hello:world")
     assert loc == "//span[text()='Hello, world']"
예제 #7
0
 def test_nested_locators(self):
     """Verify dot notation can be used to drill into nested structure"""
     loc = translate_locator("test", "foo.bar.baz")
     assert loc == "//div[@class='baz']"
예제 #8
0
 def test_strip_whitespace_from_locator(self):
     """Verify whitespace is stripped from locator key and args"""
     loc = translate_locator("test", "foo . bar . baz")
     assert loc == "//div[@class='baz']"
예제 #9
0
 def translate_locator(self, prefix, locator):
     return translate_locator(prefix, locator)