Skip to content

Commit 24af966

Browse files
author
Brandon Duffany
committed
Add user homepage tests
1 parent 0401872 commit 24af966

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

codebender_testing/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
# URL of the site to be used for testing
77
BASE_URL = "http://localhost"
88

9+
# URL of the actual Codebender website
10+
LIVE_SITE_URL = "http://codebender.cc"
911

1012
_EXTENSIONS_DIR = 'extensions'
1113
_FIREFOX_EXTENSION_FNAME = 'codebender.xpi'
1214

15+
# Files used for testing
16+
TEST_DATA_DIR = 'test_data'
17+
TEST_DATA_BLANK_PROJECT = os.path.join(TEST_DATA_DIR, 'blank_project.ino')
18+
1319
# Set up Selenium Webdrivers to be used for selenium tests
1420

1521
def _get_firefox_profile():

codebender_testing/utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from selenium import webdriver
44
from selenium.common.exceptions import NoSuchElementException
5+
from selenium.webdriver.common.by import By
56
from selenium.webdriver.common.keys import Keys
67
from selenium.webdriver.support import expected_conditions
78
from selenium.webdriver.support.ui import WebDriverWait
@@ -28,7 +29,7 @@ def _testcase_attrs(cls, webdriver):
2829
cls.driver = webdriver
2930

3031
@pytest.fixture(scope="class")
31-
def tester_login(self):
32+
def tester_login(self):
3233
self.login()
3334

3435
def open(self, url=None):
@@ -77,6 +78,16 @@ def get_element(self, *locator):
7778
"""Waits for an element specified by *locator (a tuple of
7879
(By.<something>, str)), then returns it if it is found."""
7980
WebDriverWait(self.driver, ELEMENT_FIND_TIMEOUT).until(
80-
expected_conditions.presence_of_element_located(locator))
81+
expected_conditions.visibility_of_element_located(locator))
8182
return self.driver.find_element(*locator)
82-
83+
84+
def delete_project(self, project_name):
85+
"""Deletes the project specified by `project_name`. Note that this will
86+
navigate to the user's homepage."""
87+
self.open('/')
88+
created_project = self.get_element(By.LINK_TEXT, project_name)
89+
delete_button_li = created_project.find_element_by_xpath('..')
90+
delete_button = delete_button_li.find_element_by_css_selector('button:last-child')
91+
delete_button.click()
92+
popup_delete_button = self.get_element(By.ID, 'deleteProjectButton')
93+
popup_delete_button.click()

test_data/blank_project.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* A blank Arduino project.
3+
* This should compile with no issues.
4+
*/
5+
6+
void setup() {
7+
}
8+
9+
void loop() {
10+
}

tests/user_home/__init__.py

Whitespace-only changes.

tests/user_home/test_user_home.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from selenium.webdriver.common.by import By
2+
import pytest
3+
4+
from codebender_testing.config import TEST_DATA_BLANK_PROJECT
5+
from codebender_testing.utils import SeleniumTestCase
6+
7+
8+
# Name to be used for the new project that is created.
9+
NEW_PROJECT_NAME = 'selenium_TestUserHome'
10+
11+
class TestUserHome(SeleniumTestCase):
12+
13+
@pytest.fixture(scope="class", autouse=True)
14+
def open_user_home(self, tester_login):
15+
"""Makes sure we are logged in and are at the user home page
16+
performing any of these tests."""
17+
pass
18+
19+
def test_create_project_blank_name(self):
20+
"""Test that we get an error when creating a project with no name."""
21+
create_button = self.get_element(By.CSS_SELECTOR, '.form-search button')
22+
create_button.click()
23+
error_heading = self.get_element(By.CSS_SELECTOR, '.alert h4')
24+
assert error_heading.text.startswith('Error')
25+
26+
def test_create_project_invalid_name(self):
27+
"""Test that we get an error when creating a project with an
28+
invalid name (e.g., a name containing a backslash).
29+
"""
30+
project_name_input = self.get_element(By.CSS_SELECTOR,
31+
'.form-search input[type=text]')
32+
project_name_input.clear()
33+
project_name_input.send_keys('foo\\bar')
34+
create_button = self.get_element(By.CSS_SELECTOR, '.form-search button')
35+
create_button.click()
36+
37+
error_heading = self.get_element(By.CSS_SELECTOR, '.alert h4')
38+
assert error_heading.text.startswith('Error')
39+
40+
def test_create_project_valid_name(self):
41+
"""Test that we can successfully create a project with a valid name."""
42+
project_name_input = self.get_element(By.CSS_SELECTOR,
43+
'.form-search input[type=text]')
44+
project_name_input.clear()
45+
project_name_input.send_keys(NEW_PROJECT_NAME)
46+
create_button = self.get_element(By.CSS_SELECTOR, '.form-search button')
47+
create_button.click()
48+
49+
project_heading = self.get_element(By.ID, 'editor_heading_project_name')
50+
assert project_heading.text == NEW_PROJECT_NAME
51+
52+
# Cleanup: delete the project we just created.
53+
self.delete_project(NEW_PROJECT_NAME)
54+

0 commit comments

Comments
 (0)