This function iterates through a open dialog box that has 4 values in it all optional except for aircraft1, aircraft2, warning_or_alert
.
aircraft1
,aircraft2
t_sep
# time value in format 00:12:21t_min_nm
# time value in format 00:21:21c_tracks
# can be either 'on' or 'off'warning_or_alert
# can be either 'warning' or 'alert'
First I check if I have correct airplanes aircraft_str = aircraft1 + ' - ' + aircraft2
. If I have correct aircraft I check if I have warning_or_alert
. If that is correct I can validate the last three variables t_sep, t_min_nm, c_tracks
. Don't worry about errorhandling.stca_list_exception
; it's a function in a different module that handles me error as well is utils.time_in_range
that function compares two times.
My concern here is my looping technic, by having for
loops but I'm using indexes instead of the for loop functionality utils.time_in_range(t_sep, squishtest.object.children(si)[i+2].text)
for instance.
def stca_list(aircraft1=None, aircraft2=None, t_sep=None, t_min_nm=None, c_tracks=None, warning_or_alert):
aircraft_str = None
if aircraft1:
aircraft_str = aircraft1 + ' - ' + aircraft2
stca_list_dialog = squishtest.waitForObject("{type='isds::StcaListDialog' unnamed='1' visible='1' windowTitle='STCA List'}")
for si in squishtest.object.children(stca_list_dialog):
if squishtest.className(si) == 'QTableWidget':
for i, ssi in enumerate(squishtest.object.children(si)):
if squishtest.className(ssi) == 'QModelIndex':
for stca_list_value in squishtest.object.children(si)[i+1:]:
if aircraft_str == stca_list_value.text:
if warning_or_alert == 'warning':
if stca_list_value.foregroundColor == '#FFFFFF00': # yellow
if t_sep:
utils.time_in_range(t_sep, squishtest.object.children(si)[i+2].text)
if t_min_nm:
utils.time_in_range(t_min_nm, squishtest.object.children(si)[i+3].text)
if c_tracks and c_tracks != squishtest.object.children(si)[i+4].text:
raise AssertionError("Error CTracks: Expected[%s] got[%s]"c_tracks, squishtest.object.children(si)[i+4].text)
squishtest.clickButton(squishtest.waitForObject("{name='CloseButton' text='Close' type='QPushButton' visible='1'}"))
return
else:
errorhandling.stca_list_exception('Error Warning: expected[warning] got[alert]')
elif warning_or_alert == 'alert':
if stca_list_value.foregroundColor == '#FFFF0000': # red
if t_sep:
utils.time_in_range(t_sep, squishtest.object.children(si)[i+2].text)
if t_min_nm:
utils.time_in_range(t_min_nm, squishtest.object.children(si)[i+3].text)
if c_tracks and c_tracks != squishtest.object.children(si)[i+4].text:
raise AssertionError("Error CTracks: Expected[%s] got[%s]"c_tracks, squishtest.object.children(si)[i+4].text)
squishtest.clickButton(squishtest.waitForObject("{name='CloseButton' text='Close' type='QPushButton' visible='1'}"))
return
else:
errorhandling.stca_list_exception('Error alert: expect[alert] got[waning]')
else:
errorhandling.stca_list_exception('Warning or Alert Error: Choose either warning or ellert, [%s] does not exis.' % warning_or_alert)
else:
errorhandling.stca_list_exception('Are value but wrong expected[%s] but was[%s]' % (aircraft_str, stca_list_value.text))
if aircraft_str:
errorhandling.stca_list_exception('Error: No warnings or alerts, but got aircraft[%s] and aircraft[%s] and warning or alert[%s]' % (aircraft1, aircraft2, warning_or_alert))
squishtest.clickButton(squishtest.waitForObject("{name='CloseButton' text='Close' type='QPushButton' visible='1'}"))
errorhandling.stca_list_exception
: Is that raising an actual exception or not? \$\endgroup\$errorhandling.stca_list_exception
it indeed raises an error and exits the function, it's input is just the error string. \$\endgroup\$