Skip to content

Commit f106534

Browse files
author
Brandon Duffany
committed
Add test for boards dropdown
1 parent 54d9b68 commit f106534

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

codebender_testing/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
"password": "testerPASS"
1717
}
1818

19-
# How long to wait before we give up on the 'verify' command (in seconds)
20-
VERIFY_TIMEOUT = 10
19+
TEST_PROJECT_NAME = "test_project"
2120

codebender_testing/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from codebender_testing.config import BASE_URL
1010
from codebender_testing.config import TEST_CREDENTIALS
11+
from codebender_testing.config import TEST_PROJECT_NAME
1112
from codebender_testing.config import WEBDRIVERS
1213

1314

@@ -38,6 +39,16 @@ def open(self, url=None):
3839
url = url.lstrip('/')
3940
return self.driver.get("%s/%s" % (BASE_URL, url))
4041

42+
def open_project(self, project_name=None):
43+
"""Opens the project specified by `name`, bringing the driver to the
44+
sketch view of that project. Opens the test project if `name` is
45+
unspecified. The driver must be logged in to use this function."""
46+
if project_name is None:
47+
project_name = TEST_PROJECT_NAME
48+
49+
project_link = self.driver.find_element_by_link_text(project_name)
50+
project_link.send_keys(Keys.ENTER)
51+
4152

4253
def logged_in(func):
4354
"""Decorator to ensure the user is logged in before performing a test.

tests/sketch/test_sketch.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
from selenium.webdriver.support import expected_conditions
77
from selenium.webdriver.support.ui import WebDriverWait
88

9-
from codebender_testing.config import VERIFY_TIMEOUT
109
from codebender_testing.utils import logged_in
1110
from codebender_testing.utils import SeleniumTestCase
1211

1312

13+
# How long to wait before we give up on the 'verify' command (in seconds)
14+
VERIFY_TIMEOUT = 10
15+
16+
# How long to wait before we give up on finding an element on the page.
17+
ELEMENT_FIND_TIMEOUT = 5
18+
19+
1420
class TestSketch(SeleniumTestCase):
1521

1622
@logged_in
1723
def test_verify_code(self):
18-
test_project_link = self.driver.find_element_by_link_text('test_project')
19-
test_project_link.send_keys(Keys.ENTER)
24+
self.open_project()
2025

2126
# I get a StaleElementReferenceException without
2227
# this wait. TODO: figure out how to get around this.
@@ -25,11 +30,24 @@ def test_verify_code(self):
2530
compile_button = self.driver.find_element_by_id("compile")
2631
compile_button.click()
2732

28-
try:
29-
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
30-
expected_conditions.text_to_be_present_in_element(
31-
(By.ID, "operation_output"), "Verification Successful!")
32-
)
33-
except:
34-
raise
33+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
34+
expected_conditions.text_to_be_present_in_element(
35+
(By.ID, "operation_output"), "Verification Successful!")
36+
)
37+
38+
@logged_in
39+
def test_boards_dropdown(self):
40+
self.open_project()
41+
42+
WebDriverWait(self.driver, ELEMENT_FIND_TIMEOUT).until(
43+
expected_conditions.presence_of_element_located(
44+
(By.ID, "boards"))
45+
)
46+
47+
boards_dropdown = self.driver.find_element_by_id("boards")
48+
options = boards_dropdown.find_elements_by_tag_name("option")
49+
50+
# Click something other than the first option
51+
test_option = options[3]
52+
test_option.click()
3553

0 commit comments

Comments
 (0)