29
29
"return $('{selector}').map(function() {{ return this.href; }}).toArray();"
30
30
31
31
# JavaScript snippet to verify the code on the current page.
32
- _VERIFY_SCRIPT = "compilerflasher.verify()"
32
+ _VERIFY_SCRIPT = """
33
+ if (window.compilerflasher !== undefined) {
34
+ compilerflasher.verify();
35
+ } else {
36
+ // BACHELOR
37
+ verify();
38
+ }
39
+ """
33
40
34
41
# How long (in seconds) to wait before assuming that an example
35
42
# has failed to compile
@@ -136,19 +143,22 @@ def compile_sketch(self, url, iframe=False):
136
143
# giving this iframe a meaningful name in the HTML (TODO?)
137
144
self .driver .switch_to_frame (0 )
138
145
self .execute_script (_VERIFY_SCRIPT )
146
+ # In the BACHELOR site the id is 'operation_output', but in the live
147
+ # site the id is 'cb_cf_operation_output'. The [id$=operation_output]
148
+ # here selects an id that _ends_ with 'operation_output'.
139
149
compile_result = WebDriverWait (self .driver , VERIFY_TIMEOUT ).until (
140
- any_text_to_be_present_in_element ((By .ID , "cb_cf_operation_output " ),
150
+ any_text_to_be_present_in_element ((By .CSS_SELECTOR , "[id$=operation_output] " ),
141
151
VERIFICATION_SUCCESSFUL_MESSAGE , VERIFICATION_FAILED_MESSAGE ))
142
152
if compile_result != VERIFICATION_SUCCESSFUL_MESSAGE :
143
153
raise VerificationError (compile_result )
144
154
145
155
146
- def compile_all_sketches (self , url , selector , iframe = False , log_file = None ):
156
+ def compile_all_sketches (self , url , selector , iframe = False , logfile = None ):
147
157
"""Compiles all projects on the page at `url`. `selector` is a CSS selector
148
158
that should select all relevant <a> tags containing links to sketches.
149
- `log_file ` specifies a path to a file to which test results will be
159
+ `logfile ` specifies a path to a file to which test results will be
150
160
logged. If it is not `None`, compile errors will not cause the test
151
- to halt, but rather be logged to the given file. `log_file ` may be a time
161
+ to halt, but rather be logged to the given file. `logfile ` may be a time
152
162
format string, which will be formatted appropriately.
153
163
`iframe` specifies whether the urls pointed to by `selector` are contained
154
164
within an iframe.
@@ -157,11 +167,11 @@ def compile_all_sketches(self, url, selector, iframe=False, log_file=None):
157
167
sketches = self .execute_script (_GET_SKETCHES_SCRIPT .format (selector = selector ))
158
168
assert len (sketches ) > 0
159
169
160
- if log_file is None :
170
+ if logfile is None :
161
171
for sketch in sketches :
162
172
self .compile_sketch (sketch , iframe = iframe )
163
173
else :
164
- log_entry = {'succeeded' : [], 'failed' : []}
174
+ log_entry = {'url' : self . site_url , ' succeeded' : [], 'failed' : []}
165
175
for sketch in sketches :
166
176
try :
167
177
self .compile_sketch (sketch , iframe = iframe )
@@ -172,8 +182,8 @@ def compile_all_sketches(self, url, selector, iframe=False, log_file=None):
172
182
'exception' : "%s; %s" % (type (e ).__name__ , str (e ))
173
183
# TODO?: is it possible to get the actual compiler error?
174
184
})
175
- # Dump the test results to `log_file `.
176
- f = open (strftime (log_file , gmtime ()), 'w' )
185
+ # Dump the test results to `logfile `.
186
+ f = open (strftime (logfile , gmtime ()), 'w' )
177
187
json .dump (log_entry , f )
178
188
f .close ()
179
189
0 commit comments