示例#1
0
 def test_xpath_with_square_brackets_add(self):
     object_1 = Xpath("//div[@id='timezone']")
     object_2 = Xpath(
         "//span[@class='btn btn-default form-control ui-select-toggle']")
     add_result = object_1 + object_2
     assert add_result.xpath == "//div[@id='timezone']//span[@class='btn btn-default form-control ui-select-toggle']", \
         "Addition result of {} and {} is {} instead of " \
         "//div[@id='timezone']//span[@class='btn btn-default form-control ui-select-toggle']".format(
             object_1, object_2, add_result)
示例#2
0
 def test_equal(self):
     assert self.object_1 == Xpath(
         "//div"), '"self.object_1 == Xpath("//div")" is False'
示例#3
0
 def test_failure_format_object(self):
     assert Xpath("//div[class='{}']").format('ONE') != Xpath("//div[class='TWO']"), \
         '"Xpath(\'//div[class="{}"]).format(\'ONE\')" is the same object as: Xpath(\'//div[class="TWO"]\')'
示例#4
0
 def setUp(self):
     self.object_1 = Xpath("//div")
     self.object_2 = Xpath("//span")
示例#5
0
 def test_format_return_object(self):
     assert Xpath("//div[class='{}']").format('ONE') == Xpath("//div[class='ONE']"), \
         '"Xpath(\'//div[class="{}"]).format(\'ONE\')" is not the same object as: "Xpath(\'//div[class="ONE"]\')"'
示例#6
0
 def test_format_return_type(self):
     object_1 = Xpath("//div[class='{}']").format('ONE')
     assert isinstance(
         object_1, Xpath
     ), 'Xpath.format() is not a Xpath class object. Is {} instead.'.format(
         type(object_1))
示例#7
0
 def test_failure_format_kwargs_but_args_given(self):
     with pytest.raises(KeyError):
         object_1 = Xpath("//div[class='{first}']|//span[type='{second}']")
         object_1.format('not', 'kwargs')
示例#8
0
 def test_too_many_args_format(self):
     object_1 = Xpath("//div[class='{}']|//span[type='{}']")
     assert str(object_1.format(
         'wrong', 'number',
         'of arguments')) == "//div[class='wrong']|//span[type='number']"
示例#9
0
 def test_failure_format_args_but_kwargs_given(self):
     with pytest.raises(IndexError):
         object_1 = Xpath("//div[class='{}']|//span[type='{}']")
         object_1.format(third='wrong')
示例#10
0
 def test_failure_format_kwargs(self):
     with pytest.raises(KeyError):
         object_1 = Xpath("//div[class='{first}']|//span[type='{second}']")
         object_1.format(third='wrong')
示例#11
0
 def test_kwargs_format_return(self):
     object_1 = Xpath("//div[class='{first}']|//span[type='{second}']")
     expected_string = "//div[class='ONE']|//span[type='Two']"
     assert str(object_1.format(first='ONE', second='Two')) == expected_string, \
         'object_1.format(\'One\', \'Two\') is not {}, but instead {}'.format(
             expected_string, object_1.format(first='ONE', second='Two'))
示例#12
0
 def test_kwarg_format_return(self):
     object_1 = Xpath("//div[class='{it}']")
     expected_string = "//div[class='ONE']"
     assert str(object_1.format(it='ONE')) == expected_string, \
         'object_1.format(it=\'One\') is not {}, but instead {}'.format(expected_string, object_1.format(it='ONE'))
示例#13
0
 def test_double_quote_change_to_single_quote(self):
     object_1 = Xpath('//div[@class="not"]')
     assert object_1 == "//div[@class='not']"
示例#14
0
 def test_equal_two_xpath(self):
     object_2 = Xpath("//div")
     assert self.object_1 == object_2, 'Xpath("{}") is not equal to Xpath("{}")'.format(
         self.object_1, object_2)