예제 #1
0
 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'),
     })
예제 #2
0
 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']))
예제 #3
0
 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]
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 def test_different_access(self):
     self.locators.menu.foo.bar = Locator.ID('bar')
     self.assertEqual(self.locators.menu['foo']['bar'], Locator.ID('bar'))
     self.assertEqual(self.locators.menu['foo'].bar, Locator.ID('bar'))
     self.assertEqual(self.locators.menu.foo.bar, Locator.ID('bar'))
     self.assertEqual(self.locators['menu'].foo.bar, Locator.ID('bar'))
     self.assertEqual(self.locators['menu']['foo'].bar, Locator.ID('bar'))
     self.assertEqual(self.locators['menu']['foo']['bar'],
                      Locator.ID('bar'))
     self.assertEqual(self.locators['menu.foo.bar'], Locator.ID('bar'))
예제 #7
0
    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')
예제 #8
0
 def test_interpolation(self):
     new_loc = self.locators.xpath_locator % 'wow'
     self.assertEqual(new_loc._value, '//div/wow')
     self.assertEqual(new_loc._value, Locator.XPATH('//div/wow')._value)
예제 #9
0
 def test_root_node_is_empty(self):
     self.locators.menu.foo.bar.zaz.blarg = Locator.ID('buzz')
     self.assertEqual(self.locators.menu.foo.bar.zaz.blarg._value, 'buzz')
     self.assertIsNone(self.locators.menu.foo._value)
     self.assertIsNone(self.locators.menu.foo._strategy)
예제 #10
0
 def test_add_new_locator_node_by_key(self):
     self.locators['menu.contact'] = Locator.XPATH('//contact')
     self.assertEqual(self.locators['menu.contact']._strategy, 'xpath')
     self.assertEqual(self.locators['menu.contact']._value, '//contact')
예제 #11
0
 def test_id_locator(self):
     self.assertEqual(Locator.ID('zaz')._strategy, By.ID)
예제 #12
0
 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)
예제 #13
0
 def test_css_locator(self):
     self.assertEqual(Locator.CSS('.main#a')._strategy, By.CSS_SELECTOR)
예제 #14
0
 def test_class_locator(self):
     self.assertEqual(Locator.CLASS('main')._strategy, By.CLASS_NAME)
예제 #15
0
 def test_link_text_locator(self):
     self.assertEqual(Locator.LINK_TEXT('hello')._strategy, By.LINK_TEXT)
     self.assertEqual(
         Locator.LINK_TEXT('hello', partial=True)._strategy,
         By.PARTIAL_LINK_TEXT)
예제 #16
0
 def test_tag_locator(self):
     self.assertEqual(Locator.TAG('form')._strategy, By.TAG_NAME)
예제 #17
0
 def test_requires_only_two_values(self):
     with self.assertRaises(ValueError):
         Locator(By.XPATH, '//div', 'aleatory')
예제 #18
0
 def test_add_new_locator_node_by_attr(self):
     self.locators.menu.home = Locator.XPATH('//nav//home')
     self.assertEqual(self.locators.menu.home._strategy, 'xpath')
     self.assertEqual(self.locators.menu.home._value, '//nav//home')
예제 #19
0
 def test_xpath_locator(self):
     self.assertEqual(Locator.XPATH('//div')._strategy, By.XPATH)
예제 #20
0
 def test_name_locator(self):
     self.assertEqual(Locator.NAME('foo')._strategy, By.NAME)