Index: tst_post/test.py =================================================================== diff -u -r28b3a1aa27c7776cdc70f08dfff8a294d419cdff -r0eb02c7f8376bc587ffa61662577c5495d219151 --- tst_post/test.py (.../test.py) (revision 28b3a1aa27c7776cdc70f08dfff8a294d419cdff) +++ tst_post/test.py (.../test.py) (revision 0eb02c7f8376bc587ffa61662577c5495d219151) @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. # copyright # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, @@ -6,99 +7,101 @@ # # file tst_post # @author (last) Papiya Mandal -# @date (last) 27-Jan-2022 +# @date (last) 19-04-2022 # +import names -# NOTE: -# This test is a demo and is intended to be used as an example on how to call the dialin API within SquishQt. - -import names - -from dialin.ui import utils from builtins import int as pyInt -from dialin.ui.hd_simulator import HDSimulator +from configuration import config +from dialin.ui import utils from dialin.ui.dg_simulator import DGSimulator +from dialin.ui.hd_simulator import HDSimulator -POST_ITEMS_COUNT = 20 + 1 # Python not including the last - -hd = HDSimulator() -dg = DGSimulator() +hd_simulator = HDSimulator() +dg_simulator = DGSimulator() -def get_progress(): +MSGS_AND_CONDITIONS = { 9: [True, False], 5: [True, False], 2: [True, False], + 4: [True, False], 8: [True, False], 1: [False, False], + 3: [True, False], 13: [True, False], 15: [True, False], + 11: [True, False], 18: [True, False], 12: [True, False], + 20: [True, False], 10: [True, False], 14: [True, False], + 6: [False, False], 17: [True, False], 7: [True, False], + 21: [True, True], 16: [False, True], 19: [True, True], + 22: [True, True], + } + + + +def post_a_message_and_verify_progress_and_completion(msgs_and_conditions): """ - Method to obtain progress - @return: Progress value + Method to post message and verify the + progress and completion + @param msgs_and_conditions - (list) list of messages and conditions + @return - None """ - progress_bar = object.parent(waitForObjectExists(names.progress_bar)) - progress_bar_children = object.children(progress_bar) - progress_bar_val_parent = progress_bar_children[3] - progress_bar_val_parents_children = object.children(progress_bar_val_parent) - progress_bar_val = progress_bar_val_parents_children[1] - return progress_bar_val.text.toUtf8().constData() - + for msg, conditions in msgs_and_conditions.items(): + final_msg = conditions[0] + final_msg_posted = conditions[1] + hd_simulator.cmd_send_hd_post(msg, final_msg, final_msg_posted) + dg_simulator.cmd_send_dg_post(msg, final_msg, final_msg_posted) + utils.waitForGUI(1) + verify_the_progress(value=msg, final_msg_posted=final_msg_posted) + verify_final_message_posted(final_msg=final_msg, final_msg_posted=final_msg_posted) -def verify_the_progress(item) -> None: +def verify_the_progress(value, final_msg_posted) -> None: """ Method to verify the progress - @param item: (int) single message post item - @param is_final: (bool) if this is the final post message(True/False) + @param value - (int) single message + @final_msg_posted - (bool) True/False + @return - None """ progress = pyInt(get_progress()) - test.compare(item, progress, - "Single post message item {item} expected to reflect on progress bar, got {progress}" - .format(item=item, progress=progress)) + if final_msg_posted is True: + test.xcompare(value, progress, "Final value {} should not reflect on the progress bar".format(value)) + elif final_msg_posted is False: + test.compare(value, progress, "{} should reflect on progress bar".format(value)) - -def verify_final_message_posted(is_passed: bool = False, is_final: bool = False) -> None: +def get_progress(): """ - method to verify the indication of final message posted - @param is_passed: (bool) final message result (passed,failed) - @param is_final: (bool) if this is the final post message(True/False) - @return: None + Method to obtain progress + @return: Progress value """ - if is_final == False: - if object.exists(names.busy_indicator): - busy_indicator = waitForObject(names.busy_indicator) - test.compare(busy_indicator.enabled, True, "Waiting for a value") + progress_bar = waitForObjectExists(names.o_progress_bar) + return progress_bar.value + +def verify_final_message_posted(final_msg=None, final_msg_posted=None) -> None: + """ + method to verify the indication of final + message posted + @param final_msg - (bool) final message(True/False) + @param final_msg_posted - (bool) if this is the final post message(True/False) + @return - None + """ + test.startSection("Verifying the status") + if final_msg == True and final_msg_posted == True: - if is_final == True and is_passed == True: - if object.exists(names.done_indicator): - done_indicator = waitForObject(names.done_indicator) + if object.exists(names.o_done_indicator): + done_indicator = waitForObject(names.o_done_indicator) test.compare(done_indicator.enabled, True, "Done, Final value passed") - if is_final == True and is_passed == False: - if object.exists(names.fail_indicator): - fail_indicator = waitForObject(names.fail_indicator) + elif (final_msg == False and final_msg_posted == True) : + + if object.exists(names.o_fail_indicator): + fail_indicator = waitForObject(names.o_fail_indicator) test.compare(fail_indicator.enabled, True, "Failed, Final value not passed") + elif (final_msg == True and final_msg_posted == False) or (final_msg == False and final_msg_posted == False): + + if object.exists(names.o_busy_indicator): + busy_indicator = waitForObject(names.o_busy_indicator) + test.compare(busy_indicator.enabled, True, "Waiting for a value") + test.endSection() -def post_a_message_and_verify_progress_and_completion(item: int, is_passed: bool, is_final: bool = False): - """ - method to post a message and verify the progress bar and - @param item: (int) single message post item - @param is_passed: (bool) final message result (passed,failed) - @param is_final: (bool) if this is the final post message(True/False) - """ - hd.cmd_send_hd_post(item, is_passed, is_final) - dg.cmd_send_dg_post(item, is_passed, is_final) - - if not is_final: - verify_the_progress(item) - verify_final_message_posted(is_passed, is_final) - - def main(): + utils.tstStart(__file__) - startApplication(names.AUT_NAME) + startApplication(config.AUT_NAME) - hd.cmd_send_power_on_self_test_version_request() - for item in range(POST_ITEMS_COUNT): - post_a_message_and_verify_progress_and_completion(item, True , False) # single passed - post_a_message_and_verify_progress_and_completion(item, False, False) # single failed - - for item in range(POST_ITEMS_COUNT): - post_a_message_and_verify_progress_and_completion(item, False, True ) # Final passed - post_a_message_and_verify_progress_and_completion(item, True , True ) # Final failed - - utils.tstDone() - + hd_simulator.cmd_send_power_on_self_test_version_request() + post_a_message_and_verify_progress_and_completion(MSGS_AND_CONDITIONS) + utils.tstDone() \ No newline at end of file