diff options
| author | youzhijiang <[email protected]> | 2024-11-27 14:24:00 +0800 |
|---|---|---|
| committer | youzhijiang <[email protected]> | 2024-11-27 14:24:00 +0800 |
| commit | efcf052777e65480b15ad4f7a9509e828a97bf0e (patch) | |
| tree | a655a65d0f616bd47a990aca0429ce194167c6cd | |
| parent | cb24695f76b6d53644152981c56d82011591e607 (diff) | |
object逻辑调整
| -rw-r--r-- | support/ui_utils/element_position/map_element_position_library.py | 23 | ||||
| -rw-r--r-- | support/ui_utils/object/edit_objects_example.py | 103 | ||||
| -rw-r--r-- | tests/object/test_temp/create_flag_temp.py | 74 | ||||
| -rw-r--r-- | tests/object/test_temp/create_internal_temp.py | 73 | ||||
| -rw-r--r-- | tests/object/test_temp/create_port_object_temp.py | 70 |
5 files changed, 208 insertions, 135 deletions
diff --git a/support/ui_utils/element_position/map_element_position_library.py b/support/ui_utils/element_position/map_element_position_library.py index 3f7f7f07e..3f0c0b270 100644 --- a/support/ui_utils/element_position/map_element_position_library.py +++ b/support/ui_utils/element_position/map_element_position_library.py @@ -1139,9 +1139,19 @@ object_port_object_element_position = { "objectPage_okButton_posXpath": portObjectPage_okButton_posXpath, "objectPage_okButton_warningYes_posXpath": portObjectPage_okButton_warningYes_posXpath }, + "edit": { + "ObjectListPage_editButton_posXpath": ipObjectListPage_editButton_posXpath, + "objectPage_addItem_posXpath": portObjectPage_addItem_posXpath, + "ObjectPage_edit_item_posXpath": ipObjectPage_edit_item_posXpath, + "ObjectPage_search_item_posXpath": ipObjectPage_search_item_posXpath, + "objectPage_inputItem_posXpath": portObjectPage_inputItem_posXpath, + "objectPage_button_saveItem_posXpath": portObjectPage_button_saveItem_posXpath, + "objectPage_okButton_posXpath": portObjectPage_okButton_posXpath, + }, "search": { "objectListPage_searchLabel_posXpath": portObjectListPage_searchLabel_posXpath, "objectListPage_searchLabel_selectName_posXpath": portObjectListPage_searchLabel_selectName_posXpath, + "objectListPage_searchLabel_selectID_posXpath": objectListPage_search_select_Id_posXpath, "objectListPage_tableTbody_posXpath": portObjectListPage_tableTbody_posXpath, "objectListPage_search_input_posXpath": portObjectListPage_search_input_posXpath, "objectListPage_search_dropDown_item_posXpath": portObjectListPage_search_dropDown_item_posXpath, @@ -1725,9 +1735,20 @@ object_interval_object_element_position = { "objectPage_okButton_posXpath": intObjectPage_okButton_posXpath, "objectPage_okButton_warningYes_posXpath": intObjectPage_okButton_warningYes_posXpath }, + "edit": { + "ObjectListPage_editButton_posXpath": ipObjectListPage_editButton_posXpath, + "objectPage_addItem_posXpath": intObjectPage_addItem_posXpath, + "ObjectPage_edit_item_posXpath": ipObjectPage_edit_item_posXpath, + "ObjectPage_search_item_posXpath": ipObjectPage_search_item_posXpath, + "objectPage_inputItem_lowBoundary_posXpath": intObjectDetailPage_itemValueInput_lowBoundary_poXpath, + "objectPage_inputItem_upBoundary_posXpath":intObjectDetailPage_itemValueInput_upBoundary_poXpath, + "objectPage_button_saveItem_posXpath": intObjectDetailPage_itemSaveButton_poXpath, + "objectPage_okButton_posXpath": intObjectPage_okButton_posXpath, + }, "search": { - "objectListPage_searchLabel_posId": ipObjectListPage_searchLabel_posId, + "objectListPage_searchLabel_posXpath": imsiObjectListPage_searchLabel_posXpath, "objectListPage_searchLabel_selectName_posXpath": ipObjectListPage_searchLabel_selectName_posXpath, + "objectListPage_searchLabel_selectID_posXpath": objectListPage_search_select_Id_posXpath, "objectListPage_tableTbody_posXpath": ipObjectListPage_tableTbody_posXpath, "objectListPage_search_input_posXpath": ipObjectListPage_search_input_posXpath, "objectListPage_search_dropDown_item_posXpath": ipObjectListPage_search_dropDown_item_posXpath, diff --git a/support/ui_utils/object/edit_objects_example.py b/support/ui_utils/object/edit_objects_example.py index ff37764c7..4165ecbf9 100644 --- a/support/ui_utils/object/edit_objects_example.py +++ b/support/ui_utils/object/edit_objects_example.py @@ -94,51 +94,63 @@ class EditObjects: self.driver.find_element(By.XPATH, edit_element_position["ObjectPage_sameItem_inputItem_posXpath"]).send_keys(item_value) self.driver.find_element(By.XPATH,edit_element_position["objectPage_button_saveItem_posXpath"]).click() elif object_type == "flag": - for i in range(len(object["items"])): # - self.driver.find_element(By.XPATH, edit_element_position["objectPage_addItem_posXpath"]).click() - if object["items"][i]["op"] == "add": # 直接 新增 模式 - for key_flag in object["items"][i]["flag"]: - if key_flag == "Bulky" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[2]").click() - elif key_flag == "CBR Streaming": - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[3]").click() - elif key_flag == "Client is Local" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[4]").click() - elif key_flag == "Server is Local" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[5]").click() - elif key_flag == "Download" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[6]").click() - elif key_flag == "Interactive" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[7]").click() - elif key_flag == "Inbound" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[8]").click() - elif key_flag == "Outbound" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[9]").click() - elif key_flag == "Pseudo Unidirectional" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[10]").click() - elif key_flag == "Streaming" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[11]").click() - elif key_flag == "Unidirectional" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[12]").click() - elif key_flag == "Random looking" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[13]").click() - elif key_flag == "C2S" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[14]").click() - elif key_flag == "S2C" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[15]").click() - elif key_flag == "Bidirectional" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[16]").click() - elif key_flag == "Tunneling" and object["items"][i]["flag"][key_flag] == True: - self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[17]").click() - self.driver.find_element(By.XPATH,edit_element_position["objectPage_button_saveItem_posXpath"]).click() + if src_item == "": # 直接 新增 模式 + self.driver.find_element(By.XPATH,edit_element_position["objectPage_addItem_posXpath"]).click() + for key_flag in new_item: + if key_flag == "Bulky" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[2]").click() + elif key_flag == "CBR Streaming": + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[3]").click() + elif key_flag == "Client is Local" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[4]").click() + elif key_flag == "Server is Local" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[5]").click() + elif key_flag == "Download" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[6]").click() + elif key_flag == "Interactive" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[7]").click() + elif key_flag == "Inbound" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[8]").click() + elif key_flag == "Outbound" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[9]").click() + elif key_flag == "Pseudo Unidirectional" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[10]").click() + elif key_flag == "Streaming" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[11]").click() + elif key_flag == "Unidirectional" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[12]").click() + elif key_flag == "Random looking" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[13]").click() + elif key_flag == "C2S" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[14]").click() + elif key_flag == "S2C" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[15]").click() + elif key_flag == "Bidirectional" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[16]").click() + elif key_flag == "Tunneling" and new_item[key_flag] == True: + self.driver.find_element(By.XPATH, "//*[@class='flag-object-flag']//span[17]").click() + self.driver.find_element(By.XPATH,edit_element_position["objectPage_button_saveItem_posXpath"]).click() elif object_type == "interval": - for i in range(len(object["items"])): - data_int = object["items"][i]["interval"].split("-") + if src_item == "": + data_int = new_item.split("-") self.driver.find_element(By.XPATH, edit_element_position["objectPage_addItem_posXpath"]).click() # 点击“+”按钮 # 在空内容的输入框中,输入新增的数据 self.driver.find_element(By.XPATH,edit_element_position["objectPage_inputItem_lowBoundary_posXpath"]).send_keys(eval(str(data_int))[0]) # 于item 下low_boundary value输入框键入item_value self.driver.find_element(By.XPATH,edit_element_position["objectPage_inputItem_upBoundary_posXpath"]).send_keys(eval(str(data_int))[1]) # 于item 下up_boundary value输入框键入item_value self.driver.find_element(By.XPATH, edit_element_position["objectPage_button_saveItem_posXpath"]).click() # 点击保存按钮 + elif src_item != "": + data_int = new_item.split("-") + self.driver.find_element(By.XPATH,edit_element_position["ObjectPage_search_item_posXpath"]).send_keys(src_item + Keys.ENTER) + self.driver.find_element(By.XPATH,edit_element_position["ObjectPage_edit_item_posXpath"]).click() + # 清空内容:模拟 Ctrl + A 全选后删除 + self.driver.find_element(By.XPATH,edit_element_position["objectPage_inputItem_lowBoundary_posXpath"]).send_keys(Keys.CONTROL, 'a') # 或使用 Keys.COMMAND 在 macOS + self.driver.find_element(By.XPATH,edit_element_position["objectPage_inputItem_lowBoundary_posXpath"]).send_keys(Keys.DELETE) + self.driver.find_element(By.XPATH, edit_element_position["objectPage_inputItem_upBoundary_posXpath"]).send_keys(Keys.CONTROL,'a') # 或使用 Keys.COMMAND 在 macOS + self.driver.find_element(By.XPATH, edit_element_position["objectPage_inputItem_upBoundary_posXpath"]).send_keys(Keys.DELETE) + time.sleep(0.5) + self.driver.find_element(By.XPATH, edit_element_position["objectPage_inputItem_lowBoundary_posXpath"]).send_keys(eval(str(data_int))[0]) # 于item 下low_boundary value输入框键入item_value + self.driver.find_element(By.XPATH, edit_element_position["objectPage_inputItem_upBoundary_posXpath"]).send_keys(eval(str(data_int))[1]) # 于item 下up_boundary value输入框键入item_value + self.driver.find_element(By.XPATH, edit_element_position["objectPage_button_saveItem_posXpath"]).click() # 点击保存按钮 elif object_type == "application": self.driver.find_element(By.XPATH, edit_element_position["objectPage_inputLongName_posXpath"]).send_keys(object["application"]["app_longname"]) # input long name # self.driver.find_element(By.XPATH, edit_element_position[""]).send_keys("Your description") # input description @@ -210,17 +222,6 @@ class EditObjects: self.create_common_objects(tunnel_endition_b["or_conditions"][i], common_object_element_position) self.driver.find_element(By.XPATH,edit_element_position["objectPage_okButton_posXpath"] + "[2]").click() self.driver.find_element(By.XPATH,edit_element_position["ObjectPage_side_slic_Cancel_posXpath"]).click() - elif object_type == "port": - for i in range(len(object["items"])): - if object["items"][i]["op"] == "add": - self.driver.find_element(By.XPATH, edit_element_position["objectPage_addItem_posXpath"]).click() - # 适配24.10 版本,需要逐个字符输入 - send_data = object["items"][i]["interval"] - input_field = self.driver.find_element(By.XPATH,edit_element_position["objectPage_inputItem_posXpath"]) - for char in str(send_data): - input_field.send_keys(char) - time.sleep(0.1) - self.driver.find_element(By.XPATH,edit_element_position["objectPage_button_saveItem_posXpath"]).click() elif object_type == "ip_learning": self.driver.find_element(By.XPATH,edit_element_position["objectPage_ipLearningType_posXpath"]).click() if object["op"] == "add": @@ -261,8 +262,6 @@ class EditObjects: self.driver.find_element(By.XPATH,edit_element_position["ObjectPage_search_item_posXpath"]).send_keys(src_item + Keys.ENTER) self.driver.find_element(By.XPATH,edit_element_position["ObjectPage_edit_item_posXpath"]).click() input_field = self.driver.find_element(By.XPATH,edit_element_position["objectPage_inputItem_posXpath"]) - # self.driver.execute_script("arguments[0].setAttribute('aria-autocomplete', 'none');",input_field) - # self.driver.execute_script("arguments[0].value = '';", input_field) # 清空内容:模拟 Ctrl + A 全选后删除 input_field.send_keys(Keys.CONTROL, 'a') # 或使用 Keys.COMMAND 在 macOS input_field.send_keys(Keys.DELETE) diff --git a/tests/object/test_temp/create_flag_temp.py b/tests/object/test_temp/create_flag_temp.py index f6c57faee..8813db9b4 100644 --- a/tests/object/test_temp/create_flag_temp.py +++ b/tests/object/test_temp/create_flag_temp.py @@ -16,8 +16,7 @@ def run(parameter): script_start_time = time.time() #测试数据 - object_configuration = { - "or_conditions": [ + object_configuration = [ { "name": "test", "type": "flag", @@ -33,24 +32,47 @@ def run(parameter): } ] } - ], - "search": { - "is_fuzzy": False, - "type": "uuid" - }, + ] - "audit_log": False # system - } + ui_client = UIClient(parameter) # 创建 - ui_client = UIClient() - objects_tuple, ui_error = ui_client.create_objects(object_configuration) - if len(ui_error) > 0: - return ui_error + code = ui_client.create_objects(object_configuration) + if code != 200: + return "Fail to create object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Create Object successful ") + + search_type = { + "is_fuzzy": False, + "type": "", + } + + # 查询 + objects_tuple, code = ui_client.search_objects("create_apn_object", object_configuration, search_type) objects_list = list(objects_tuple) - if len(objects_list) > 0 and len(objects_list[0]["uuid"]) > 0: - return "" + if len(objects_list) == 0: + return "Fail to get object uuid." + if code != 200: + return "Fail to search object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Search Object successful ") + # 编辑 + # 如果src_item是空,则表示该item是新加 + code = ui_client.edit_objects(objects_tuple, src_item="", new_item="testapn$") + if code != 200: + return "Fail to edit object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Edit Object successful ") + # 如果src_item是不是空,在item输入框,输入src_item,找到item,点击item的编辑按钮,删除src_item,输入new_item,点击保存按钮 + code = ui_client.edit_objects(objects_tuple, src_item="acdcd$", new_item="^xrwom.fu$") + if code != 200: + return "Fail to edit object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Edit Object successful ") + + return "" except Exception as e: exception_result = str(e) @@ -59,26 +81,22 @@ def run(parameter): finally: # 删除 - if parameter["initiation_method"] == "ui": - if objects_tuple is not None: - ui_client.delete_objects(parameter, objects_tuple, object_configuration["search"]) - # elif parameter["initiation_method"] == "api": - # if not objects_tuple: - # api_client.delete_rules(rules_tuple) - # if not objects_tuple: - # api_client.delete_objects(objects_tuple) - + if objects_tuple: + ui_client.delete_objects(objects_tuple) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Delete Object successful ") + # ui_client.cleanup() # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) + if __name__ == '__main__': parameter = { "username": "auto_ui_yzj", diff --git a/tests/object/test_temp/create_internal_temp.py b/tests/object/test_temp/create_internal_temp.py index 8b02ee307..0129f8b50 100644 --- a/tests/object/test_temp/create_internal_temp.py +++ b/tests/object/test_temp/create_internal_temp.py @@ -16,10 +16,9 @@ def run(parameter): script_start_time = time.time() #测试数据 - object_configuration = { - "or_conditions": [ + object_configuration = [ { - "name": "test", + "name": "create_interval_object", "type": "interval", "member_type": "item", "statistics_option": "", # random @@ -30,25 +29,47 @@ def run(parameter): } ], } - ], + ] - "search": { - "is_fuzzy": False, - "type": "uuid" - }, + ui_client = UIClient(parameter) - "audit_log": False # system + # 创建 + code = ui_client.create_objects(object_configuration) + if code != 200: + return "Fail to create object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Create Object successful ") + + search_type = { + "is_fuzzy": False, + "type": "", } - # 创建 - ui_client = UIClient() - objects_tuple, ui_error = ui_client.create_objects(object_configuration) - if len(ui_error) > 0: - return ui_error + # 查询 + objects_tuple, code = ui_client.search_objects("create_interval_object", object_configuration, search_type) objects_list = list(objects_tuple) - if len(objects_list) > 0 and len(objects_list[0]["uuid"]) > 0: - return "" + if len(objects_list) == 0: + return "Fail to get object uuid." + if code != 200: + return "Fail to search object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Search Object successful ") + # 编辑 + # 如果src_item是空,则表示该item是新加 + code = ui_client.edit_objects(objects_tuple, src_item="", new_item="5-80") + if code != 200: + return "Fail to edit object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Edit Object successful ") + # 如果src_item是不是空,在item输入框,输入src_item,找到item,点击item的编辑按钮,删除src_item,输入new_item,点击保存按钮 + code = ui_client.edit_objects(objects_tuple, src_item="1-65535", new_item="300-500") + if code != 200: + return "Fail to edit object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Edit Object successful ") + + return "" except Exception as e: exception_result = str(e) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"When running test case, the exception error: ", str(e), flush=True) @@ -56,22 +77,16 @@ def run(parameter): finally: # 删除 - if parameter["initiation_method"] == "ui": - if objects_tuple is not None: - ui_client.delete_objects(parameter, objects_tuple, object_configuration["search"]) - # elif parameter["initiation_method"] == "api": - # if not objects_tuple: - # api_client.delete_rules(rules_tuple) - # if not objects_tuple: - # api_client.delete_objects(objects_tuple) - + if objects_tuple: + ui_client.delete_objects(objects_tuple) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Delete Object successful ") + # ui_client.cleanup() # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) - print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], - "Finish test case: " + parameter["test_case_name"], flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Duration of running the test case: ", "{:.3f}".format(duration), flush=True) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) diff --git a/tests/object/test_temp/create_port_object_temp.py b/tests/object/test_temp/create_port_object_temp.py index 80833fa59..e211a3add 100644 --- a/tests/object/test_temp/create_port_object_temp.py +++ b/tests/object/test_temp/create_port_object_temp.py @@ -16,10 +16,9 @@ def run(parameter): script_start_time = time.time() #测试数据 - object_configuration = { - "or_conditions": [ + object_configuration = [ { - "name": "test", + "name": "create_port_object", "type": "port", "member_type": "item", "statistics_option": "", # random @@ -30,23 +29,46 @@ def run(parameter): } ], } - ], - "search": { - "is_fuzzy": False, - "type": "uuid" - }, - "audit_log": False # system - } + ] + + ui_client = UIClient(parameter) # 创建 - ui_client = UIClient() - objects_tuple, ui_error = ui_client.create_objects(object_configuration) - if len(ui_error) > 0: - return ui_error + code = ui_client.create_objects(object_configuration) + if code != 200: + return "Fail to create object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Create Object successful ") + + search_type = { + "is_fuzzy": False, + "type": "", + } + # 查询 + objects_tuple, code = ui_client.search_objects("create_port_object", object_configuration, search_type) objects_list = list(objects_tuple) - if len(objects_list) > 0 and len(objects_list[0]["uuid"]) > 0: - return "" + if len(objects_list) == 0: + return "Fail to get object uuid." + if code != 200: + return "Fail to search object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Search Object successful ") + # 编辑 + # 如果src_item是空,则表示该item是新加 + code = ui_client.edit_objects(objects_tuple, src_item="", new_item="1-80") + if code != 200: + return "Fail to edit object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Edit Object successful ") + # 如果src_item是不是空,在item输入框,输入src_item,找到item,点击item的编辑按钮,删除src_item,输入new_item,点击保存按钮 + code = ui_client.edit_objects(objects_tuple, src_item="1-65535", new_item="100-200") + if code != 200: + return "Fail to edit object." + else: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],"Edit Object successful ") + + return "" except Exception as e: exception_result = str(e) @@ -55,15 +77,11 @@ def run(parameter): finally: # 删除 - if parameter["initiation_method"] == "ui": - if objects_tuple is not None: - ui_client.delete_objects(parameter, objects_tuple, object_configuration["search"]) - # elif parameter["initiation_method"] == "api": - # if not objects_tuple: - # api_client.delete_rules(rules_tuple) - # if not objects_tuple: - # api_client.delete_objects(objects_tuple) - + if objects_tuple: + ui_client.delete_objects(objects_tuple) + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], + "Delete Object successful ") + # ui_client.cleanup() # 统计脚本用时 script_end_time = time.time() duration = script_end_time - script_start_time @@ -71,10 +89,12 @@ def run(parameter): "Duration of running the test case: ", "{:.3f}".format(duration), flush=True) print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Finish test case: " + parameter["test_case_name"], flush=True) + # 生成csv报告 update = ReportUpdate() update.write_result(parameter, result, exception_result) + if __name__ == '__main__': parameter = { "username": "auto_ui_yzj", |
