Skip to content

Commit 0e00eeb

Browse files
committed
Moved tests for live site into a seperate directory.
Needed in order to run these tests separately from the compilation tests.
1 parent 67d170c commit 0e00eeb

File tree

10 files changed

+151
-129
lines changed

10 files changed

+151
-129
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from codebender_testing.utils import CodebenderEmbeddedTestCase
2+
import re
3+
4+
5+
EMBEDDED_VIEWS = [
6+
'http://blog.codebender.cc/2014/03/07/lesson-1-inputs-and-outputs/',
7+
'https://www.sparkfun.com/news/1803',
8+
'http://1sheeld.com/blog/announcing-4-new-shields-tasker-integration-partnership-with-codebender/',
9+
'http://edu.olympiacircuits.com/codebender.html',
10+
'http://redbearlab.com/quick-start-codebender/',
11+
'https://tiny-circuits.com/tinyscreen',
12+
'http://lowpowerlab.com/programming/',
13+
'http://lowpowerlab.com/blog/2014/12/03/moteino-now-on-codebender-cc/',
14+
'http://microview.io/intro/getting-started.html',
15+
'http://www.hummingbirdkit.com/learning/arduino-programming'
16+
]
17+
18+
19+
class TestHome(CodebenderEmbeddedTestCase):
20+
21+
def test_embedded_views(self):
22+
embed_sketch_re = re.compile('^https:\/\/codebender\.cc\/embed\/sketch:\d+$')
23+
example_re = re.compile('^https:\/\/codebender\.cc\/example\/.+$$')
24+
serial_monitor_re = re.compile('^https:\/\/codebender\.cc\/embed\/serialmonitor$$')
25+
for embedded in EMBEDDED_VIEWS:
26+
self.open(embedded)
27+
iframes = self.driver.find_elements_by_tag_name('iframe')
28+
test_iframes = []
29+
for iframe in iframes:
30+
iframe_src = iframe.get_attribute('src')
31+
if embed_sketch_re.match(iframe_src):
32+
self.test_embedded_sketch(iframe_src)
File renamed without changes.
Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,88 @@
11
from codebender_testing.config import TEST_CREDENTIALS
22
from codebender_testing.utils import SeleniumTestCase
33
from selenium.webdriver.common.keys import Keys
4+
from selenium.webdriver.common.by import By
5+
from codebender_testing import config
6+
import os
47

58
class TestHome(SeleniumTestCase):
69

710
def test_navigate_home(self, tester_logout):
811
""" opens browser to codebender bachelor """
912
self.open("/")
10-
assert "Codebender" in self.driver.title
13+
assert "codebender" in self.driver.title
1114

1215
def test_login(self, tester_logout):
16+
credentials = {
17+
'username': os.environ.get('CODEBENDER_TEST_USER', config.TEST_CREDENTIALS['username']),
18+
'password': os.environ.get('CODEBENDER_TEST_PASS', config.TEST_CREDENTIALS['password']),
19+
}
1320
driver = self.driver
1421
self.open("/")
1522

1623
""" tests to ensure login div appears """
17-
login_elem = driver.find_element_by_id("login_btn") #finds login button
24+
login_elem = self.get_element(By.ID, "login_btn") #finds login button
1825
login_elem.send_keys(Keys.RETURN) #clicks login button
19-
logbox_elem = driver.find_element_by_id("login_box") #finds login div
26+
logbox_elem = self.get_element(By.ID, "login_box") #finds login div
2027
assert logbox_elem.is_displayed() #checks to see if div is visible
2128

2229
""" tests login with invalid username """
2330
# define elements in login form
24-
username_elem = driver.find_element_by_id("username")
25-
password_elem = driver.find_element_by_id("password")
26-
submit_elem = driver.find_element_by_id("_submit")
31+
username_elem = self.get_element(By.ID, "username")
32+
password_elem = self.get_element(By.ID, "password")
33+
submit_elem = self.get_element(By.ID, "_submit")
2734

