Fetching contributors…
Cannot retrieve contributors at this time
69 lines (57 sloc) 2.67 KB
# -*- coding: utf-8 -*-
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import warnings
from .fake_webapp import EXAMPLE_APP
class MouseInteractionTest(object):
def test_mouse_over(self):
"Should be able to perform a mouse over on an element"
self.browser.visit(EXAMPLE_APP)
self.browser.find_by_css(".add-element-mouseover").mouse_over()
self.assertTrue(self.browser.is_element_present_by_id('what-is-your-name'))
self.browser.find_by_css(".add-element-mouseover").mouse_out()
def test_mouse_out(self):
"Should be able to perform a mouse out on an element"
self.browser.visit(EXAMPLE_APP)
element = self.browser.find_by_css(".add-element-mouseover")
element.mouse_over()
element.mouse_out()
self.assertFalse(self.browser.is_element_present_by_id('what-is-your-name'))
def test_double_click(self):
"double click should shows a hidden element"
self.browser.visit(EXAMPLE_APP)
button = self.browser.find_by_css(".db-button")
button.double_click()
element = self.browser.find_by_css(
".should-be-visible-after-double-click"
)
self.assertTrue(element.visible)
self.assertTrue(self.browser.is_element_not_present_by_id('what-is-your-name'))
def test_right_click(self):
"should be able to perform a right click on an element"
self.browser.visit(EXAMPLE_APP)
element = self.browser.find_by_css(".right-clicable")
element.right_click()
self.assertEqual(
self.browser.find_by_css('.right-clicable').text,
'right clicked'
)
def test_drag_and_drop(self):
"""
should be able to perform a drag an element and drop in another element
"""
droppable = self.browser.find_by_css('.droppable')
draggable = self.browser.find_by_css('.draggable')
draggable.drag_and_drop(droppable)
self.assertEqual(self.browser.find_by_css('.dragged').text, 'yes')
def test_mouseover_should_be_an_alias_to_mouse_over(self):
"mouseover should be an alias to mouse_over and be deprecated"
with warnings.catch_warnings(record=True) as warnings_list:
self.browser.visit(EXAMPLE_APP)
warnings.simplefilter("always")
element = self.browser.find_by_css(".add-element-mouseover")
element.mouseover()
warn_message = warnings_list[-1].message
self.assertIsInstance(warn_message, DeprecationWarning)
self.assertIn('mouse_over', warn_message.args[0])