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)
def test_equal(self): assert self.object_1 == Xpath( "//div"), '"self.object_1 == Xpath("//div")" is False'
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"]\')'
def setUp(self): self.object_1 = Xpath("//div") self.object_2 = Xpath("//span")
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"]\')"'
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))
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')
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']"
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')
def test_failure_format_kwargs(self): with pytest.raises(KeyError): object_1 = Xpath("//div[class='{first}']|//span[type='{second}']") object_1.format(third='wrong')
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'))
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'))
def test_double_quote_change_to_single_quote(self): object_1 = Xpath('//div[@class="not"]') assert object_1 == "//div[@class='not']"
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)