2835
# enter invalid username with correct password
29-
username_elem.send_keys("codebender")
30-
password_elem.send_keys(TEST_CREDENTIALS['password'])
36+
username_elem.send_keys("asdfghjklpoiuytrewqzxcvbnm")
37+
password_elem.send_keys('1234567890')
3138
submit_elem.click()
3239

3340
# check for error message
34-
error_elem = driver.find_element_by_class_name('text-error')
41+
error_elem = self.get_element(By.CLASS_NAME, 'text-error')
3542
assert error_elem.is_displayed()
43+
assert error_elem.text.strip() == 'Invalid username or password'
3644

3745
""" tests login with invalid password """
3846
# refresh page so error message no longer visible
3947
driver.refresh()
4048

4149
# re-click on login button
42-
login_elem = driver.find_element_by_id("login_btn")
50+
login_elem = self.get_element(By.ID, "login_btn")
4351
login_elem.send_keys(Keys.RETURN)
4452

4553
# re-define elements in login form
46-
username_elem = driver.find_element_by_id("username")
47-
password_elem = driver.find_element_by_id("password")
48-
submit_elem = driver.find_element_by_id("_submit")
54+
username_elem = self.get_element(By.ID, "username")
55+
password_elem = self.get_element(By.ID, "password")
56+
submit_elem = self.get_element(By.ID, "_submit")
4957

5058
# enter correct username with invalid password
5159
username_elem.clear()
52-
username_elem.send_keys(TEST_CREDENTIALS['username'])
53-
password_elem.send_keys("codebender")
60+
username_elem.send_keys(credentials['username'])
61+
password_elem.send_keys(1234567890)
5462
submit_elem.click()
5563

5664
# re-define error message element and test
57-
error_elem = driver.find_element_by_class_name('text-error')
65+
error_elem = self.get_element(By.CLASS_NAME, 'text-error')
5866
assert error_elem.is_displayed()
67+
assert error_elem.text.strip() == 'Invalid username or password'
5968

6069
""" tests that login takes you to user's home """
6170
# refresh page so error message no longer visible
6271
driver.refresh()
6372

6473
# re-click on login button
65-
login_elem = driver.find_element_by_id("login_btn")
74+
login_elem = self.get_element(By.ID, "login_btn")
6675
login_elem.send_keys(Keys.RETURN)
6776

6877
# re-define elements in login form
69-
username_elem = driver.find_element_by_id("username")
70-
password_elem = driver.find_element_by_id("password")
71-
submit_elem = driver.find_element_by_id("_submit")
78+
username_elem = self.get_element(By.ID, "username")
79+
password_elem = self.get_element(By.ID, "password")
80+
submit_elem = self.get_element(By.ID, "_submit")
7281

7382
# log in to site using correct credentials
7483
username_elem.clear()
7584
password_elem.clear()
76-
username_elem.send_keys(TEST_CREDENTIALS['username'])
77-
password_elem.send_keys(TEST_CREDENTIALS['password'])
85+
username_elem.send_keys(credentials['username'])
86+
password_elem.send_keys(credentials['password'])
7887
submit_elem.click()
7988
assert "Logged in as" in driver.page_source
File renamed without changes.

tests/sketch/test_sketch.py renamed to tests/common/sketch/test_sketch.py

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
from codebender_testing.config import TEST_PROJECT_NAME
1010
from codebender_testing.utils import SeleniumTestCase
11+
from codebender_testing.utils import SELECT_BOARD_SCRIPT
12+
from codebender_testing.utils import throttle_compile
1113

1214

1315
# How long to wait before we give up on trying to assess the result of commands
14-
VERIFY_TIMEOUT = 10
15-
FLASH_TIMEOUT = 2
16+
VERIFY_TIMEOUT = 30
17+
FLASH_TIMEOUT = 30
1618

1719
# Board to test for the dropdown selector.
1820
TEST_BOARD = "Arduino Fio"
@@ -22,29 +24,32 @@ class TestSketch(SeleniumTestCase):
2224
"""Tests various functions of the /sketch view."""
2325

