8
8
9
9
from codebender_testing .config import TEST_PROJECT_NAME
10
10
from codebender_testing .utils import SeleniumTestCase
11
+ from codebender_testing .utils import SELECT_BOARD_SCRIPT
12
+ from codebender_testing .utils import throttle_compile
11
13
12
14
13
15
# 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
16
18
17
19
# Board to test for the dropdown selector.
18
20
TEST_BOARD = "Arduino Fio"
@@ -22,29 +24,32 @@ class TestSketch(SeleniumTestCase):
22
24
"""Tests various functions of the /sketch view."""
23
25
24
26
@pytest .fixture (scope = "class" , autouse = True )
25
- def open_test_project (self , tester_login ):
27
+ def create_test_project (self , tester_login ):
26
28
"""Makes sure we are logged in and have a project open before
27
29
performing any of these tests."""
28
- self .open_project ( )
30
+ self .create_sketch ( TEST_PROJECT_NAME )
29
31
30
32
def test_verify_code (self ):
31
33
"""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 ()
34
39
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
+ )
38
44
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 ()
43
48
44
49
def test_boards_dropdown (self ):
45
50
"""Tests that the boards dropdown is present, and that we can change
46
51
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 " ))
48
53
49
54
# Click something other than the first option
50
55
boards_dropdown .select_by_visible_text (TEST_BOARD )
@@ -54,40 +59,43 @@ def test_boards_dropdown(self):
54
59
@pytest .mark .requires_extension
55
60
def test_ports_dropdown (self ):
56
61
"""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'
58
64
59
65
@pytest .mark .requires_extension
60
66
def test_run_with_no_port (self ):
61
67
"""Makes sure that there is an error when we attempt to run with no
62
68
port selected."""
63
- flash_button = self .get_element (By .ID , "uploadusb " )
69
+ flash_button = self .get_element (By .ID , "cb_cf_flash_btn " )
64
70
flash_button .click ()
65
71
WebDriverWait (self .driver , FLASH_TIMEOUT ).until (
66
72
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
+ )
68
76
69
77
@pytest .mark .requires_extension
70
78
def test_speeds_dropdown (self ):
71
79
"""Tests that the speeds dropdown exists."""
72
- self .get_element (By .ID , "baudrates " )
80
+ self .get_element (By .ID , "cb_cf_baud_rates " )
73
81
74
82
@pytest .mark .requires_extension
75
83
def test_serial_monitor_disables_fields (self ):
76
84
"""Tests that opening the serial monitor disables the port and baudrate
77
85
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 ' )
79
87
open_serial_monitor_button .click ()
80
88
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
+ )
86
94
87
95
def test_clone_project (self ):
88
96
"""Tests that clicking the 'Clone Project' link brings us to a new
89
97
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 ' )
91
99
clone_link .click ()
92
100
project_name = self .get_element (By .ID , 'editor_heading_project_name' )
93
101
# Here, I use `startswith` in case the user has a bunch of
@@ -97,42 +105,56 @@ def test_clone_project(self):
97
105
# Cleanup: delete the project we just created.
98
106
self .delete_project ("%s copy" % TEST_PROJECT_NAME )
99
107
100
-
101
108
def test_add_projectfile_direct (self ):
102
109
""" Tests that new file can be added to project using create-new-file
103
110
field """
104
111
self .open_project ()
105
112
106
- add_button = self .get_element (By .CLASS_NAME , 'icon-plus ' )
113
+ add_button = self .get_element (By .CLASS_NAME , 'add-file-button ' )
107
114
add_button .click ()
115
+ WebDriverWait (self .driver , VERIFY_TIMEOUT ).until (
116
+ expected_conditions .visibility_of (
117
+ self .get_element (By .ID , "creationModal" )
118
+ )
119
+ )
108
120
create_field = self .get_element (By .ID , 'createfield' )
109
121
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 ' )
111
123
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
+ )
113
129
assert 'test_file.txt' in self .driver .page_source
114
130
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
-
126
131
def test_delete_file (self ):
127
132
"""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 ' )
129
134
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 ()
132
141
133
142
def test_verify_deletion (self ):
134
143
""" Verifies that file has been deleted """
135
144
confirm_delete_button = self .get_element (By .ID , 'filedeleteButton' )
136
145
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 )
0 commit comments