def test_multi_level_locator(self): root = LocatorDict({ "content_env.edit_description": (By.XPATH, ("//form[@bst-edit-textarea='environment.description']" "//i[contains(@class,'fa-edit')]")), "content_env.edit_description_textarea.save": (By.XPATH, "//form[@bst-edit-textarea='environment.description']//button"), "content_env.edit_description_textarea": (By.XPATH, ("//form[@bst-edit-textarea='environment.description']" "/div/textarea")), }) self.assertTrue(root['content_env']._is_root) self.assertFalse(root["content_env.edit_description"]._is_root) self.assertEquals(root["content_env.edit_description"][0], 'xpath') self.assertEquals( root["content_env.edit_description"][1], ("//form[@bst-edit-textarea='environment.description']" "//i[contains(@class,'fa-edit')]")) self.assertIn('save', root["content_env.edit_description_textarea"].keys()) self.assertEquals( root["content_env.edit_description_textarea.save"][1], "//form[@bst-edit-textarea='environment.description']//button")
def test_init_with_dict_locators(self): root = LocatorDict({ "menu": Locator.XPATH('//div'), "logout": (By.ID, 'logout') }) self.assertTrue('menu' in root) self.assertTrue('logout' in root)
def setUp(self): self.locators = LocatorDict({ "simple_locator": (By.XPATH, '//div'), "xpath_locator": Locator.XPATH('//div/%s'), "id_locator": Locator(By.ID, 'this_is_id_%s'), })
def test_item_existance(self): root = LocatorDict() root.menu.home = Locator.XPATH('//div') self.assertTrue('home' in root.menu) self.assertTrue('menu' in root) self.assertFalse('baz' in root) self.assertFalse('foo' in root.menu) self.assertFalse('zaz' in root.menu.bla.arg)
def test_inspect_members(self): root = LocatorDict() root.menu.home = Locator.XPATH('//div') root.menu.contact = Locator.ID('contact') root.menu.login = Locator.CLASS('login') self.assertEqual( sorted(dir(root.menu)), sorted( ['home', 'contact', 'login', '_store', '_value', '_strategy']))
def test_getitem(self): root = LocatorDict() root.menu.home = Locator.XPATH('//div') # only 0 and 1 allowed self.assertEqual(root.menu.home[0], 'xpath') self.assertEqual(root.menu.home[1], '//div') # all new keys gets empty locator self.assertEqual(root.menu.home['empty_locator'], Locator()) self.assertEqual(root.menu.home._strategy, 'xpath') # access by key also gets empty self.assertEqual(root['menu']['home']['empty'], Locator()) # not allowed to access 3rd element with self.assertRaises(IndexError): root.menu.home[3]
def test_merge_locator_dicts(self): first = LocatorDict({ "foo.bar": (By.XPATH, '//foo/bar'), "foo": (By.XPATH, '//foo'), "second.naz": (By.XPATH, '//second/naz') }) second = Locator.XPATH('//foo/bar/blaz') second['zaz'] = ('xpath', '//zaz') self.assertIn('zaz', second.keys()) self.assertTrue(first.second._is_root) first['second'] = second self.assertFalse(first.second._is_root) self.assertEqual(first.second[1], '//foo/bar/blaz') self.assertEqual(first['second.naz'][1], '//second/naz') self.assertEqual(first['second.zaz'][1], '//zaz')
def test_init_with_named_locators(self): root = LocatorDict(menu=Locator.XPATH('//div'), logout=(By.ID, 'logout')) self.assertTrue('menu' in root) self.assertTrue('logout' in root)