2426
@pytest.fixture(scope="class", autouse=True)
25-
def open_test_project(self, tester_login):
27+
def create_test_project(self, tester_login):
2628
"""Makes sure we are logged in and have a project open before
2729
performing any of these tests."""
28-
self.open_project()
30+
self.create_sketch(TEST_PROJECT_NAME)
2931

3032
def test_verify_code(self):
3133
"""Ensures that we can compile code and see the success message."""
32-
compile_button = self.get_element(By.ID, "compile")
33-
compile_button.click()
34+
boards = ['Arduino Uno', 'Arduino Leonardo', 'Arduino Mega 2560 or Mega ADK']
35+
for board in boards:
36+
self.execute_script(SELECT_BOARD_SCRIPT(board))
37+
compile_button = self.get_element(By.ID, "cb_cf_verify_btn")
38+
compile_button.click()
3439

35-
# test progress bar is visible
36-
progress_bar = self.get_element(By.ID, 'progress')
37-
assert progress_bar.is_displayed()
40+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
41+
expected_conditions.invisibility_of_element_located(
42+
(By.ID, "progress"))
43+
)
3844

39-
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
40-
expected_conditions.text_to_be_present_in_element(
41-
(By.ID, "operation_output"), "Verification Successful!")
42-
)
45+
operation_output = self.driver.find_element_by_id('operation_output')
46+
assert operation_output.text.strip() == 'Verification successful!'
47+
throttle_compile()
4348

4449
def test_boards_dropdown(self):
4550
"""Tests that the boards dropdown is present, and that we can change
4651
the board successfully."""
47-
boards_dropdown = Select(self.get_element(By.ID, "boards"))
52+
boards_dropdown = Select(self.get_element(By.ID, "cb_cf_boards"))
4853

4954
# Click something other than the first option
5055
boards_dropdown.select_by_visible_text(TEST_BOARD)
@@ -54,40 +59,43 @@ def test_boards_dropdown(self):
5459
@pytest.mark.requires_extension
5560
def test_ports_dropdown(self):
5661
"""Tests that the ports dropdown exists."""
57-
self.get_element(By.ID, "ports")
62+
ports = self.get_element(By.ID, "cb_cf_ports")
63+
assert ports.text == 'No ports detected'
5864

5965
@pytest.mark.requires_extension
6066
def test_run_with_no_port(self):
6167
"""Makes sure that there is an error when we attempt to run with no
6268
port selected."""
63-
flash_button = self.get_element(By.ID, "uploadusb")
69+
flash_button = self.get_element(By.ID, "cb_cf_flash_btn")
6470
flash_button.click()
6571
WebDriverWait(self.driver, FLASH_TIMEOUT).until(
6672
expected_conditions.text_to_be_present_in_element(
67-
(By.ID, "operation_output"), "Please select a valid port or enable the plugin!!"))
73+
(By.ID, "operation_output"), "Please select a valid port!"
74+
)
75+
)
6876

6977
@pytest.mark.requires_extension
7078
def test_speeds_dropdown(self):
7179
"""Tests that the speeds dropdown exists."""
72-
self.get_element(By.ID, "baudrates")
80+
self.get_element(By.ID, "cb_cf_baud_rates")
7381

7482
@pytest.mark.requires_extension
7583
def test_serial_monitor_disables_fields(self):
7684
"""Tests that opening the serial monitor disables the port and baudrate
7785
fields."""
78-
open_serial_monitor_button = self.get_element(By.ID, 'toggle_connect_serial')
86+
open_serial_monitor_button = self.get_element(By.ID, 'cb_cf_serial_monitor_connect')
7987
open_serial_monitor_button.click()
8088

81-
baudrate_field = self.get_element(By.ID, 'baudrates_placeholder')
82-
assert baudrate_field.get_attribute('disabled') == 'true'
83-
84-
ports_field = self.get_element(By.ID, 'ports_placeholder')
85-
assert ports_field.get_attribute('disabled') == 'true'
89+
WebDriverWait(self.driver, FLASH_TIMEOUT).until(
90+
expected_conditions.text_to_be_present_in_element(
91+
(By.ID, "operation_output"), 'Please select a valid port!'
92+
)
93+
)
8694

