-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement location of element in view in javascript when speaking to …
…a W3C Conformant endpoint
- Loading branch information
1 parent
2adcc58
commit 48cc1a9
Showing
2 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
py/test/selenium/webdriver/common/position_and_size_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import pytest | ||
import unittest | ||
from selenium.webdriver.common.by import By | ||
|
||
|
||
class PositionAndSizeTest(unittest.TestCase): | ||
|
||
def testShouldBeAbleToDetermineTheLocationOfAnElement(self): | ||
self._loadPage("xhtmlTest") | ||
|
||
location = self._get_location_in_viewport(By.ID,"username") | ||
|
||
self.assertGreater(location["x"], 0) | ||
self.assertGreater(location["y"], 0) | ||
|
||
def testShouldGetCoordinatesOfAnElement(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/simple_page.html")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 10, "y": 10}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesOfAnEmptyElement(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_empty_element.html")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 10, "y": 10}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesOfATransparentElement(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_transparent_element.html")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 10, "y": 10}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesOfAHiddenElement(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_hidden_element.html")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 10, "y": 10}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesOfAnInvisibleElement(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_invisible_element.html")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 0, "y": 0}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 0, "y": 0}) | ||
|
||
def testShouldScrollPageAndGetCoordinatesOfAnElementThatIsOutOfViewPort(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_element_out_of_view.html")) | ||
windowHeight =self.driver.get_window_size()["height"] | ||
location = self._get_location_in_viewport(By.ID,"box") | ||
self.assertEqual(location["x"], 10) | ||
self.assertGreaterEqual(location["y"], 0) | ||
self.assertLessEqual(location["y"], windowHeight - 100) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x":10, "y":5010}) | ||
|
||
def testShouldGetCoordinatesOfAnElementInAFrame(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/element_in_frame.html")) | ||
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr")) | ||
box =self.driver.find_element(By.ID,"box") | ||
self.assertEqual(box.location, {"x": 10, "y": 10}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesInViewPortOfAnElementInAFrame(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/element_in_frame.html")) | ||
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 25, "y": 25}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesInViewPortOfAnElementInANestedFrame(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/element_in_nested_frame.html")) | ||
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr")) | ||
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"box"), {"x": 40, "y": 40}) | ||
self.assertEqual(self._get_location_on_page(By.ID,"box"), {"x": 10, "y": 10}) | ||
|
||
def testShouldGetCoordinatesOfAnElementWithFixedPosition(self): | ||
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_fixed_element.html")) | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"fixed")["y"], 0) | ||
self.assertEqual(self._get_location_on_page(By.ID,"fixed")["y"], 0) | ||
|
||
self.driver.find_element(By.ID,"bottom").click() | ||
self.assertEqual(self._get_location_in_viewport(By.ID,"fixed")["y"], 0) | ||
self.assertGreater(self._get_location_on_page(By.ID,"fixed")["y"], 0) | ||
|
||
def testShouldCorrectlyIdentifyThatAnElementHasWidthAndHeight(self): | ||
self._loadPage("xhtmlTest") | ||
|
||
shrinko =self.driver.find_element(By.ID,"linkId") | ||
size = shrinko.size | ||
self.assertTrue(size["width"] > 0) | ||
self.assertTrue(size["height"] > 0) | ||
|
||
def _get_location_in_viewport(self, by, locator): | ||
element = self.driver.find_element(by, locator) | ||
return element.location_once_scrolled_into_view | ||
|
||
|
||
def _get_location_on_page(self, by, locator): | ||
element = self.driver.find_element(by, locator) | ||
return element.location | ||
|
||
def _pageURL(self, name): | ||
return self.webserver.where_is(name + '.html') | ||
|
||
def _loadPage(self, name): | ||
self.driver.get(self._pageURL(name)) |