Skip to content

Commit 509424b

Browse files
committed
Use jquery-confirm by default for MasterQA page checks
1 parent 4527671 commit 509424b

File tree

1 file changed

+130
-33
lines changed

1 file changed

+130
-33
lines changed

seleniumbase/masterqa/master_qa.py

Lines changed: 130 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from seleniumbase import BaseCase
88
from seleniumbase.core.style_sheet import style
99
from seleniumbase.config import settings
10+
from seleniumbase.fixtures import js_utils
1011

1112
LATEST_REPORT_DIR = settings.LATEST_REPORT_DIR
1213
ARCHIVE_DIR = settings.REPORT_ARCHIVE_DIR
@@ -57,54 +58,135 @@ def clear_out_old_logs(self, archive_past_runs=True, get_log_folder=False):
5758
for f in filelist:
5859
os.remove("%s/%s" % (file_path, f))
5960

61+
def jq_confirm_dialog(self, question):
62+
count = self.manual_check_count + 1
63+
question = js_utils.escape_quotes_if_needed(question)
64+
jqcd = ("""jconfirm({
65+
boxWidth: '30%%',
66+
useBootstrap: false,
67+
containerFluid: false,
68+
theme: 'light',
69+
animation: 'scale',
70+
draggable: true,
71+
dragWindowGap: 0,
72+
container: 'body',
73+
title: 'Manual Check #%s:',
74+
content: '<h3><b>%s</b></h3>',
75+
buttons: {
76+
fail_button: {
77+
btnClass: 'btn-red',
78+
text: 'NO / FAIL',
79+
action: function(){
80+
$jqc_status = "Failure!"
81+
}
82+
},
83+
pass_button: {
84+
btnClass: 'btn-green',
85+
text: 'YES / PASS',
86+
action: function(){
87+
$jqc_status = "Success!"
88+
}
89+
}
90+
}
91+
});""" % (count, question))
92+
self.execute_script(jqcd)
93+
6094
def manual_page_check(self, *args):
6195
if not args:
62-
instructions = DEFAULT_VALIDATION_MESSAGE
96+
instructions = DEFAULT_VALIDATION_MESSAGE # self.verify()
6397
else:
6498
instructions = str(args[0])
99+
if len(args) > 1:
100+
pass
65101

66-
# Give the human enough time to see the page first
67-
wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
68-
if self.verify_delay:
69-
wait_time_before_verify = float(self.verify_delay)
70-
time.sleep(wait_time_before_verify)
71-
question = "Approve?"
102+
question = "Approve?" # self.verify("")
72103
if instructions and "?" not in instructions:
73-
question = instructions + " Approve?"
104+
question = instructions + " <> Approve?"
74105
elif instructions and "?" in instructions:
75106
question = instructions
76107

