Skip to content

Commit 10ff3e9

Browse files
committed
2 parents 312dd7e + 9320a55 commit 10ff3e9

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
# seleniumTests
2-
Selenium tests for the codebender website
1+
# Codebender Selenium Tests
2+
3+
This repo contains Selenium tests for the codebender website.
4+
The tests are written in Python 3.
5+
6+
## Running Tests
7+
8+
To run tests locally, you'll need to be running a selenium server. See
9+
[here](https://selenium-python.readthedocs.org/installation.html#downloading-selenium-server)
10+
for instructions.
11+
12+
Once you've got a Selenium server running, simply run `$ tox` from within the
13+
repo. If you don't have tox, run `$ sudo pip3 install -r requirements-dev.txt`
14+
from within the repo to install it.
15+
16+
When running tox, you might get a `pkg_resources.DistributionNotFound` error
17+
with reference to `virtualenv`. This is likely due to an out of date setuptools.
18+
To fix this issue, run `$ sudo pip3 install -U setuptools`.

codebender_testing/config.py

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

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

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.

requirements-dev.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tox
2+
pytest
3+
virtualenv
4+

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
pytest==2.6.4
22
selenium==2.44.0
3-
tox==1.8.1
4-
virtualenv==12.0.6

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)