2
2
from time import gmtime
3
3
from time import strftime
4
4
import json
5
+ import os
5
6
import re
6
7
import tempfile
7
8
@@ -161,6 +162,30 @@ def open_project(self, project_name=None):
161
162
project_link = self .driver .find_element_by_link_text (project_name )
162
163
project_link .send_keys (Keys .ENTER )
163
164
165
+ def upload_project (self , test_fname , project_name = None ):
166
+ """Tests that we can successfully upload `test_fname`.
167
+ `project_name` is the expected name of the project; by
168
+ default it is inferred from the file name.
169
+ Returns a pair of (the name of the project, the url of the project sketch)
170
+ """
171
+ # A tempfile is used here since we want the name to be
172
+ # unique; if the file has already been successfully uploaded
173
+ # then the test might give a false-positive.
174
+ with temp_copy (test_fname ) as test_file :
175
+ self .dropzone_upload ("#dropzoneForm" , test_file .name )
176
+ if project_name is None :
177
+ project_name = os .path .split (test_file .name )[- 1 ].split ('.' )[0 ]
178
+
179
+ # The upload was successful <==> we get a green "check" on its
180
+ # Dropzone upload indicator
181
+ self .get_element (By .CSS_SELECTOR , '#dropzoneForm .dz-success' )
182
+
183
+ # Make sure the project shows up in the Projects list
184
+ last_project = self .get_element (By .CSS_SELECTOR ,
185
+ '#sidebar-list-main li:last-child .project_link' )
186
+
187
+ return last_project .text , last_project .get_attribute ('href' )
188
+
164
189
def login (self ):
165
190
"""Performs a login."""
166
191
try :
@@ -244,20 +269,25 @@ def dropzone_upload(self, selector, fname):
244
269
test_input .send_keys (fname )
245
270
self .execute_script (_move_file_to_dropzone_script (selector ))
246
271
247
- def compile_all_sketches (self , url , selector , iframe = False , logfile = None ):
248
- """Compiles all projects on the page at `url`. `selector` is a CSS selector
272
+ def compile_all_sketches (self , url , selector , ** kwargs ):
273
+ """Compiles all sketches on the page at `url`. `selector` is a CSS selector
249
274
that should select all relevant <a> tags containing links to sketches.
275
+ See `compile_sketches` for the possible keyword arguments that can be specified.
276
+ """
277
+ self .open (url )
278
+ sketches = self .execute_script (_GET_SKETCHES_SCRIPT .format (selector = selector ))
279
+ assert len (sketches ) > 0
280
+ self .compile_sketches (sketches , ** kwargs )
281
+
282
+ def compile_sketches (self , sketches , iframe = False , logfile = None ):
283
+ """Compiles the sketches with URLs given by the `sketches` list.
250
284
`logfile` specifies a path to a file to which test results will be
251
285
logged. If it is not `None`, compile errors will not cause the test
252
286
to halt, but rather be logged to the given file. `logfile` may be a time
253
287
format string, which will be formatted appropriately.
254
288
`iframe` specifies whether the urls pointed to by `selector` are contained
255
289
within an iframe.
256
290
"""
257
- self .open (url )
258
- sketches = self .execute_script (_GET_SKETCHES_SCRIPT .format (selector = selector ))
259
- assert len (sketches ) > 0
260
-
261
291
if logfile is None :
262
292
for sketch in sketches :
263
293
self .compile_sketch (sketch , iframe = iframe )
@@ -278,7 +308,6 @@ def compile_all_sketches(self, url, selector, iframe=False, logfile=None):
278
308
json .dump (log_entry , f )
279
309
f .close ()
280
310
281
-
282
311
def execute_script (self , script , * deps ):
283
312
"""Waits for all JavaScript variables in `deps` to be defined, then
284
313
executes the given script."""
0 commit comments