77-
if self.browser == 'ie':
78-
text = self.execute_script(
79-
'''if(confirm("%s")){return "Success!"}
80-
else{return "Failure!"}''' % question)
81-
elif self.browser == 'chrome':
82-
self.execute_script('''if(confirm("%s"))
83-
{window.master_qa_result="Success!"}
84-
else{window.master_qa_result="Failure!"}''' % question)
85-
time.sleep(0.05)
86-
self.wait_for_special_alert_absent()
87-
text = self.execute_script('''return window.master_qa_result''')
108+
use_jqc = False
109+
if js_utils.is_jquery_confirm_activated(self.driver):
110+
use_jqc = True
88111
else:
112+
if self.browser == "firefox":
113+
js_utils.activate_jquery(self.driver)
114+
js_utils.activate_jquery_confirm(self.driver)
115+
get_jqc = None
116+
try:
117+
get_jqc = self.execute_script("return jconfirm")
118+
get_jqc = get_jqc["instances"]
119+
use_jqc = True
120+
except Exception:
121+
use_jqc = False
122+
123+
if use_jqc:
124+
wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
125+
if self.verify_delay:
126+
wait_time_before_verify = float(self.verify_delay)
127+
# Allow a moment to see the full page before the dialog box pops up
128+
time.sleep(wait_time_before_verify)
129+
130+
# Use the jquery_confirm library for manual page checks
131+
self.jq_confirm_dialog(question)
132+
time.sleep(0.02)
133+
waiting_for_response = True
134+
while waiting_for_response:
135+
time.sleep(0.05)
136+
jqc_open = self.execute_script(
137+
"return jconfirm.instances.length")
138+
if str(jqc_open) == "0":
139+
break
140+
time.sleep(0.1)
141+
status = None
89142
try:
90-
self.execute_script(
91-
'''if(confirm("%s")){window.master_qa_result="Success!"}
143+
status = self.execute_script("return $jqc_status")
144+
except Exception:
145+
status = "Failure!"
146+
pre_status = self.execute_script(
147+
"return jconfirm.lastClicked.hasClass('btn-green')")
148+
if pre_status:
149+
status = "Success!"
150+
else:
151+
# Fallback to plain js confirm dialogs if can't load jquery_confirm
152+
if self.browser == 'ie':
153+
text = self.execute_script(
154+
'''if(confirm("%s")){return "Success!"}
155+
else{return "Failure!"}''' % question)
156+
elif self.browser == 'chrome':
157+
self.execute_script('''if(confirm("%s"))
158+
{window.master_qa_result="Success!"}
92159
else{window.master_qa_result="Failure!"}''' % question)
93-
except WebDriverException:
94-
# Fix for https://github.com/mozilla/geckodriver/issues/431
95-
pass
96-
time.sleep(0.05)
97-
self.wait_for_special_alert_absent()
98-
text = self.execute_script('''return window.master_qa_result''')
160+
time.sleep(0.05)
161+
self.wait_for_special_alert_absent()
162+
text = self.execute_script('return window.master_qa_result')
163+
else:
164+
try:
165+
self.execute_script(
166+
'''if(confirm("%s"))
167+
{window.master_qa_result="Success!"}
168+
else{window.master_qa_result="Failure!"}''' % question)
169+
except WebDriverException:
170+
# Fix for https://github.com/mozilla/geckodriver/issues/431
171+
pass
172+
time.sleep(0.05)
173+
self.wait_for_special_alert_absent()
174+
text = self.execute_script('return window.master_qa_result')
175+
status = text
176+
99177
self.manual_check_count += 1
100-
if "Success!" in text:
178+
try:
179+
current_url = self.driver.current_url
180+
except Exception:
181+
current_url = self.execute_script("return document.URL")
182+
if "Success!" in str(status):
101183
self.manual_check_successes += 1
102184
self.page_results_list.append(
103185
'"%s","%s","%s","%s","%s","%s","%s","%s"' % (
104186
self.manual_check_count,
105187
"Success",
106188
"-",
107-
self.driver.current_url,
189+
current_url,
108190
self.browser,
109191
self.get_timestamp()[:-3],
110192
instructions,
@@ -118,7 +200,7 @@ def manual_page_check(self, *args):
118200
self.manual_check_count,
119201
"FAILED!",
120202
bad_page_name,
121-
self.driver.current_url,
203+
current_url,
122204
self.browser,
123205
self.get_timestamp()[:-3],
124206
instructions,
@@ -200,15 +282,18 @@ def process_manual_check_results(self, auto_close_results_page=False):
200282
if self.manual_check_successes == self.manual_check_count:
201283
pass
202284
else:
203-
print("WARNING!!! There were page issues detected!")
285+
print("WARNING: There were page issues detected!")
204286
perfection = False
205287

206288
if self.incomplete_runs > 0:
207-
print("WARNING!!! Not all tests finished running!")
289+
print("WARNING: Not all tests finished running!")
208290
perfection = False
209291

210292
if perfection:
211-
print("SUCCESS!!! Everything checks out OKAY!")
293+
if self.manual_check_count > 0:
294+
print("SUCCESS: Everything checks out OKAY!")
295+
else:
296+
print("WARNING: No manual checks were performed!")
212297
else:
213298
pass
214299
self.add_bad_page_log_file() # Includes successful results
@@ -303,13 +388,23 @@ def process_manual_check_results(self, auto_close_results_page=False):
303388
class MasterQA(__MasterQATestCase__):
304389

305390
def setUp(self):
391+
self.check_count = 0
306392
self.auto_close_results_page = False
307393
super(__MasterQATestCase__, self).setUp()
308394
self.manual_check_setup()
395+
if self.headless:
396+
self.auto_close_results_page = True
309397
if START_IN_FULL_SCREEN_MODE:
310398
self.maximize_window()
311399

312400
def verify(self, *args):
401+
warn_msg = "\nWARNING: MasterQA skips manual checks in headless mode!"
402+
self.check_count += 1
403+
if self.headless:
404+
if self.check_count == 1:
405+
print(warn_msg)
406+
return
407+
# This is where the magic happens
313408
self.manual_page_check(*args)
314409

315410
def auto_close_results(self):
@@ -320,6 +415,8 @@ def auto_close_results(self):
320415
self.auto_close_results_page = True
321416

322417
def tearDown(self):
418+
if self.headless and self.check_count > 0:
419+
print("WARNING: %s manual checks were skipped!" % self.check_count)
323420
if sys.exc_info()[1]:
324421
self.add_failure(sys.exc_info()[1])
325422
self.process_manual_check_results(self.auto_close_results_page)

0 commit comments

Comments
 (0)