Пример #1
0
class ExtendedElementTests(unittest.TestCase):
    """Extended element keyword test class."""
    def setUp(self):
        """Instantiate the extended element class."""
        self.element = ExtendedElementKeywords()
        self.element._current_browser = mock.Mock()
        self.element._wait_until_page_ready = mock.Mock()
        self.locator = 'css=.selector'
        self.locator_attribute = 'css=.selector@class'
        self.locator_class = 'selector'
        self.web_element = WebElement('element', False)

    def test_should_inherit_keywords(self):
        """Extended element instance should inherit Selenium2 element instances."""
        self.assertIsInstance(self.element, _ElementKeywords)

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_element"
    )
    def test_should_click_element(self, mock_click_element):
        """Should click an element."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_element.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_element"
    )
    def test_should_click_elementi_and_skip_ready(self, mock_click_element):
        """Should click an element with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_element.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.click_element_at_coordinates")
    def test_should_click_element_at_coordinates(
            self, mock_click_element_at_coordinates):
        """Should click an element at given coordinates."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_element_at_coordinates.assert_called_with(
            self.web_element, 0, 0)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.click_element_at_coordinates")
    def test_should_click_element_at_coordinates_and_skip_ready(
            self, mock_click_element_at_coordinates):
        """Should click an element at given coordinates with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_element_at_coordinates.assert_called_with(
            self.web_element, 0, 0)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_image"
    )
    def test_should_click_image(self, mock_click_image):
        """Should click an image."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_image(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_image.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_image"
    )
    def test_should_click_image_and_skip_ready(self, mock_click_image):
        """Should click an image with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_image(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_image.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_link"
    )
    def test_should_click_link(self, mock_click_link):
        """Should click a link."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_link(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_link.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_link"
    )
    def test_should_click_link_and_skip_ready(self, mock_click_link):
        """Should click a link with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_link(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_click_link.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.double_click_element")
    def test_should_double_click_element(self, mock_double_click_element):
        """Should double click an element."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.double_click_element(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_double_click_element.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.double_click_element")
    def test_should_double_click_element_and_skip_ready(
            self, mock_double_click_element):
        """Should double click an element."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.double_click_element(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(
            self.locator)
        mock_double_click_element.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_element_attribute_should_contain(self):
        """Element attribute should contain expected."""
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        self.element.element_attribute_should_contain(self.locator_attribute,
                                                      self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)

    def test_element_attribute_should_raise_exception(self):
        """Element attribute should raise exception."""
        actual = 'nada'
        message = "Element attribute '%s' should have contained '%s' but its value was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(
                self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_should_raise_custom_message_exception(self):
        """Element attribute should raise exception with custom message."""
        actual = 'nada'
        message = "Locator '%s' should have contained '%s' but it was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(
                self.locator_attribute, self.locator_class, message)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_should_not_contain(self):
        """Element attribute should not contain unexpected."""
        actual = 'nada'
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        self.element.element_attribute_should_not_contain(
            self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)

    def test_element_attribute_not_contain_should_raise_exception(self):
        """Element attribute not contain should raise exception."""
        message = "Element attribute '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(
                self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_not_contain_should_raise_custom_message_exception(
            self):
        """Element attribute not contain should raise exception with custom message."""
        message = "Locator '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(
                self.locator_attribute, self.locator_class, message)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_is_element_visible(self):
        """Element should be visible."""
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = True
        self.assertTrue(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    def test_is_element_not_visible(self):
        """Element should not be visible."""
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = False
        self.assertFalse(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    def test_scroll_element_into_view(self):
        """Scroll element into view."""
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._current_browser().execute_script = mock.Mock()
        self.assertEqual(self.element.scroll_element_into_view(self.locator),
                         self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._current_browser().\
            execute_script.assert_called_with('arguments[0].scrollIntoView()',
                                              self.web_element)

    def test_scroll_element_into_view_raise_exception(self):
        """Scroll element into view raise exception."""
        message = "Element '%s' not found." % self.locator
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = None
        with self.assertRaises(AssertionError) as context:
            self.assertIsNone(
                self.element.scroll_element_into_view(self.locator))
        self.assertEqual(' '.join(context.exception.args).strip(), message)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.assertFalse(self.element._current_browser().execute_script.called)

    def test_get_browser_name(self):
        """Should return browser name."""
        self.element._current_browser().capabilities = {
            'browserName': 'chrome'
        }
        self.assertEqual(self.element._get_browser_name(), 'chrome')

    def test_is_internet_explorer(self):
        """Browser name should be internet explorer."""
        self.element._get_browser_name = mock.Mock()
        self.element._get_browser_name.return_value = 'ie'
        self.assertTrue(self.element._is_internet_explorer())
        self.element._get_browser_name.assert_called_with()

    def test_is_not_internet_explorer(self):
        """Browser name should not be internet explorer."""
        self.element._get_browser_name = mock.Mock()
        self.assertFalse(self.element._is_internet_explorer('chrome'))
        self.assertFalse(self.element._get_browser_name.called)

    def test_scroll_into_view_on_internet_explorer(self):
        """Should scroll into view on internet explorer."""
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = True
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(
            self.element._scroll_into_view_on_internet_explorer(self.locator),
            self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._is_internet_explorer.assert_called_with()
        self.element.scroll_element_into_view.assert_called_with(
            self.web_element)

    def test_not_scroll_into_view_on_non_internet_explorer(self):
        """Should not scroll into view on non internet explorer."""
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = False
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(
            self.element._scroll_into_view_on_internet_explorer(self.locator),
            self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._is_internet_explorer.assert_called_with()
        self.assertFalse(self.element.scroll_element_into_view.called)
class ExtendedElementTests(unittest.TestCase):
    """Extended element keyword test class."""

    def setUp(self):
        """Instantiate the extended element class."""
        self.element = ExtendedElementKeywords()
        self.element._current_browser = mock.Mock()
        self.element._wait_until_page_ready = mock.Mock()
        self.locator = 'css=.selector'
        self.locator_attribute = 'css=.selector@class'
        self.locator_class = 'selector'
        self.web_element = WebElement('element', False)

    def test_should_inherit_keywords(self):
        """Extended element instance should inherit Selenium2 element instances."""
        self.assertIsInstance(self.element, _ElementKeywords)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_element")
    def test_should_click_element(self, mock_click_element):
        """Should click an element."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_element.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_element")
    def test_should_click_elementi_and_skip_ready(self, mock_click_element):
        """Should click an element with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_element.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.click_element_at_coordinates")
    def test_should_click_element_at_coordinates(self, mock_click_element_at_coordinates):
        """Should click an element at given coordinates."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_element_at_coordinates.assert_called_with(self.web_element, 0, 0)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.click_element_at_coordinates")
    def test_should_click_element_at_coordinates_and_skip_ready(self,
                                                                mock_click_element_at_coordinates):
        """Should click an element at given coordinates with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_element_at_coordinates.assert_called_with(self.web_element, 0, 0)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_image")
    def test_should_click_image(self, mock_click_image):
        """Should click an image."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_image(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_image.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_image")
    def test_should_click_image_and_skip_ready(self, mock_click_image):
        """Should click an image with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_image(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_image.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_link")
    def test_should_click_link(self, mock_click_link):
        """Should click a link."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_link(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_link.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement._ElementKeywords.click_link")
    def test_should_click_link_and_skip_ready(self, mock_click_link):
        """Should click a link with skip_ready."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.click_link(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_click_link.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.double_click_element")
    def test_should_double_click_element(self, mock_double_click_element):
        """Should double click an element."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.double_click_element(self.locator)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_double_click_element.assert_called_with(self.web_element)
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement."
                "_ElementKeywords.double_click_element")
    def test_should_double_click_element_and_skip_ready(self, mock_double_click_element):
        """Should double click an element."""
        self.element._scroll_into_view_on_internet_explorer = mock.Mock()
        self.element._scroll_into_view_on_internet_explorer.return_value = self.web_element
        self.element.double_click_element(self.locator, True)
        self.element._scroll_into_view_on_internet_explorer.assert_called_with(self.locator)
        mock_double_click_element.assert_called_with(self.web_element)
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_element_attribute_should_contain(self):
        """Element attribute should contain expected."""
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        self.element.element_attribute_should_contain(self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)

    def test_element_attribute_should_raise_exception(self):
        """Element attribute should raise exception."""
        actual = 'nada'
        message = "Element attribute '%s' should have contained '%s' but its value was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(self.locator_attribute,
                                                          self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_should_raise_custom_message_exception(self):
        """Element attribute should raise exception with custom message."""
        actual = 'nada'
        message = "Locator '%s' should have contained '%s' but it was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(self.locator_attribute,
                                                          self.locator_class,
                                                          message)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_should_not_contain(self):
        """Element attribute should not contain unexpected."""
        actual = 'nada'
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        self.element.element_attribute_should_not_contain(self.locator_attribute,
                                                          self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)

    def test_element_attribute_not_contain_should_raise_exception(self):
        """Element attribute not contain should raise exception."""
        message = "Element attribute '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(self.locator_attribute,
                                                              self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_not_contain_should_raise_custom_message_exception(self):
        """Element attribute not contain should raise exception with custom message."""
        message = "Locator '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(self.locator_attribute,
                                                              self.locator_class,
                                                              message)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_is_element_visible(self):
        """Element should be visible."""
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = True
        self.assertTrue(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    def test_is_element_not_visible(self):
        """Element should not be visible."""
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = False
        self.assertFalse(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    def test_scroll_element_into_view(self):
        """Scroll element into view."""
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._current_browser().execute_script = mock.Mock()
        self.assertEqual(self.element.scroll_element_into_view(self.locator),
                         self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._current_browser().\
            execute_script.assert_called_with('arguments[0].scrollIntoView()',
                                              self.web_element)

    def test_scroll_element_into_view_raise_exception(self):
        """Scroll element into view raise exception."""
        message = "Element '%s' not found." % self.locator
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = None
        with self.assertRaises(AssertionError) as context:
            self.assertIsNone(self.element.scroll_element_into_view(self.locator))
        self.assertEqual(' '.join(context.exception.args).strip(), message)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.assertFalse(self.element._current_browser().execute_script.called)

    def test_get_browser_name(self):
        """Should return browser name."""
        self.element._current_browser().capabilities = {'browserName': 'chrome'}
        self.assertEqual(self.element._get_browser_name(), 'chrome')

    def test_is_internet_explorer(self):
        """Browser name should be internet explorer."""
        self.element._get_browser_name = mock.Mock()
        self.element._get_browser_name.return_value = 'ie'
        self.assertTrue(self.element._is_internet_explorer())
        self.element._get_browser_name.assert_called_with()

    def test_is_not_internet_explorer(self):
        """Browser name should not be internet explorer."""
        self.element._get_browser_name = mock.Mock()
        self.assertFalse(self.element._is_internet_explorer('chrome'))
        self.assertFalse(self.element._get_browser_name.called)

    def test_scroll_into_view_on_internet_explorer(self):
        """Should scroll into view on internet explorer."""
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = True
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(self.element._scroll_into_view_on_internet_explorer(self.locator),
                         self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._is_internet_explorer.assert_called_with()
        self.element.scroll_element_into_view.assert_called_with(self.web_element)

    def test_not_scroll_into_view_on_non_internet_explorer(self):
        """Should not scroll into view on non internet explorer."""
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = False
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(self.element._scroll_into_view_on_internet_explorer(self.locator),
                         self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._is_internet_explorer.assert_called_with()
        self.assertFalse(self.element.scroll_element_into_view.called)
Пример #3
0
class ExtendedElementTests(unittest.TestCase):
    """Extended element keyword test class."""
    def setUp(self):
        """Instantiate the extended element class."""
        self.driver = mock.Mock()
        self.driver.session_id = 'session'
        self.element = ExtendedElementKeywords()
        # pylint: disable=protected-access
        self.element._current_browser = mock.Mock()
        self.element._info = mock.Mock()
        self.element._wait_until_page_ready = mock.Mock()
        self.locator = 'css=.selector'
        self.locator_attribute = 'css=.selector@class'
        self.locator_class = 'selector'
        self.web_element = WebElement(self.driver, 'element', False)
        self.web_element.click = mock.Mock()

    def test_should_inherit_keywords(self):
        """Extended element instance should inherit Selenium2 element instances."""
        self.assertIsInstance(self.element, _ElementKeywords)

    def test_should_click_element(self):
        """Should click an element."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element(self.locator)
        self.element._info.assert_called_with("Clicking element '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(
            self.locator)
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_element_and_skip_ready(self):
        """Should click an element with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element(self.locator, True)
        self.element._info.assert_called_with("Clicking element '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(
            self.locator)
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_click_element_at_coordinates(self, mock_action_chains):
        """Should click an element at given coordinates."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0)
        self.element._info.assert_called_with(
            "Clicking element '%s' in coordinates '%s', '%s'." %
            (self.locator, 0, 0))
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(
            self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.move_to_element.assert_called_with(self.web_element)
        move_to_element = action_chains.move_to_element(self.web_element)
        move_to_element.move_by_offset.assert_called_with(0, 0)
        move_by_offset = move_to_element.move_by_offset(0, 0)
        move_by_offset.click.assert_called_with()
        click = move_by_offset.click()
        click.perform.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_click_el_at_coords_and_skip_ready(self,
                                                      mock_action_chains):
        """Should click an element at given coordinates with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0, True)
        self.element._info.assert_called_with(
            "Clicking element '%s' in coordinates '%s', '%s'." %
            (self.locator, 0, 0))
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(
            self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.move_to_element.assert_called_with(self.web_element)
        move_to_element = action_chains.move_to_element(self.web_element)
        move_to_element.move_by_offset.assert_called_with(0, 0)
        move_by_offset = move_to_element.move_by_offset(0, 0)
        move_by_offset.click.assert_called_with()
        click = move_by_offset.click()
        click.perform.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_should_click_image(self):
        """Should click an image."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_image(self.locator)
        self.element._info.assert_called_with("Clicking image '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, False, 'image')
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_image_and_skip_ready(self):
        """Should click an image with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_image(self.locator, True)
        self.element._info.assert_called_with("Clicking image '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, False, 'image')
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_should_click_input_image(self):
        """Should click an input image."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.side_effect = \
            [None, self.web_element]
        self.element.click_image(self.locator)
        self.element._info.assert_called_with("Clicking image '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, True, 'input')
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_input_image_and_skip_ready(self):
        """Should click an input image with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.side_effect = \
            [None, self.web_element]
        self.element.click_image(self.locator, True)
        self.element._info.assert_called_with("Clicking image '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, True, 'input')
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_should_click_link(self):
        """Should click a link."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_link(self.locator)
        self.element._info.assert_called_with("Clicking link '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, tag='a')
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_link_and_skip_ready(self):
        """Should click a link with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_link(self.locator, True)
        self.element._info.assert_called_with("Clicking link '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, tag='a')
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_double_click_element(self, mock_action_chains):
        """Should double click an element."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.double_click_element(self.locator)
        self.element._info.assert_called_with("Double clicking element '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(
            self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.double_click.assert_called_with(self.web_element)
        double_click = action_chains.double_click(self.web_element)
        double_click.perform.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch(
        "ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_double_click_element_and_skip_ready(
            self, mock_action_chains):
        """Should double click an element with skip ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock(
        )
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.double_click_element(self.locator, True)
        self.element._info.assert_called_with("Double clicking element '%s'." %
                                              self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(
            self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.double_click.assert_called_with(self.web_element)
        double_click = action_chains.double_click(self.web_element)
        double_click.perform.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_element_attribute_should_contain(self):
        """Element attribute should contain expected."""
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        self.element.element_attribute_should_contain(self.locator_attribute,
                                                      self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)

    def test_element_attribute_should_raise_exception(self):
        """Element attribute should raise exception."""
        actual = 'nada'
        message = "Element attribute '%s' should have contained '%s' but its value was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(
                self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_el_attr_should_raise_custom_msg_exception(self):
        """Element attribute should raise exception with custom message."""
        actual = 'nada'
        message = "Locator '%s' should have contained '%s' but it was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(
                self.locator_attribute, self.locator_class, message)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_should_not_contain(self):
        """Element attribute should not contain unexpected."""
        actual = 'nada'
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        self.element.element_attribute_should_not_contain(
            self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)

    def test_el_attr_not_contain_should_raise_exception(self):
        """Element attribute not contain should raise exception."""
        message = "Element attribute '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(
                self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_el_attr_not_contain_raise_custom_msg_ex(self):
        """Element attribute not contain should raise exception with custom message."""
        message = "Locator '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(
                self.locator_attribute, self.locator_class, message)
        self.element.get_element_attribute.assert_called_with(
            self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_is_element_visible(self):
        """Element should be visible."""
        # pylint: disable=protected-access
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = True
        self.assertTrue(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    def test_is_element_not_visible(self):
        """Element should not be visible."""
        # pylint: disable=protected-access
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = False
        self.assertFalse(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement.logger")
    def test_scroll_element_into_view(self, mock_logger):
        """Scroll element into view."""
        # pylint: disable=protected-access
        self.element._current_browser().execute_script = mock.Mock()
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.assertEqual(self.element.scroll_element_into_view(self.locator),
                         self.web_element)
        mock_logger.info.assert_called_with(
            "Scrolling element '%s' into view." % self.locator)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._current_browser().\
            execute_script.assert_called_with('arguments[0].scrollIntoView()',
                                              self.web_element)

    def test_scroll_element_into_view_with_web_element(self):
        """Scroll element into view with web element."""
        # pylint: disable=protected-access
        self.element._current_browser().execute_script = mock.Mock()
        self.element._element_find = mock.Mock()
        self.assertEqual(
            self.element.scroll_element_into_view(self.web_element),
            self.web_element)
        self.assertFalse(self.element._info.called)
        self.assertFalse(self.element._element_find.called)
        self.element._current_browser().\
            execute_script.assert_called_with('arguments[0].scrollIntoView()',
                                              self.web_element)

    def test_get_browser_name(self):
        """Should return browser name."""
        # pylint: disable=protected-access
        self.element._current_browser().capabilities = {
            'browserName': 'chrome'
        }
        self.assertEqual(self.element._get_browser_name(), 'chrome')

    def test_get_element_and_scroll_into_view_on_iexplore(self):
        """Should scroll into view on internet explorer and returns the element."""
        # pylint: disable=protected-access
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = True
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(
            self.element._get_element_and_scroll_into_view_on_iexplore(
                self.locator), self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True,
                                                      None)
        self.element._is_internet_explorer.assert_called_with()
        self.element.scroll_element_into_view.assert_called_with(
            self.web_element)

    def test_get_el_and_not_scroll_on_non_iexplore(self):
        """Should not scroll into view on non internet explorer and returns element."""
        # pylint: disable=protected-access
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = False
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(
            self.element._get_element_and_scroll_into_view_on_iexplore(
                self.locator), self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True,
                                                      None)
        self.element._is_internet_explorer.assert_called_with()
        self.assertFalse(self.element.scroll_element_into_view.called)

    def test_is_internet_explorer(self):
        """Browser name should be internet explorer."""
        # pylint: disable=protected-access
        self.element._get_browser_name = mock.Mock()
        self.element._get_browser_name.return_value = 'ie'
        self.assertTrue(self.element._is_internet_explorer())
        self.element._get_browser_name.assert_called_with()

    def test_is_not_internet_explorer(self):
        """Browser name should not be internet explorer."""
        # pylint: disable=protected-access
        self.element._get_browser_name = mock.Mock()
        self.assertFalse(self.element._is_internet_explorer('chrome'))
        self.assertFalse(self.element._get_browser_name.called)
class ExtendedElementTests(unittest.TestCase):
    """Extended element keyword test class."""

    def setUp(self):
        """Instantiate the extended element class."""
        self.driver = mock.Mock()
        self.driver.session_id = 'session'
        self.element = ExtendedElementKeywords()
        # pylint: disable=protected-access
        self.element._current_browser = mock.Mock()
        self.element._info = mock.Mock()
        self.element._wait_until_page_ready = mock.Mock()
        self.locator = 'css=.selector'
        self.locator_attribute = 'css=.selector@class'
        self.locator_class = 'selector'
        self.web_element = WebElement(self.driver, 'element', False)
        self.web_element.click = mock.Mock()

    def test_should_inherit_keywords(self):
        """Extended element instance should inherit Selenium2 element instances."""
        self.assertIsInstance(self.element, _ElementKeywords)

    def test_should_click_element(self):
        """Should click an element."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element(self.locator)
        self.element._info.assert_called_with("Clicking element '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(self.locator)
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_element_and_skip_ready(self):
        """Should click an element with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element(self.locator, True)
        self.element._info.assert_called_with("Clicking element '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(self.locator)
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_click_element_at_coordinates(self, mock_action_chains):
        """Should click an element at given coordinates."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0)
        self.element._info.assert_called_with("Clicking element '%s' in coordinates '%s', '%s'." %
                                              (self.locator, 0, 0))
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.move_to_element.assert_called_with(self.web_element)
        move_to_element = action_chains.move_to_element(self.web_element)
        move_to_element.move_by_offset.assert_called_with(0, 0)
        move_by_offset = move_to_element.move_by_offset(0, 0)
        move_by_offset.click.assert_called_with()
        click = move_by_offset.click()
        click.perform.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_click_el_at_coords_and_skip_ready(self, mock_action_chains):
        """Should click an element at given coordinates with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_element_at_coordinates(self.locator, 0, 0, True)
        self.element._info.assert_called_with("Clicking element '%s' in coordinates '%s', '%s'." %
                                              (self.locator, 0, 0))
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.move_to_element.assert_called_with(self.web_element)
        move_to_element = action_chains.move_to_element(self.web_element)
        move_to_element.move_by_offset.assert_called_with(0, 0)
        move_by_offset = move_to_element.move_by_offset(0, 0)
        move_by_offset.click.assert_called_with()
        click = move_by_offset.click()
        click.perform.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_should_click_image(self):
        """Should click an image."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_image(self.locator)
        self.element._info.assert_called_with("Clicking image '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, False, 'image')
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_image_and_skip_ready(self):
        """Should click an image with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_image(self.locator, True)
        self.element._info.assert_called_with("Clicking image '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, False, 'image')
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_should_click_input_image(self):
        """Should click an input image."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.side_effect = \
            [None, self.web_element]
        self.element.click_image(self.locator)
        self.element._info.assert_called_with("Clicking image '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, True, 'input')
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_input_image_and_skip_ready(self):
        """Should click an input image with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.side_effect = \
            [None, self.web_element]
        self.element.click_image(self.locator, True)
        self.element._info.assert_called_with("Clicking image '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, True, 'input')
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_should_click_link(self):
        """Should click a link."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_link(self.locator)
        self.element._info.assert_called_with("Clicking link '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, tag='a')
        self.web_element.click.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    def test_should_click_link_and_skip_ready(self):
        """Should click a link with skip_ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.click_link(self.locator, True)
        self.element._info.assert_called_with("Clicking link '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.\
            assert_called_with(self.locator, tag='a')
        self.web_element.click.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_double_click_element(self, mock_action_chains):
        """Should double click an element."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.double_click_element(self.locator)
        self.element._info.assert_called_with("Double clicking element '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.double_click.assert_called_with(self.web_element)
        double_click = action_chains.double_click(self.web_element)
        double_click.perform.assert_called_with()
        self.element._wait_until_page_ready.assert_called_with()

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement.ActionChains")
    def test_should_double_click_element_and_skip_ready(self, mock_action_chains):
        """Should double click an element with skip ready."""
        # pylint: disable=protected-access
        self.element._get_element_and_scroll_into_view_on_iexplore = mock.Mock()
        self.element._get_element_and_scroll_into_view_on_iexplore.return_value = self.web_element
        self.element.double_click_element(self.locator, True)
        self.element._info.assert_called_with("Double clicking element '%s'." % self.locator)
        self.element._get_element_and_scroll_into_view_on_iexplore.assert_called_with(self.locator)
        mock_action_chains.assert_called_with(self.element._current_browser())
        action_chains = mock_action_chains(self.element._current_browser())
        action_chains.double_click.assert_called_with(self.web_element)
        double_click = action_chains.double_click(self.web_element)
        double_click.perform.assert_called_with()
        self.assertFalse(self.element._wait_until_page_ready.called)

    def test_element_attribute_should_contain(self):
        """Element attribute should contain expected."""
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        self.element.element_attribute_should_contain(self.locator_attribute, self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)

    def test_element_attribute_should_raise_exception(self):
        """Element attribute should raise exception."""
        actual = 'nada'
        message = "Element attribute '%s' should have contained '%s' but its value was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(self.locator_attribute,
                                                          self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_el_attr_should_raise_custom_msg_exception(self):
        """Element attribute should raise exception with custom message."""
        actual = 'nada'
        message = "Locator '%s' should have contained '%s' but it was '%s'." %\
                  (self.locator_attribute, self.locator_class, actual)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_contain(self.locator_attribute,
                                                          self.locator_class,
                                                          message)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_element_attribute_should_not_contain(self):
        """Element attribute should not contain unexpected."""
        actual = 'nada'
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = actual
        self.element.element_attribute_should_not_contain(self.locator_attribute,
                                                          self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)

    def test_el_attr_not_contain_should_raise_exception(self):
        """Element attribute not contain should raise exception."""
        message = "Element attribute '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(self.locator_attribute,
                                                              self.locator_class)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_el_attr_not_contain_raise_custom_msg_ex(self):
        """Element attribute not contain should raise exception with custom message."""
        message = "Locator '%s' should not contain '%s' but it did." %\
                  (self.locator_attribute, self.locator_class)
        self.element.get_element_attribute = mock.Mock()
        self.element.get_element_attribute.return_value = self.locator_class
        with self.assertRaises(AssertionError) as context:
            self.element.element_attribute_should_not_contain(self.locator_attribute,
                                                              self.locator_class,
                                                              message)
        self.element.get_element_attribute.assert_called_with(self.locator_attribute)
        self.assertEqual(' '.join(context.exception.args).strip(), message)

    def test_is_element_visible(self):
        """Element should be visible."""
        # pylint: disable=protected-access
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = True
        self.assertTrue(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    def test_is_element_not_visible(self):
        """Element should not be visible."""
        # pylint: disable=protected-access
        self.element._is_visible = mock.Mock()
        self.element._is_visible.return_value = False
        self.assertFalse(self.element.is_element_visible(self.locator))
        self.element._is_visible.assert_called_with(self.locator)

    @mock.patch("ExtendedSelenium2Library.keywords.extendedelement.logger")
    def test_scroll_element_into_view(self, mock_logger):
        """Scroll element into view."""
        # pylint: disable=protected-access
        self.element._current_browser().execute_script = mock.Mock()
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.assertEqual(self.element.scroll_element_into_view(self.locator),
                         self.web_element)
        mock_logger.info.assert_called_with("Scrolling element '%s' into view." % self.locator)
        self.element._element_find.assert_called_with(self.locator, True, True)
        self.element._current_browser().\
            execute_script.assert_called_with('arguments[0].scrollIntoView()',
                                              self.web_element)

    def test_scroll_element_into_view_with_web_element(self):
        """Scroll element into view with web element."""
        # pylint: disable=protected-access
        self.element._current_browser().execute_script = mock.Mock()
        self.element._element_find = mock.Mock()
        self.assertEqual(self.element.scroll_element_into_view(self.web_element),
                         self.web_element)
        self.assertFalse(self.element._info.called)
        self.assertFalse(self.element._element_find.called)
        self.element._current_browser().\
            execute_script.assert_called_with('arguments[0].scrollIntoView()',
                                              self.web_element)

    def test_get_browser_name(self):
        """Should return browser name."""
        # pylint: disable=protected-access
        self.element._current_browser().capabilities = {'browserName': 'chrome'}
        self.assertEqual(self.element._get_browser_name(), 'chrome')

    def test_get_element_and_scroll_into_view_on_iexplore(self):
        """Should scroll into view on internet explorer and returns the element."""
        # pylint: disable=protected-access
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = True
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(self.element._get_element_and_scroll_into_view_on_iexplore(self.locator),
                         self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True, None)
        self.element._is_internet_explorer.assert_called_with()
        self.element.scroll_element_into_view.assert_called_with(self.web_element)

    def test_get_el_and_not_scroll_on_non_iexplore(self):
        """Should not scroll into view on non internet explorer and returns element."""
        # pylint: disable=protected-access
        self.element._element_find = mock.Mock()
        self.element._element_find.return_value = self.web_element
        self.element._is_internet_explorer = mock.Mock()
        self.element._is_internet_explorer.return_value = False
        self.element.scroll_element_into_view = mock.Mock()
        self.assertEqual(self.element._get_element_and_scroll_into_view_on_iexplore(self.locator),
                         self.web_element)
        self.element._element_find.assert_called_with(self.locator, True, True, None)
        self.element._is_internet_explorer.assert_called_with()
        self.assertFalse(self.element.scroll_element_into_view.called)

    def test_is_internet_explorer(self):
        """Browser name should be internet explorer."""
        # pylint: disable=protected-access
        self.element._get_browser_name = mock.Mock()
        self.element._get_browser_name.return_value = 'ie'
        self.assertTrue(self.element._is_internet_explorer())
        self.element._get_browser_name.assert_called_with()

    def test_is_not_internet_explorer(self):
        """Browser name should not be internet explorer."""
        # pylint: disable=protected-access
        self.element._get_browser_name = mock.Mock()
        self.assertFalse(self.element._is_internet_explorer('chrome'))
        self.assertFalse(self.element._get_browser_name.called)