Skip to content

Commit

Permalink
fixing python tests for phantom and py3, switch_to.frame(string) in w…
Browse files Browse the repository at this point in the history
…3c should throw NoSuchFrame also
  • Loading branch information
lukeis committed Sep 25, 2016
1 parent 1bc37b7 commit adb5938
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
7 changes: 5 additions & 2 deletions py/selenium/webdriver/remote/switch_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .command import Command
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoSuchElementException, NoSuchFrameException

try:
basestring
Expand Down Expand Up @@ -76,7 +76,10 @@ def frame(self, frame_reference):
try:
frame_reference = self._driver.find_element(By.ID, frame_reference)
except NoSuchElementException:
frame_reference = self._driver.find_element(By.NAME, frame_reference)
try:
frame_reference = self._driver.find_element(By.NAME, frame_reference)
except NoSuchElementException:
raise NoSuchFrameException(frame_reference)

self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference})

Expand Down
16 changes: 8 additions & 8 deletions py/test/selenium/webdriver/common/click_scrolling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def tearDown(self):
self.driver.switch_to.default_content()

def testClickingOnAnchorScrollsPage(self):
scrollScript = "var pageY"
"if (typeof(window.pageYOffset) == 'number') {"
" pageY = window.pageYOffset"
" else {"
" pageY = document.documentElement.scrollTop"
"}"
"return pageY"
scrollScript = """var pageY;
if (typeof(window.pageYOffset) == 'number') {
pageY = window.pageYOffset;
} else {
pageY = document.documentElement.scrollTop;
}
return pageY;"""

self._loadPage("macbeth")

Expand All @@ -46,7 +46,7 @@ def testClickingOnAnchorScrollsPage(self):

# Focusing on to click, but not actually following,
# the link will scroll it in to view, which is a few pixels further than 0
self.assertGreater(300, yOffset)
self.assertGreater(yOffset, 300)

def testShouldScrollToClickOnAnElementHiddenByOverflow(self):
url = self.webserver.where_is("click_out_of_bounds_overflow.html")
Expand Down
2 changes: 1 addition & 1 deletion py/test/selenium/webdriver/common/frame_switching_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def testFrameSearchesShouldBeRelativeToTheCurrentlySelectedFrame(self):
try:
self.driver.switch_to.frame("second")
self.fail("Should have thrown NoSuchElementException")
except NoSuchElementException:
except NoSuchFrameException:
# Do nothing
pass
self.driver.switch_to.default_content()
Expand Down
14 changes: 14 additions & 0 deletions py/test/selenium/webdriver/common/position_and_size_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,36 @@ def testShouldBeAbleToDetermineTheLocationOfAnElement(self):
self.assertGreater(location["y"], 0)

def testShouldGetCoordinatesOfAnElement(self):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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})
Expand All @@ -73,13 +83,17 @@ def testShouldGetCoordinatesOfAnElementInAFrame(self):

@pytest.mark.ignore_marionette
def testShouldGetCoordinatesInViewPortOfAnElementInAFrame(self):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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})

@pytest.mark.ignore_marionette
def testShouldGetCoordinatesInViewPortOfAnElementInANestedFrame(self):
if self.driver.capabilities['browserName'] == 'phantomjs':
pytest.xfail("phantomjs calculates coordinates differently")
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"))
Expand Down
1 change: 1 addition & 0 deletions py/test/selenium/webdriver/common/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def do_GET(self):
<body>Page number <span id=\"pageNumber\">{page_number}</span>
<p><a href=\"../xhtmlTest.html\" target=\"_top\">top</a>
</body></html>""".format(page_number=path[5:])
html = html.encode('utf-8')
else:
with open(os.path.join(HTML_ROOT, path), 'r', encoding='latin-1') as f:
html = f.read().encode('utf-8')
Expand Down

0 comments on commit adb5938

Please sign in to comment.