Skip to content

Commit adb5938

Browse files
committed
fixing python tests for phantom and py3, switch_to.frame(string) in w3c should throw NoSuchFrame also
1 parent 1bc37b7 commit adb5938

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

py/selenium/webdriver/remote/switch_to.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .command import Command
1919
from selenium.webdriver.common.alert import Alert
2020
from selenium.webdriver.common.by import By
21-
from selenium.common.exceptions import NoSuchElementException
21+
from selenium.common.exceptions import NoSuchElementException, NoSuchFrameException
2222

2323
try:
2424
basestring
@@ -76,7 +76,10 @@ def frame(self, frame_reference):
7676
try:
7777
frame_reference = self._driver.find_element(By.ID, frame_reference)
7878
except NoSuchElementException:
79-
frame_reference = self._driver.find_element(By.NAME, frame_reference)
79+
try:
80+
frame_reference = self._driver.find_element(By.NAME, frame_reference)
81+
except NoSuchElementException:
82+
raise NoSuchFrameException(frame_reference)
8083

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

py/test/selenium/webdriver/common/click_scrolling_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def tearDown(self):
3030
self.driver.switch_to.default_content()
3131

3232
def testClickingOnAnchorScrollsPage(self):
33-
scrollScript = "var pageY"
34-
"if (typeof(window.pageYOffset) == 'number') {"
35-
" pageY = window.pageYOffset"
36-
" else {"
37-
" pageY = document.documentElement.scrollTop"
38-
"}"
39-
"return pageY"
33+
scrollScript = """var pageY;
34+
if (typeof(window.pageYOffset) == 'number') {
35+
pageY = window.pageYOffset;
36+
} else {
37+
pageY = document.documentElement.scrollTop;
38+
}
39+
return pageY;"""
4040

4141
self._loadPage("macbeth")
4242

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

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

5151
def testShouldScrollToClickOnAnElementHiddenByOverflow(self):
5252
url = self.webserver.where_is("click_out_of_bounds_overflow.html")

py/test/selenium/webdriver/common/frame_switching_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def testFrameSearchesShouldBeRelativeToTheCurrentlySelectedFrame(self):
161161
try:
162162
self.driver.switch_to.frame("second")
163163
self.fail("Should have thrown NoSuchElementException")
164-
except NoSuchElementException:
164+
except NoSuchFrameException:
165165
# Do nothing
166166
pass
167167
self.driver.switch_to.default_content()

py/test/selenium/webdriver/common/position_and_size_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,36 @@ def testShouldBeAbleToDetermineTheLocationOfAnElement(self):
3131
self.assertGreater(location["y"], 0)
3232

3333
def testShouldGetCoordinatesOfAnElement(self):
34+
if self.driver.capabilities['browserName'] == 'phantomjs':
35+
pytest.xfail("phantomjs calculates coordinates differently")
3436
self.driver.get(self.webserver.where_is("coordinates_tests/simple_page.html"))
3537
self.assertEqual(self._get_location_in_viewport(By.ID, "box"), {"x": 10, "y": 10})
3638
self.assertEqual(self._get_location_on_page(By.ID, "box"), {"x": 10, "y": 10})
3739

3840
def testShouldGetCoordinatesOfAnEmptyElement(self):
41+
if self.driver.capabilities['browserName'] == 'phantomjs':
42+
pytest.xfail("phantomjs calculates coordinates differently")
3943
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_empty_element.html"))
4044
self.assertEqual(self._get_location_in_viewport(By.ID, "box"), {"x": 10, "y": 10})
4145
self.assertEqual(self._get_location_on_page(By.ID, "box"), {"x": 10, "y": 10})
4246

4347
def testShouldGetCoordinatesOfATransparentElement(self):
48+
if self.driver.capabilities['browserName'] == 'phantomjs':
49+
pytest.xfail("phantomjs calculates coordinates differently")
4450
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_transparent_element.html"))
4551
self.assertEqual(self._get_location_in_viewport(By.ID, "box"), {"x": 10, "y": 10})
4652
self.assertEqual(self._get_location_on_page(By.ID, "box"), {"x": 10, "y": 10})
4753

4854
def testShouldGetCoordinatesOfAHiddenElement(self):
55+
if self.driver.capabilities['browserName'] == 'phantomjs':
56+
pytest.xfail("phantomjs calculates coordinates differently")
4957
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_hidden_element.html"))
5058
self.assertEqual(self._get_location_in_viewport(By.ID, "box"), {"x": 10, "y": 10})
5159
self.assertEqual(self._get_location_on_page(By.ID, "box"), {"x": 10, "y": 10})
5260

5361
def testShouldGetCoordinatesOfAnInvisibleElement(self):
62+
if self.driver.capabilities['browserName'] == 'phantomjs':
63+
pytest.xfail("phantomjs calculates coordinates differently")
5464
self.driver.get(self.webserver.where_is("coordinates_tests/page_with_invisible_element.html"))
5565
self.assertEqual(self._get_location_in_viewport(By.ID, "box"), {"x": 0, "y": 0})
5666
self.assertEqual(self._get_location_on_page(By.ID, "box"), {"x": 0, "y": 0})
@@ -73,13 +83,17 @@ def testShouldGetCoordinatesOfAnElementInAFrame(self):
7383

7484
@pytest.mark.ignore_marionette
7585
def testShouldGetCoordinatesInViewPortOfAnElementInAFrame(self):
86+
if self.driver.capabilities['browserName'] == 'phantomjs':
87+
pytest.xfail("phantomjs calculates coordinates differently")
7688
self.driver.get(self.webserver.where_is("coordinates_tests/element_in_frame.html"))
7789
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr"))
7890
self.assertEqual(self._get_location_in_viewport(By.ID, "box"), {"x": 25, "y": 25})
7991
self.assertEqual(self._get_location_on_page(By.ID, "box"), {"x": 10, "y": 10})
8092

8193
@pytest.mark.ignore_marionette
8294
def testShouldGetCoordinatesInViewPortOfAnElementInANestedFrame(self):
95+
if self.driver.capabilities['browserName'] == 'phantomjs':
96+
pytest.xfail("phantomjs calculates coordinates differently")
8397
self.driver.get(self.webserver.where_is("coordinates_tests/element_in_nested_frame.html"))
8498
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr"))
8599
self.driver.switch_to_frame(self.driver.find_element(By.NAME, "ifr"))

py/test/selenium/webdriver/common/webserver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def do_GET(self):
6161
<body>Page number <span id=\"pageNumber\">{page_number}</span>
6262
<p><a href=\"../xhtmlTest.html\" target=\"_top\">top</a>
6363
</body></html>""".format(page_number=path[5:])
64+
html = html.encode('utf-8')
6465
else:
6566
with open(os.path.join(HTML_ROOT, path), 'r', encoding='latin-1') as f:
6667
html = f.read().encode('utf-8')

0 commit comments

Comments
 (0)