Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit d1fdf14

Browse files
authored
Merge pull request #1180 from bjones1/more-tests
DRY: Refactor test framework.
2 parents 354cba8 + ad1025c commit d1fdf14

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

runestone/activecode/test/test_activecode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def find_ac(selenium_utils, div_id):
1313

1414
def click_run(selenium_utils, ac_selenium_element):
1515
# The run button can sometimes be scrolled to the top of the screen, where it's hidden by the navigation bar. In this case, we can't click it, since Selenium will complain ``Message: element click intercepted: Element <button class="btn btn-success run-button" type="button">...</button> is not clickable at point (460, 17). Other element would receive the click: <div class="navbar-collapse collapse navbar-ex1-collapse">...</div>``. To avoid this, always scroll to the top of the document, guaranteeing that the navbar won't be hiding the run button.
16-
selenium_utils.driver.execute_script("window.scrollTo(0, 0);")
16+
selenium_utils.scroll_to_top()
1717
rb = ac_selenium_element.find_element_by_class_name("run-button")
1818
rb.click()
1919
# After clicking run, the browser may need some time to load and execute the code. Wait until the run button becomes clickable, indicating the code has finished running.

runestone/shared_conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def get(self, relative_url):
7474
"{}/{}".format(self.host_address, relative_url)
7575
)
7676

77+
# Scroll to the top of the window. A button can sometimes be scrolled to the top of the screen, where it's hidden by the navigation bar. In this case, we can't click it, since Selenium will complain ``Message: element click intercepted: Element <button class="btn btn-success run-button" type="button">...</button> is not clickable at point (460, 17). Other element would receive the click: <div class="navbar-collapse collapse navbar-ex1-collapse">...</div>``. To avoid this, scroll to the top of the document, guaranteeing that the navbar won't be hiding the run button.
78+
def scroll_to_top(self):
79+
self.driver.execute_script("window.scrollTo(0, 0);")
80+
7781
# Wait until a Runestone component has finished rendering itself, given the ID of the component.
7882
def wait_until_ready(self, id):
7983
# The component is ready when it has the class below.

runestone/shortanswer/test/test_shortanswer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
def get_sa(selenium_utils):
1111
selenium_utils.wait_until_ready(DIV_ID)
12-
# See the notes in ``test_activecode.click_run`` on the need for this call.
13-
selenium_utils.driver.execute_script("window.scrollTo(0, 0);")
12+
selenium_utils.scroll_to_top()
1413
return selenium_utils.driver.find_element_by_id(DIV_ID)
1514

1615

0 commit comments

Comments
 (0)