8795
def test_clone_project(self):
8896
"""Tests that clicking the 'Clone Project' link brings us to a new
8997
sketch with the title 'test_project clone'."""
90-
clone_link = self.get_element(By.LINK_TEXT, 'Clone Project')
98+
clone_link = self.get_element(By.ID, 'clone_btn')
9199
clone_link.click()
92100
project_name = self.get_element(By.ID, 'editor_heading_project_name')
93101
# Here, I use `startswith` in case the user has a bunch of
@@ -97,42 +105,56 @@ def test_clone_project(self):
97105
# Cleanup: delete the project we just created.
98106
self.delete_project("%s copy" % TEST_PROJECT_NAME)
99107

100-
101108
def test_add_projectfile_direct(self):
102109
""" Tests that new file can be added to project using create-new-file
103110
field """
104111
self.open_project()
105112

106-
add_button = self.get_element(By.CLASS_NAME, 'icon-plus')
113+
add_button = self.get_element(By.CLASS_NAME, 'add-file-button')
107114
add_button.click()
115+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
116+
expected_conditions.visibility_of(
117+
self.get_element(By.ID, "creationModal")
118+
)
119+
)
108120
create_field = self.get_element(By.ID, 'createfield')
109121
create_field.send_keys('test_file.txt')
110-
create_button = self.get_element(By.CLASS_NAME, 'btn')
122+
create_button = self.get_element(By.ID, 'createbutton')
111123
create_button.click()
112-
self.driver.refresh()
124+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
125+
expected_conditions.invisibility_of_element_located(
126+
(By.ID, "creationModal")
127+
)
128+
)
113129
assert 'test_file.txt' in self.driver.page_source
114130

115-
'''
116-
def test_add_projectfile_upload(self):
117-
""" Tests that new file can be added to project using upload dialog """
118-
add_button = self.get_element(By.CLASS_NAME, 'icon-plus')
119-
add_button.click()
120-
drop_zone = self.get_element(By.CLASS_NAME, 'dz-clickable')
121-
drop_zone.click()
122-
self.driver.get("http://localhost/js/dropzone/min.js")
123-
self.driver.execute_script("self.get_element(By.NAME,'uploadType').value = '/test.h'")
124-
#file_input_element = self.get_element(By.NAME, 'uploadType')'''
125-
126131
def test_delete_file(self):
127132
"""Tests file delete modal """
128-
delete_file_button = self.get_element(By.CLASS_NAME, 'icon-remove')
133+
delete_file_button = self.get_element(By.CLASS_NAME, 'delete-file-button')
129134
delete_file_button.click()
130-
delete_modal = self.get_element(By.ID, 'filedeleteModal')
131-
assert delete_modal.is_displayed()
135+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
136+
expected_conditions.visibility_of(
137+
self.get_element(By.ID, "filedeleteModal")
138+
)
139+
)
140+
assert self.get_element(By.ID, 'filedeleteModal').is_displayed()
132141

133142
def test_verify_deletion(self):
134143
""" Verifies that file has been deleted """
135144
confirm_delete_button = self.get_element(By.ID, 'filedeleteButton')
136145
confirm_delete_button.click()
137-
self.driver.refresh()
138-
assert 'test_file.txt' not in self.driver.page_source
146+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
147+
expected_conditions.invisibility_of_element_located(
148+
(By.ID, "filedeleteModal")
149+
)
150+
)
151+
operation_output = self.get_element(By.ID, 'operation_output')
152+
assert operation_output.text.strip() == 'File successfully deleted.'
153+
WebDriverWait(self.driver, VERIFY_TIMEOUT).until(
154+
expected_conditions.invisibility_of_element_located(
155+
(By.CSS_SELECTOR, '#files_list a[data-name="test_file.txt"]')
156+
)
157+
)
158+
159+
def test_remove_sketch(self):
160+
self.delete_project(TEST_PROJECT_NAME)
File renamed without changes.

0 commit comments

Comments
 (0)