Exemplo n.º 1
0
    def test_aliases_work_correctly(self):
        mock_elem = mock.Mock(WebElement)
        self.mock.find_element_by_xpath.return_value = mock_elem
        self.mock.find_element_by_css_selector.return_value = mock_elem
        self.mock.find_element_by_tag_name.return_value = mock_elem
        self.mock.find_element_by_class_name.return_value = mock_elem
        self.mock.find_element_by_id.return_value = mock_elem
        self.mock.find_element_by_name.return_value = mock_elem
        self.mock.find_element_by_link_text.return_value = mock_elem
        self.mock.find_element_by_partial_link_text.return_value = mock_elem
        wrapper = SeleniumWrapper(self.mock)

        self.assertIsInstance(wrapper.xpath("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.css("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_tag("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_class("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_id("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_name("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_linktxt("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_linktxt("dummy", partial=True), SeleniumWrapper)
        self.assertIsInstance(wrapper.href("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.img(alt="dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_text("dummy", "dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.button("dummy"), SeleniumWrapper)

        wrapped_elem = mock.Mock(WebElement)
        wrapped_elem.find_element_by_xpath.return_value = mock_elem
        wrapper = SeleniumWrapper(wrapped_elem)
        self.assertIsInstance(wrapper.parent, SeleniumWrapper)
    def test_aliases_work_correctly(self):
        mock_elem = mock.Mock(WebElement)
        self.mock.find_element_by_xpath.return_value = mock_elem
        self.mock.find_element_by_css_selector.return_value = mock_elem
        self.mock.find_element_by_tag_name.return_value = mock_elem
        self.mock.find_element_by_class_name.return_value = mock_elem
        self.mock.find_element_by_id.return_value = mock_elem
        self.mock.find_element_by_name.return_value = mock_elem
        self.mock.find_element_by_link_text.return_value = mock_elem
        self.mock.find_element_by_partial_link_text.return_value = mock_elem
        wrapper = SeleniumWrapper(self.mock)

        self.assertIsInstance(wrapper.xpath("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.css("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_tag("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_class("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_id("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_name("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_linktxt("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_linktxt("dummy", partial=True),
                              SeleniumWrapper)
        self.assertIsInstance(wrapper.href("dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.img(alt="dummy"), SeleniumWrapper)
        self.assertIsInstance(wrapper.by_text("dummy", "dummy"),
                              SeleniumWrapper)
        self.assertIsInstance(wrapper.button("dummy"), SeleniumWrapper)

        wrapped_elem = mock.Mock(WebElement)
        wrapped_elem.find_element_by_xpath.return_value = mock_elem
        wrapper = SeleniumWrapper(wrapped_elem)
        self.assertIsInstance(wrapper.parent, SeleniumWrapper)
Exemplo n.º 3
0
 def test_wrapper_returns_None_in_silent_mode(self):
     mocked_driver = mock.Mock(WebDriver)
     mocked_driver.find_element_by_id.side_effect = TimeoutException
     driver = SeleniumWrapper(mocked_driver)
     self.assertRaises(NoSuchElementException, driver.by_id, 'hoge')
     driver.silent = True
     self.assertIsNone(driver.by_id('hoge'))
 def test_wrapper_returns_None_in_silent_mode(self):
     mocked_driver = mock.Mock(WebDriver)
     mocked_driver.find_element_by_id.side_effect = TimeoutException
     driver = SeleniumWrapper(mocked_driver)
     self.assertRaises(NoSuchElementException, driver.by_id, 'hoge')
     driver.silent = True
     self.assertIsNone(driver.by_id('hoge'))