def get_identifier(self): """Get the identifier for this Element. :returns: the identifier used to locate this Element. """ if self.parent is not None: return xpath_of(self.parent.strategy, self.parent.get_identifier()) + xpath_of(self.strategy, self._identifier, self.content) else: return self._identifier % tuple(self.content)
def test_id(self): self.assertEqual("//*[@id='element_id']", xpath_of(ID, "element_id", [])) self.assertEqual("//*[@id='element_x_id']", xpath_of(ID, "element_%s_id", ["x"])) self.assertEqual("//*[@id='element_1_id']", xpath_of(ID, "element_%d_id", [1])) # TypeError: not all arguments converted during string formatting self.assertRaisesRegexp(TypeError, "not all arguments converted during string formatting", xpath_of, ID, "element_id", ["asdf"]) # TypeError: not enough arguments for format string self.assertRaisesRegexp(TypeError, "not enough arguments for format string", xpath_of, ID, "element_%s_id", []) # TypeError: %d format: a number is required, not str self.assertRaisesRegexp(TypeError, "%d format: a number is required, not str", xpath_of, ID, "element_%d_id", ["x"])
def test_xpath(self): self.assertEqual("//*[@id='element_id']", xpath_of(XPATH, "//*[@id='element_id']"))
def make_ith_identifier(self, i): return xpath_of(self.get_identifier())