|
3 | 3 | # distributed with this work for additional information
|
4 | 4 | # regarding copyright ownership. The SFC licenses this file
|
5 | 5 | # to you under the Apache License, Version 2.0 (the
|
6 |
| -# "License"); you may not use this file except in compliance |
| 6 | +# "License") you may not use this file except in compliance |
7 | 7 | # with the License. You may obtain a copy of the License at
|
8 | 8 | #
|
9 | 9 | # http://www.apache.org/licenses/LICENSE-2.0
|
|
20 | 20 |
|
21 | 21 | from selenium.webdriver.common.by import By
|
22 | 22 | from selenium.common.exceptions import MoveTargetOutOfBoundsException
|
| 23 | +from selenium.webdriver.support import expected_conditions as EC |
| 24 | +from selenium.webdriver.support.ui import WebDriverWait |
23 | 25 |
|
24 | 26 |
|
25 | 27 | class ClickScrollingTest(unittest.TestCase):
|
26 | 28 |
|
| 29 | + def tearDown(self): |
| 30 | + self.driver.switch_to.default_content() |
| 31 | + |
27 | 32 | def testClickingOnAnchorScrollsPage(self):
|
28 |
| - scrollScript = "var pageY;\ |
29 |
| - if (typeof(window.pageYOffset) == 'number') {\ |
30 |
| - pageY = window.pageYOffset;\ |
31 |
| - } else {\ |
32 |
| - pageY = document.documentElement.scrollTop;\ |
33 |
| - }\ |
34 |
| - return pageY;" |
35 |
| - |
36 |
| - self._loadPage("macbeth") |
37 |
| - self.driver.find_element(By.PARTIAL_LINK_TEXT,"last speech").click() |
| 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" |
| 40 | + |
| 41 | + self._loadPage("macbeth") |
| 42 | + |
| 43 | + self.driver.find_element(By.PARTIAL_LINK_TEXT, "last speech").click() |
| 44 | + |
38 | 45 | yOffset = self.driver.execute_script(scrollScript)
|
39 | 46 |
|
40 | 47 | # Focusing on to click, but not actually following,
|
41 |
| - # the link will scroll it in to view, which is a few |
42 |
| - # pixels further than 0 |
43 |
| - self.assertTrue(yOffset > 300) |
| 48 | + # the link will scroll it in to view, which is a few pixels further than 0 |
| 49 | + self.assertGreater(300, yOffset) |
44 | 50 |
|
45 | 51 | def testShouldScrollToClickOnAnElementHiddenByOverflow(self):
|
46 |
| - self._loadPage("click_out_of_bounds_overflow") |
47 |
| - link = self.driver.find_element(By.ID, "link") |
| 52 | + url = self.webserver.where_is("click_out_of_bounds_overflow.html") |
| 53 | + self.driver.get(url) |
| 54 | + |
| 55 | + link =self.driver.find_element(By.ID,"link") |
48 | 56 | try:
|
49 | 57 | link.click()
|
50 |
| - except MoveTargetOutOfBoundsException: |
51 |
| - self.fail("Should not be out of bounds") |
| 58 | + except MoveTargetOutOfBoundsException as e: |
| 59 | + self.fail("Should not be out of bounds: %s" % e.msg) |
52 | 60 |
|
53 |
| - @pytest.mark.ignore_chrome |
54 | 61 | def testShouldBeAbleToClickOnAnElementHiddenByOverflow(self):
|
55 |
| - self._loadPage("scroll") |
56 |
| - link = self.driver.find_element(By.ID, "line8") |
| 62 | + self.driver.get(self.webserver.where_is("scroll.html")) |
| 63 | + |
| 64 | + link =self.driver.find_element(By.ID,"line8") |
| 65 | + # This used to throw a MoveTargetOutOfBoundsException - we don't expect it to |
57 | 66 | link.click()
|
58 |
| - self.assertEqual("line8", self.driver.find_element(By.ID, "clicked").text) |
| 67 | + self.assertEquals("line8", self.driver.find_element(By.ID,"clicked").text) |
| 68 | + |
| 69 | + |
| 70 | + def testShouldBeAbleToClickOnAnElementHiddenByDoubleOverflow(self): |
| 71 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_double_overflow_auto.html")) |
| 72 | + |
| 73 | + self.driver.find_element(By.ID,"link").click() |
| 74 | + WebDriverWait(self.driver, 3).until(EC.title_is("Clicked Successfully!")) |
| 75 | + |
| 76 | + def testShouldBeAbleToClickOnAnElementHiddenByYOverflow(self): |
| 77 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_y_overflow_auto.html")) |
| 78 | + |
| 79 | + self.driver.find_element(By.ID,"link").click() |
| 80 | + WebDriverWait(self.driver, 3).until(EC.title_is("Clicked Successfully!")) |
59 | 81 |
|
60 |
| - @pytest.mark.ignore_chrome |
61 | 82 | def testShouldNotScrollOverflowElementsWhichAreVisible(self):
|
62 |
| - self._loadPage("scroll2") |
| 83 | + self.driver.get(self.webserver.where_is("scroll2.html")) |
63 | 84 | list = self.driver.find_element(By.TAG_NAME, "ul")
|
64 | 85 | item = list.find_element(By.ID, "desired")
|
65 | 86 | item.click()
|
66 |
| - yOffset = self.driver.execute_script("return arguments[0].scrollTop;", list) |
67 |
| - self.assertEqual(0, yOffset) |
| 87 | + yOffset = self.driver.execute_script("return arguments[0].scrollTop", list) |
| 88 | + self.assertEquals(0, yOffset, "Should not have scrolled") |
68 | 89 |
|
69 |
| - @pytest.mark.ignore_chrome |
70 |
| - @pytest.mark.ignore_safari |
71 | 90 | def testShouldNotScrollIfAlreadyScrolledAndElementIsInView(self):
|
72 |
| - self._loadPage("scroll3") |
| 91 | + self.driver.get(self.webserver.where_is("scroll3.html")) |
73 | 92 | self.driver.find_element(By.ID, "button1").click()
|
74 |
| - scrollTop = self.driver.execute_script("return document.body.scrollTop;") |
| 93 | + scrollTop = self.getScrollTop() |
75 | 94 | self.driver.find_element(By.ID, "button2").click()
|
76 |
| - self.assertEqual(scrollTop, self.driver.execute_script("return document.body.scrollTop;")) |
| 95 | + self.assertEquals(scrollTop, self.getScrollTop()) |
77 | 96 |
|
78 | 97 | def testShouldBeAbleToClickRadioButtonScrolledIntoView(self):
|
79 |
| - self._loadPage("scroll4") |
80 |
| - self.driver.find_element(By.ID, "radio").click() |
81 |
| - # If we dont throw we are good |
82 |
| - |
83 |
| - @pytest.mark.ignore_ie |
| 98 | + self.driver.get(self.webserver.where_is("scroll4.html")) |
| 99 | + self.driver.find_element(By.ID,"radio").click() |
| 100 | + # If we don't throw, we're good |
| 101 | + |
84 | 102 | def testShouldScrollOverflowElementsIfClickPointIsOutOfViewButElementIsInView(self):
|
85 |
| - self._loadPage("scroll5") |
86 |
| - self.driver.find_element(By.ID, "inner").click() |
87 |
| - self.assertEqual("clicked", self.driver.find_element(By.ID, "clicked").text) |
| 103 | + self.driver.get(self.webserver.where_is("scroll5.html")) |
| 104 | + self.driver.find_element(By.ID,"inner").click() |
| 105 | + self.assertEquals("clicked",self.driver.find_element(By.ID,"clicked").text) |
| 106 | + |
| 107 | + def testShouldBeAbleToClickElementInAFrameThatIsOutOfView(self): |
| 108 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_frame_out_of_view.html")) |
| 109 | + self.driver.switch_to.frame(self.driver.find_element_by_name("frame")) |
| 110 | + element = self.driver.find_element(By.NAME, "checkbox") |
| 111 | + element.click() |
| 112 | + self.assertTrue(element.is_selected()) |
| 113 | + |
| 114 | + def testShouldBeAbleToClickElementThatIsOutOfViewInAFrame(self): |
| 115 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_scrolling_frame.html")) |
| 116 | + self.driver.switch_to.frame(self.driver.find_element_by_name("scrolling_frame")) |
| 117 | + element = self.driver.find_element(By.NAME, "scroll_checkbox") |
| 118 | + element.click() |
| 119 | + self.assertTrue(element.is_selected()) |
| 120 | + |
| 121 | + @pytest.mark.ignore_chrome |
| 122 | + @pytest.mark.ignore_marionette |
| 123 | + @pytest.mark.ignore_firefox |
| 124 | + @pytest.mark.ignore_phantomjs |
| 125 | + def testShouldNotBeAbleToClickElementThatIsOutOfViewInANonScrollableFrame(self): |
| 126 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_non_scrolling_frame.html")) |
| 127 | + self.driver.switch_to.frame("scrolling_frame") |
| 128 | + element = self.driver.find_element(By.NAME, "scroll_checkbox") |
| 129 | + element.click() |
| 130 | + |
| 131 | + def testShouldBeAbleToClickElementThatIsOutOfViewInAFrameThatIsOutOfView(self): |
| 132 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_scrolling_frame_out_of_view.html")) |
| 133 | + self.driver.switch_to.frame(self.driver.find_element_by_name("scrolling_frame")) |
| 134 | + element = self.driver.find_element(By.NAME, "scroll_checkbox") |
| 135 | + element.click() |
| 136 | + self.assertTrue(element.is_selected()) |
| 137 | + |
| 138 | + def testShouldBeAbleToClickElementThatIsOutOfViewInANestedFrame(self): |
| 139 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_nested_scrolling_frames.html")) |
| 140 | + self.driver.switch_to.frame(self.driver.find_element_by_name("scrolling_frame")) |
| 141 | + self.driver.switch_to.frame(self.driver.find_element_by_name("nested_scrolling_frame")) |
| 142 | + element = self.driver.find_element(By.NAME, "scroll_checkbox") |
| 143 | + element.click() |
| 144 | + self.assertTrue(element.is_selected()) |
| 145 | + |
| 146 | + def testShouldBeAbleToClickElementThatIsOutOfViewInANestedFrameThatIsOutOfView(self): |
| 147 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html")) |
| 148 | + self.driver.switch_to.frame(self.driver.find_element_by_name("scrolling_frame")) |
| 149 | + self.driver.switch_to.frame(self.driver.find_element_by_name("nested_scrolling_frame")) |
| 150 | + element = self.driver.find_element(By.NAME, "scroll_checkbox") |
| 151 | + element.click() |
| 152 | + self.assertTrue(element.is_selected()) |
| 153 | + |
| 154 | + def testShouldNotScrollWhenGettingElementSize(self): |
| 155 | + self.driver.get(self.webserver.where_is("scroll3.html")) |
| 156 | + scrollTop = self.getScrollTop() |
| 157 | + self.driver.find_element(By.ID,"button1").size |
| 158 | + self.assertEquals(scrollTop, self.getScrollTop()) |
| 159 | + |
| 160 | + def getScrollTop(self): |
| 161 | + return self.driver.execute_script("return document.body.scrollTop") |
| 162 | + |
| 163 | + def testShouldBeAbleToClickElementInATallFrame(self): |
| 164 | + self.driver.get(self.webserver.where_is("scrolling_tests/page_with_tall_frame.html")) |
| 165 | + self.driver.switch_to.frame(self.driver.find_element_by_name("tall_frame")) |
| 166 | + element = self.driver.find_element(By.NAME, "checkbox") |
| 167 | + element.click() |
| 168 | + self.assertTrue(element.is_selected()) |
88 | 169 |
|
89 | 170 | def _loadPage(self, name):
|
90 | 171 | self.driver.get(self._pageURL(name))
|
|
0 commit comments