diff options
| author | zhz <[email protected]> | 2024-11-19 09:58:36 +0800 |
|---|---|---|
| committer | zhz <[email protected]> | 2024-11-19 09:58:36 +0800 |
| commit | 9133843ed34e250c37e80849d472d5484e0ae4e8 (patch) | |
| tree | 15a8915abaa9df84b20fcb2f26ecf6e871bfe57c | |
| parent | 811d40959940287323e288758c32e39a5e79ea59 (diff) | |
response_page 元素定位修改
| -rw-r--r-- | cases/profiles/test_response_pages.py | 40 | ||||
| -rw-r--r-- | common/ui_common/profiles/profiles_public_operations.py | 501 | ||||
| -rw-r--r-- | common/ui_common/profiles/response_pages.py | 506 |
3 files changed, 670 insertions, 377 deletions
diff --git a/cases/profiles/test_response_pages.py b/cases/profiles/test_response_pages.py index 408ad293..20854ea1 100644 --- a/cases/profiles/test_response_pages.py +++ b/cases/profiles/test_response_pages.py @@ -17,34 +17,11 @@ data = ReadData() class TestResponsePages: @pytest.mark.parametrize("data", data.read_data_profiles("response_pages.json"), ids=data.generate_id) + @pytest.mark.curd def test_resposnePages(self, demo_fixture, data): responsePages = ResponsePages(demo_fixture) responsePages.response_page_case(data) - @pytest.mark.parametrize( - "data", - [ - { - "ids": "创建respose_page文件再修改", - "model": "modify", - "file": "testa.html->testb.html" - } - ], - ids=["创建respose_page文件再修改"] - ) - def test_responsePages_modify(self, demo_fixture, data): - responsePages = ResponsePages(demo_fixture) - responsePage_name = responsePages.create(data) - time.sleep(1) - responsePages.query(data, Name=responsePage_name) - responsePages.audit_log("Create") - responsePage_dict = responsePages.query(data, Name=responsePage_name) - responsePages.modify(data) - time.sleep(1) - responsePages.audit_log("Edit") - responsePages.query(data, ID=responsePage_dict["ID"]) - responsePages.delete() - # 上传20M文件 @pytest.mark.parametrize( "data", @@ -75,6 +52,7 @@ class TestResponsePages: ], ids=["创建response_pages数据name测试"] ) + # & 存在问题 def test_name(self, demo_fixture, data): time.sleep(1) name_group = ("", "123", "test", "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest", "1!@#$%^&*():\"{}|?><,./中文русскийEnglish") @@ -111,11 +89,12 @@ class TestResponsePages: responsePages.create(data) # 列设置测试 + @pytest.mark.curd def test_column_setting(self,demo_fixture): - column_allname = ["ID", "Vsys ID", "Name", "File", "Reference Count", "Modified Time", "Last Modified By"] - column_requiredname = ["ID", "Name"] - column_defaultname = ["ID", "Name", "File", "Reference Count", "Modified Time", "Last Modified By"] - column_name = ["ID", "Name", "File", "Last Modified By"] + column_allname = ["Vsys ID", "UUID", "Name", "File", "Usage", "Modified Time", "Operator"] + column_requiredname = ["Name"] + column_defaultname = ["Name", "File", "Usage", "Modified Time", "Operator"] + column_name = ["Name", "File", "Operator"] responsePages = ResponsePages(demo_fixture) responsePages.column_setting(column_defaultname, column_flags=0) responsePages.column_setting(column_requiredname, column_flags=1) @@ -163,6 +142,7 @@ class TestResponsePages: responsePages.turn_pages(2) # 切换语言测试 + @pytest.mark.curd def test_language_change(self, demo_fixture): responsePages = ResponsePages(demo_fixture) responsePages.language_change(2) @@ -180,7 +160,7 @@ class TestResponsePages: ], ids=["创建response_pages数据referenceCount测试"] ) - def test_referenceCount(self, demo_fixture, data): + def test_reference_count(self, demo_fixture, data): responsePages = ResponsePages(demo_fixture) responsePages_name = responsePages.create(data) #创建 response_pages time.sleep(1) @@ -193,7 +173,7 @@ class TestResponsePages: responsePages.delete() # 列表页底部All 按钮测试 - def test_listPageBottom_allSelect_case(self, demo_fixture): + def test_listpage_bottom_all_select_case(self, demo_fixture): responsePages = ResponsePages(demo_fixture) responsePages.listPageBottom_allSelect() diff --git a/common/ui_common/profiles/profiles_public_operations.py b/common/ui_common/profiles/profiles_public_operations.py index 09dfaa09..4310b459 100644 --- a/common/ui_common/profiles/profiles_public_operations.py +++ b/common/ui_common/profiles/profiles_public_operations.py @@ -21,15 +21,21 @@ from selenium.common.exceptions import StaleElementReferenceException from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait +from config.workpath import workdir +import datetime +from datetime import datetime as date_time + class ProfilesPublicOperations: def __init__(self, driver): self.driver = driver self.my_random = RandomName() + self.workdir = workdir + self.config_parser = configparser.ConfigParser() self.wait = WebDriverWait(self.driver, 5) # 最多等待5秒 - def query(self, mainPage_profileSearch_selectLabel_posId, listPage_profileSearch_subProfiles_dropDown_item_posXpath, - listPage_profileSearch_subProfiles_input_itemContent_posXpath, mainPage_profileSearch_buttonSearch_posId, + def query(self, mainpage_profile_search_select_label_posxpath, listPage_profileSearch_subProfiles_dropDown_item_posXpath, + listPage_profileSearch_subProfiles_input_itemContent_posXpath, mainpage_profile_search_button_search_posxpath, listPage_profilTable_subProfiles_tableTbody_posXpath, listPage_profilTable_subProfiles_tableHeader_posXpath, listPage_profileSearch_subProfiles_dropDown_typeItem_posXpath="", **kwargs): @@ -46,75 +52,62 @@ class ProfilesPublicOperations: :return: [first_row, map_header_className] """ # 点击search查询框 - self.driver.find_element(By.ID, mainPage_profileSearch_selectLabel_posId).click() + self.driver.find_element(By.XPATH, mainpage_profile_search_select_label_posxpath).click() # 循环输入查询内容 for key, value in kwargs.items(): if "_" in key: key = key.replace("_", " ") # 将下划线替换为空格 - dropdown_item_posXpath = listPage_profileSearch_subProfiles_dropDown_item_posXpath.format(replaceName=key) - self.driver.find_element(By.XPATH, dropdown_item_posXpath).click() # 点击下拉item if key != "type": - input_item_posXpath = listPage_profileSearch_subProfiles_input_itemContent_posXpath.format( - replaceName=key) + input_item_posXpath = listPage_profileSearch_subProfiles_input_itemContent_posXpath self.driver.find_element(By.XPATH, input_item_posXpath).send_keys(value.strip()) # 输入查询值 - self.driver.find_element(By.XPATH, input_item_posXpath).send_keys(Keys.ENTER) # 模拟回车按键 + # self.driver.find_element(By.XPATH, input_item_posXpath).send_keys(Keys.ENTER) # 模拟回车按键 else: dropdown_typeItem_posXpath = listPage_profileSearch_subProfiles_dropDown_typeItem_posXpath.format( - replaceName=value.split("->")[0]) + replace_name=value.split("->")[0]) self.driver.find_element(By.XPATH, dropdown_typeItem_posXpath).click() # 点击type的下拉item + dropdown_item_posXpath = listPage_profileSearch_subProfiles_dropDown_item_posXpath.format(replace_name=key) + self.driver.find_element(By.XPATH, dropdown_item_posXpath).click() # 点击下拉item + # 点击查询按钮 - element_search = self.driver.find_element(By.ID, mainPage_profileSearch_buttonSearch_posId) + element_search = self.driver.find_element(By.XPATH, mainpage_profile_search_button_search_posxpath) self.driver.execute_script("arguments[0].click()", element_search) # 强制点击 element_tbody = self.driver.find_element(By.XPATH, listPage_profilTable_subProfiles_tableTbody_posXpath) # 找到所有的行,table的body - element_header = self.driver.find_element(By.XPATH, - listPage_profilTable_subProfiles_tableHeader_posXpath) # 查询table的header - # 获取table header的text、th.class - headers = element_header.find_elements(By.XPATH, "th") # table header - rows = element_tbody.find_elements(By.XPATH, "tr") # table body + rows = element_tbody.find_elements(By.XPATH, "//div[contains(@class, 'MuiDataGrid-row')]") # table body if len(rows) == 0: print(f"没有查询到数据:查询条件:{kwargs}") return [0, 0] map_header_className = {} # 表头名称和th.class的映射,为了从表body中取对应列的值{"ID":"33"} - for th in headers: - self.driver.execute_script("arguments[0].scrollIntoView();", th) - header_content = th.text.strip() - classNames = th.get_attribute("class").split() - for c_name in classNames: - if "el-table" in c_name and "column" in c_name: - tableBodyRowClassName = c_name - if header_content and tableBodyRowClassName: - map_header_className[header_content] = tableBodyRowClassName # 从第一行查询的结果中,取出需要断言的值、name first_row = rows[0] return [first_row, map_header_className] - def getListPageTableContents(self, el_body=listPage_profilTable_dnsRecords_tableTbody_posXpath): + def getListPageTableContents(self, el_body=listpage_profile_table_dns_records_table_tbody_posxpath): """ 获取列表页中表格行的所有数据 :param listPage_profilTable_subProfiles_tableTbody_posXpath: :return: """ element_tbody = self.driver.find_element(By.XPATH, el_body) # 定位到<tbody>元素,在进一步解析 - rows = element_tbody.find_elements(By.XPATH, "tr") #获取<tbody>下的所有<tr>行的元素 + rows = element_tbody.find_elements(By.XPATH, "//div[@data-rowindex]") #获取<tbody>下的所有<tr>行的元素 return rows - def getListPage_firstTableData_checkBoxClass_and_ID(self, el_body=listPage_profilTable_dnsRecords_tableTbody_posXpath, sublevel_path_model=0): + def getListPage_firstTableData_checkBoxClass_and_ID(self, el_body=listpage_profile_table_dns_records_table_tbody_posxpath, sublevel_path_model=0): """ 获取列表页中第一列(单元格)中选择框属性和ID值,返回dict :parameter sublevel_path_model 可以取值0、1、2、3。。。自定义,默认为0.因为 选择框class属性和id值子级定位在不同的模块下定位方法不一样,需要增加取法判断 :return: dict """ table_rows = self.getListPageTableContents(el_body=el_body) # 获得到<tbody>的所有<tr>行元素集合 - id_checkbox_dict = {} + name_checkbox_dict = {} if len(table_rows) == 0: print("列表页中没有数据...") else: # 取出每个行数据 for tr_s in table_rows: # 取出每一个行 - el_first_data = tr_s.find_element(By.XPATH, "./td[1]") # 只取第一单元格数据 + el_first_data = tr_s.find_element(By.XPATH, "//input[@class='MuiCheckbox-input css-1jj0cvj']") # 只取第一单元格数据 if sublevel_path_model == 0: # 符合profiles模块下大部分子模块,除了ssl fingerprints - first_data_checkbox_class = el_first_data.find_element(By.XPATH, ".//div[@class='table-status-box']//label[contains(@class, 'checkbox')]").get_attribute("class") - first_data_id = el_first_data.find_element(By.XPATH, ".//div[@class='table-status-box']//div[contains(@class, 'table-status-item-id')]//span").text.strip() + first_data_checkbox_class = el_first_data.find_element(By.XPATH, "./parent::span").get_attribute("class") + first_data_name = tr_s.find_element(By.XPATH, "//div[contains(@class, 'MuiDataGrid-row')]//div[@data-field='name']").text.strip() elif sublevel_path_model == 1: # 适用于profiles--ssl fingerprints模块的class和id取用 可以删除 #print(el_first_data.get_attribute('outerHTML')) pass @@ -122,9 +115,9 @@ class ProfilesPublicOperations: #first_data_id = el_first_data.find_element(By.XPATH, ".//*[contains(@class, 'el-checkbox__original')]").get_attribute("value") else: print("sublevel_path_model传入的参数不准确,请检查...") - id_checkbox_dict[first_data_id] = first_data_checkbox_class + name_checkbox_dict[first_data_name] = first_data_checkbox_class #print(id_checkbox_dict) - return id_checkbox_dict + return name_checkbox_dict def linkdata(self, link_list_dict, listPage_profile_dnsRecords_linkButton_posId, listPage_linkTips_dnsRecords_button_save_posXpath, listPage_linkTips_dnsRecords_button_add_posXpath, listPage_linkTips_dnsRecords_button_OK_posXpath): @@ -138,7 +131,7 @@ class ProfilesPublicOperations: #{"link_dst_cluster": "42.49-User4Link", "link_dst_vsys":"Vsys2test"} #link_dst_cluster = link_dict["link_dst_cluster"] #link_dst_vsys = link_dict["Vsys2test"] - self.driver.find_element(By.ID, listPage_profile_dnsRecords_linkButton_posId).click() + self.driver.find_element(By.XPATH, listPage_profile_dnsRecords_linkButton_posId).click() link_count = len(link_list_dict) for link_index in range(len(link_list_dict)): link_dst_cluster = link_list_dict[link_index]["link_dst_cluster"] @@ -170,7 +163,7 @@ class ProfilesPublicOperations: time.sleep(3) # 状态断言 status_info = "color: rgb(141, 203, 75);" - rows = self.driver.find_element(By.XPATH, listPage_profilTable_dnsRecords_tableTbody_posXpath).find_elements(By.XPATH, "./tr") + rows = self.driver.find_element(By.XPATH, listpage_profile_table_dns_records_table_tbody_posxpath).find_elements(By.XPATH, "./tr") print(len(rows)) for row_0 in rows: status_style = row_0.find_element(By.XPATH, "./td[7]//i").get_attribute("style") @@ -181,7 +174,7 @@ class ProfilesPublicOperations: Element="//tbody/tr[@class='el-table__row']") # 查看第一行是否存在数据 if self.driver.Exist: # 展示所有列 - self.driver.find_element(By.ID, mainPage_profileColumn_columnSetting_posId).click() # 点击列设置 + self.driver.find_element(By.XPATH, mainpage_profile_column_setting_posxpath).click() # 点击列设置 all_checked_xpath = "//div[@class='all-btn']//span[@class='el-checkbox__input is-checked']" if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 self.driver.find_element(By.XPATH, @@ -277,7 +270,7 @@ class ProfilesPublicOperations: return return_code - def check_checkBoxClass_by_buttonAll(self, el_body=listPage_profilTable_dnsRecords_tableTbody_posXpath, el_all_btn=mainPage_profileBottomPage_button_allSelect_posXpath, sublevel_path_model=0): + def check_checkBoxClass_by_buttonAll(self, el_body=listpage_profile_table_dns_records_table_tbody_posxpath, el_all_btn=mainpage_profile_bottom_page_button_all_select_posXpath, sublevel_path_model=0): """ 点击页面底部all后,判断列表页第一列中,选择框的属性值,有is-checked属性,表明已经勾选 :param el_body: body元素定位,大部分是上都是默认的 @@ -288,38 +281,38 @@ class ProfilesPublicOperations: """ id_checkbox_dict = self.getListPage_firstTableData_checkBoxClass_and_ID(el_body=el_body, sublevel_path_model=sublevel_path_model) print(id_checkbox_dict) - if id_checkbox_dict == {}: + if id_checkbox_dict == None: # mod_by_kg for list null return 0 # 点击all前属性判断,此时无is-checked 属性 - first_data_checkbox_class_except = "is-checked" + first_data_checkbox_class_except = "Mui-checked" print("all button 点击前属性验证...") - for k,v in id_checkbox_dict.items(): + for k, v in id_checkbox_dict.items(): pytest_check.is_not_in(first_data_checkbox_class_except, v, msg="所在行数{}".format(inspect.currentframe().f_lineno)) # 点击all后,属性判断,此时有is-checked 属性 self.driver.find_element(By.XPATH, el_all_btn).click() time.sleep(1) - id_checkbox_dict = self.getListPage_firstTableData_checkBoxClass_and_ID(el_body=el_body) - print(id_checkbox_dict) - if id_checkbox_dict == {}: + name_checkbox_dict = self.getListPage_firstTableData_checkBoxClass_and_ID(el_body=el_body) + print(name_checkbox_dict) + if name_checkbox_dict == None: return 0 print("all button 点击后属性验证...") - for k,v in id_checkbox_dict.items(): + for k, v in name_checkbox_dict.items(): pytest_check.is_in(first_data_checkbox_class_except, v, msg="所在行数{}".format(inspect.currentframe().f_lineno)) # 再点击all,取消点击后,属性判断,此时没有is-checked 属性 self.driver.find_element(By.XPATH, el_all_btn).click() - id_checkbox_dict = self.getListPage_firstTableData_checkBoxClass_and_ID(el_body=el_body) - print(id_checkbox_dict) - if id_checkbox_dict == {}: + name_checkbox_dict = self.getListPage_firstTableData_checkBoxClass_and_ID(el_body=el_body) + print(name_checkbox_dict) + if name_checkbox_dict == {}: return 0 # 取消all点击后判断,此时无is-checked 属性 print("all button 取消点击后属性验证...") - for k,v in id_checkbox_dict.items(): + for k, v in name_checkbox_dict.items(): pytest_check.is_not_in(first_data_checkbox_class_except, v, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - def delete(self, listPage_profile_subProfiles_delButton_posId, listPage_dialogTips_subProfiles_button_yes_posCss, - listPage_dialogTips_subProfiles_button_no_posCss): + def delete(self, listpage_profile_response_pages_del_button_posxpath, listpage_dialogtips_response_pages_button_yes_posxpath, + listpage_dialogtips_response_pages_button_no_posxpath): """ 直接删除函数, :param listPage_profile_subProfiles_delButton_posId: 删除按钮id @@ -327,16 +320,16 @@ class ProfilesPublicOperations: :param listPage_dialogTips_subProfiles_button_no_posCss: 提示删除框中no定位css :return: """ - self.driver.find_element(By.ID, listPage_profile_subProfiles_delButton_posId).click() # 点击删除按钮 + element = self.driver.find_element(By.XPATH, listpage_profile_response_pages_del_button_posxpath) # 点击删除按钮 + self.driver.execute_script("arguments[0].click()", element) random_yes_or_no = random.randint(0, 1) if random_yes_or_no == 0: # 点击yes,删除 - self.driver.find_element(By.CSS_SELECTOR, listPage_dialogTips_subProfiles_button_yes_posCss).click() # 直接删除 + self.driver.find_element(By.XPATH, listpage_dialogtips_response_pages_button_yes_posxpath).click() # 直接删除 else: - self.driver.find_element(By.CSS_SELECTOR, - listPage_dialogTips_subProfiles_button_no_posCss).click() # 先取消,再删除 - self.driver.find_element(By.ID, listPage_profile_subProfiles_delButton_posId).click() # 点击删除按钮 - self.driver.find_element(By.CSS_SELECTOR, listPage_dialogTips_subProfiles_button_yes_posCss).click() - time.sleep(0.5) + self.driver.find_element(By.XPATH, + listpage_dialogtips_response_pages_button_no_posxpath).click() # 先取消,再删除 + self.driver.find_element(By.XPATH, listpage_profile_response_pages_del_button_posxpath).click() # 点击删除按钮 + self.driver.find_element(By.XPATH, listpage_dialogtips_response_pages_button_yes_posxpath).click() def is_valid_ip(self, ip): "判断ip字符串是否为ip格式数据,是返回True" @@ -384,7 +377,7 @@ class ProfilesPublicOperations: :param vsys_name: vsys name, 例如:Default Vsys 、或者空。vsys_name与当前vsys一直或者为空字符串时,不要操作vsys :return: """ - current_vsys_name = self.driver.find_element(By.XPATH, mainPage_currentPage_vsysName_posXpath, find_before_wait_time=0.6, ).text.strip().lower() + current_vsys_name = self.driver.find_element(By.XPATH, mainpage_currentpage_vsysname_posxpath, find_before_wait_time=0.6, ).text.strip().lower() if vsys_name.lower() == current_vsys_name: print(f"当前系统所在vsys:{current_vsys_name}") return 0 @@ -401,7 +394,7 @@ class ProfilesPublicOperations: else: # 切换到指定vsys change_vsys_name = vsys_name print(f"当前系统所在vsys:{current_vsys_name},需要切换到vsys:{change_vsys_name}") - self.driver.find_element(By.XPATH, mainPage_button_menu_posXpath).click() # 点击vsys menu + self.driver.find_element(By.XPATH, mainpage_button_menu_posxpath).click() # 点击vsys menu # 如果切换vsys时弹出 Leave this page?的确认弹窗,点击确认 if self.driver.element_isExist(By.XPATH, leave_this_page_elem_Xpath, timeout=0.5): try: # 上述条件判断中,会存在会存在对应的元素,但是没有提示框情况,因此异常跳过继续执行 @@ -411,7 +404,7 @@ class ProfilesPublicOperations: pass else: pass - vsys_tree_name_list = self.driver.find_elements(By.XPATH, mainPage_vsysTree_vsysName_posXpath) + vsys_tree_name_list = self.driver.find_elements(By.XPATH, mainpage_vsys_tree_vsysname_posxpath) flag_num = 0 for el_vsys_item in vsys_tree_name_list: vsys_item_name = el_vsys_item.text.strip().lower() @@ -423,9 +416,8 @@ class ProfilesPublicOperations: print(f"测试用户没有vsys:{change_vsys_name}") raise ValueError(f"测试用户没有vsys:{change_vsys_name}") - def column_setting(self, mainPage_profileColumn_columnSetting_posId, - listPage_profileColumn_button_columnAll_posXpath, listPage_profileColumn_button_cancel_posId, - listPage_profileColumn_button_ok_posId, Profiles, column_flags, column: ()): + def column_setting(self, mainpage_profile_column_setting_posxpath, + mainpage_profile_column_setting_show_all_posxpath, Profiles, column_flags, column: ()): """ 列设置函数, column_flags: 0---保持当前状态 1---仅显示默认列 2---显示所有列 3---显示自定义列 @@ -439,38 +431,41 @@ class ProfilesPublicOperations: :return: """ - self.driver.find_element(By.ID, mainPage_profileColumn_columnSetting_posId).click() # 点击列设置按钮 - columnAll_class = self.driver.find_element(By.XPATH, - listPage_profileColumn_button_columnAll_posXpath).get_attribute( - "class").split() - print("columnAll_class=", columnAll_class) - if column_flags == 0: # 保持当前状态 - self.driver.find_element(By.ID, listPage_profileColumn_button_cancel_posId).click() # 点击cancel按钮 + self.driver.find_element(By.XPATH, mainpage_profile_column_setting_posxpath).click() # 点击列设置按钮 + column_all_class = self.driver.find_element(By.XPATH, + mainpage_profile_column_setting_show_all_posxpath).get_attribute( + "aria-checked").split() + print("column_all_class =", column_all_class) + if column_flags == 0: # 保持当前状态, 点击 Name 处 + self.driver.find_element(By.XPATH, "//*[normalize-space(text())='Name']").click() elif column_flags == 1: # 仅显示默认列 - if "is-checked" in columnAll_class: - self.driver.find_element(By.XPATH, - listPage_profileColumn_button_columnAll_posXpath).click() # 取消点击列All按钮 - self.driver.find_element(By.ID, listPage_profileColumn_button_ok_posId).click() # 点击ok按钮 + if "false" in column_all_class: + pass else: - self.driver.find_element(By.XPATH, listPage_profileColumn_button_columnAll_posXpath).click() # 点击列All按钮 - self.driver.find_element(By.XPATH, - listPage_profileColumn_button_columnAll_posXpath).click() # 取消点击列All按钮 - self.driver.find_element(By.ID, listPage_profileColumn_button_ok_posId).click() # 点击ok按钮 + self.driver.find_element(By.XPATH, mainpage_profile_column_setting_show_all_posxpath).click() # 点击列All按钮 + self.driver.find_element(By.XPATH, "//*[normalize-space(text())='Name']").click() elif column_flags == 2: # 显示所有列 - if "is-checked" in columnAll_class: - self.driver.find_element(By.ID, listPage_profileColumn_button_ok_posId).click() # 点击ok按钮 + if "true" in column_all_class: + pass else: - self.driver.find_element(By.XPATH, listPage_profileColumn_button_columnAll_posXpath).click() # 点击列All按钮 - self.driver.find_element(By.ID, listPage_profileColumn_button_ok_posId).click() # 点击ok按钮 + for _ in range(2): + self.driver.find_element(By.XPATH, mainpage_profile_column_setting_show_all_posxpath).click() # 点击列All按钮 + self.driver.find_element(By.XPATH, "//*[normalize-space(text())='Name']").click() else: + if "false" in column_all_class: + pass + else: + self.driver.find_element(By.XPATH, + mainpage_profile_column_setting_show_all_posxpath).click() # 点击列All按钮 for name in column: # print("name=", name) - self.driver.find_element(By.XPATH, - f"//*[@id='dropColRes-_ElementSet_{Profiles}_Home_App_anonymousComponent']//span[contains(text(),'{name}')]").click() # 选择指定列按钮 - self.driver.find_element(By.ID, listPage_profileColumn_button_ok_posId).click() # 点击ok按钮 + self.driver.find_element(By.XPATH, f"//div[@class='MuiDataGrid-columnsManagement css-1v3xuhs']//span[contains(text(),'{name}')]").click() + self.driver.find_element(By.XPATH, "//*[normalize-space(text())='Name']").click() + element_header = self.driver.find_element(By.XPATH, - "//div[contains(@class,'ly-table1')]//table[@class='el-table__header']//thead//tr") # 查询table的header - headers = element_header.find_elements(By.XPATH, "//th[@colspan='1']") # table header + "//div[@class='MuiDataGrid-row--borderBottom css-k008qs']") # 查询table的header + headers = element_header.find_elements(By.XPATH, + "//div[@data-field!='']//div[@class='MuiDataGrid-columnHeaderTitle css-rw8nxc']") # table header # print("headers=", headers) # print("headers_len=", len(headers)) headers_content = [] @@ -562,7 +557,7 @@ class ProfilesPublicOperations: if pages >= 8: self.driver.find_element(By.XPATH, f"//li[text()='1']").click() else: - self.driver.find_element(By.XPATH, f"//li[text()='{pages}']").click() + self.driver.find_element(By.XPATH, f"//li[text()='{pages}' and contains(@style, 'rgb')]").click() # 右快速翻页 if pages >= 8: current_page = f"//*[@id='pagination-_pagination_{profiles}_Home_App_anonymousComponent']//li[contains(@class, 'active')]" @@ -576,7 +571,7 @@ class ProfilesPublicOperations: current_page_content = int(self.driver.find_element(By.XPATH, current_page).text.strip()) pytest_check.equal(current_page_content, flag, msg="所在行数{}".format(inspect.currentframe().f_lineno)) # 左翻页 - self.driver.find_element(By.XPATH, f"//li[text()='{pages}']").click() + self.driver.find_element(By.XPATH, f"//li[text()='{pages}' and contains(@style, 'rgb')]").click() while pages - 1: self.driver.find_element(By.XPATH, "//div[@class='pagination']//button[contains(@class, 'btn-prev')]").click() time.sleep(0.5) @@ -611,9 +606,13 @@ class ProfilesPublicOperations: btn = self.driver.find_element(By.XPATH, mainPage_language_russian_posXpath) self.driver.execute_script("arguments[0].click()", btn) time.sleep(1) + # 点击全选 + self.driver.find_element(By.XPATH, mainpage_profile_column_setting_posxpath).click() + for _ in range(2): + self.driver.find_element(By.XPATH, mainpage_profile_column_setting_show_all_posxpath).click() element_header = self.driver.find_element(By.XPATH, - "//div[contains(@class,'ly-table1')]//table[@class='el-table__header']//thead//tr") # 查询table的header - headers = element_header.find_elements(By.XPATH, "//th[@colspan='1']") # table header + "//div[@class='MuiDataGrid-topContainer MuiDataGrid-container--top css-1oudwrl']") # 查询table的header + headers = element_header.find_elements(By.XPATH, "//div[@data-field!='']//div[@class='MuiDataGrid-columnHeaderTitle css-mh3zap']") # table header # print("headers=", headers) # print("headers_len=", len(headers)) headers_content = [] @@ -643,27 +642,27 @@ class ProfilesPublicOperations: self.driver.isElementExist("//i[@class='iconfont icon-lock']") assert self.driver.Exist - def policy_create(self, action, profile_name, listPage_rule_create_button_posId, rule_input_Name_posXpath, - rule_action_posId, rule_source_add_posXpath, rule_button_oK_posId, rule_button_cancel_posId, + def policy_create(self, action, profile_name, listpage_rule_create_button_posxpath, rule_input_name_posxpath, + rule_action_posxpath, rule_source_add_posxpath, rule_button_ok_posxpath, rule_button_cancel_posxpath, rule_button_warningSaveYes_posCss, - application="http", rule_application_add_posXpath="", rule_application_search_posXpath="", + application="http", rule_application_add_posxpath="", rule_application_search_posxpath="", *actionParameters): """若策略为Intercept时,actionParameters[0]表示为引用profile的类型: Traffic_Mirror_Profile、SSL_Decryption_Keyring、SSL_Decryption_Profile、TCP_Proxy_Profile""" # 点击创建按钮 - self.driver.find_element(By.ID, listPage_rule_create_button_posId).click() + self.driver.find_element(By.XPATH, listpage_rule_create_button_posxpath).click() # 输入name policy_name = profile_name + "Rule" - self.driver.find_element(By.XPATH, rule_input_Name_posXpath).send_keys(policy_name) + self.driver.find_element(By.XPATH, rule_input_name_posxpath).send_keys(policy_name) # 选择Action - self.driver.find_element(By.ID, rule_action_posId).click() + self.driver.find_element(By.XPATH, rule_action_posxpath).click() # 选择source - self.driver.find_element(By.XPATH, rule_source_add_posXpath).click() + self.driver.find_element(By.XPATH, rule_source_add_posxpath).click() time.sleep(0.5) ## 选择IP的第一条记录 self.driver.find_element(By.XPATH, - "//div[@class='CommonListDetail list-detail']//ul[contains(@class, 'tableList')]/li[1]").click() + "(//div[@class='css-dob60y']//span[@class='truncate'])[1]").click() # 关闭侧滑框 - self.driver.find_element(By.XPATH, "//div[contains(text(),'IP Address')]/i").click() + self.driver.find_element(By.XPATH, "//div[@class='MuiDrawer-content css-10lcz44']//i[@class='iconfont icon-Clear_aNormal close-icon']").click() # 选择Application application_isselected = ["Manipulation_Allow", "Manipulation_Deny", "Manipulation_Monitor", "Manipulation_Replace", "Manipulation_Hijack", "Manipulation_Insert", @@ -671,13 +670,13 @@ class ProfilesPublicOperations: if action in application_isselected: pass elif action == "Intercept": - self.driver.find_element(By.XPATH, rule_application_add_posXpath).click() + self.driver.find_element(By.XPATH, rule_application_add_posxpath).click() self.driver.find_element(By.XPATH, f"//div[@class='AppList list-box']//div[@class='CommonListDetail list-detail']//ul[contains(@class, 'tableList')]//span[text()='{application}']").click() else: - self.driver.find_element(By.XPATH, rule_application_add_posXpath).click() - self.driver.find_element(By.XPATH, rule_application_search_posXpath).send_keys(application) - self.driver.find_element(By.XPATH, rule_application_search_posXpath).send_keys(Keys.ENTER) + self.driver.find_element(By.XPATH, rule_application_add_posxpath).click() + self.driver.find_element(By.XPATH, rule_application_search_posxpath).send_keys(application) + self.driver.find_element(By.XPATH, rule_application_search_posxpath).send_keys(Keys.ENTER) self.driver.find_element(By.XPATH, "//div[@class='AppList list-box']//div[@class='CommonListDetail list-detail']//ul[contains(@class, 'tableList')]/li[1]").click() # Action Parameters @@ -712,25 +711,25 @@ class ProfilesPublicOperations: self.driver.find_element(By.ID, actionParameters[9]).send_keys("300") elif action == "Manipulation_Deny": # 选择response code - self.driver.find_element(By.CSS_SELECTOR, actionParameters[0]).click() + self.driver.find_element(By.XPATH, actionParameters[0]).click() self.driver.find_element(By.XPATH, actionParameters[1]).click() time.sleep(1) # 选择 response content profile 类型 - self.driver.find_element(By.CSS_SELECTOR, actionParameters[2]).click() + self.driver.find_element(By.XPATH, actionParameters[2]).click() self.driver.find_element(By.XPATH, actionParameters[3]).click() # 选择profile self.driver.find_element(By.XPATH, actionParameters[4]).click() self.driver.find_element(By.XPATH, actionParameters[5]).send_keys(profile_name) # 输入查询值 self.driver.find_element(By.XPATH, actionParameters[5]).send_keys(Keys.ENTER) # 模拟回车按键 time.sleep(1) - if self.driver.find_element(By.XPATH, "//li[contains(@id, 'filelist_')]").get_attribute( - "id") == "filelist_null": - pytest_check.equal(self.driver.find_element(By.XPATH, "//li[contains(@id, 'filelist_')]").text.strip(), - "No Data", msg="所在行数{}".format(inspect.currentframe().f_lineno)) - result = "No Data" + if self.driver.element_isExist(By.XPATH, "//div[@class='css-dob60y']//div[@class='MuiBox-root css-1n4b3az']"): + self.driver.find_element(By.XPATH, "//div[@class='css-dob60y']//div[@class='MuiBox-root css-1n4b3az']").click() + result = self.driver.find_element(By.XPATH, "//div[@class='css-dob60y']//div[@class='MuiBox-root css-1n4b3az']").text + self.driver.find_element(By.XPATH, "//div[@class='css-dob60y']/following-sibling::div//button[normalize-space(text())='Cancel']").click() else: - self.driver.find_element(By.XPATH, "//li[@id='filelist_select0']").click() - result = self.driver.find_element(By.XPATH, "//li[@id='filelist_select0']").get_attribute("value") + pytest_check.equal(self.driver.find_element(By.XPATH, "//div[@class='px-[12px] pb-[4px] pt-[2px] text-[--color-text-disabled]']").text.strip(), + "Totol:0", msg="所在行数{}".format(inspect.currentframe().f_lineno)) + result = "No Data" elif action == "Manipulation_Hijack": # 选择URL ---URL为必填项 self.driver.find_element(By.XPATH, actionParameters[0]).click() @@ -899,13 +898,15 @@ class ProfilesPublicOperations: # 保存策略 if result == "No Data": print("无可引用的文件,取消创建") - self.driver.find_element(By.ID, rule_button_cancel_posId).click() - if self.driver.find_element(By.CSS_SELECTOR, rule_button_warningSaveYes_posCss).is_displayed(): - self.driver.find_element(By.CSS_SELECTOR, rule_button_warningSaveYes_posCss).click() + self.driver.find_element(By.XPATH, rule_button_cancel_posxpath).click() + # if self.driver.find_element(By.CSS_SELECTOR, rule_button_warningSaveYes_posCss).is_displayed(): + # self.driver.find_element(By.CSS_SELECTOR, rule_button_warningSaveYes_posCss).click() return 0 else: - self.driver.find_element(By.ID, rule_button_oK_posId).click() - self.driver.find_element(By.CSS_SELECTOR, rule_button_warningSaveYes_posCss).click() + element = self.driver.find_element(By.XPATH, rule_button_ok_posxpath) + self.driver.execute_script("arguments[0].scrollIntoView();", element) + element.click() + # self.driver.find_element(By.CSS_SELECTOR, rule_button_warningSaveYes_posCss).click() return policy_name def policy_query(self, listPage_policiesSearch_selectLabel_posId, listPage_policiesSearch_dropDown_item_posXpath, @@ -963,7 +964,7 @@ class ProfilesPublicOperations: """ from common.ui_common.login_logout.loginout import LogInOut username = self.driver.find_element(By.XPATH, '//*[@id="user_avator"]/span').text - if username == "AUTO_TEST": + if username == "AUTO_TEST_KG": loginout = LogInOut(self.driver) loginout.logout() time.sleep(1) @@ -975,7 +976,7 @@ class ProfilesPublicOperations: self.change_sou_vsys() # 跳转至Federation-Policy Links # 点击Menu按钮 - self.driver.find_element(By.CSS_SELECTOR, mainPage_button_menu_posXCss).click() + self.driver.find_element(By.XPATH, mainpage_button_menu_posxpath).click() # 点击Admin area self.driver.find_element(By.XPATH, mainPage_navigationBar_Menu_adminArea_posXpath).click() # 点击Federation @@ -1025,7 +1026,7 @@ class ProfilesPublicOperations: def _del_policy_links(self, Request_ID): from common.ui_common.login_logout.loginout import LogInOut username = self.driver.find_element(By.XPATH, '//*[@id="user_avator"]/span').text - if username == "AUTO_TEST": + if username == "AUTO_TEST_KG": loginout = LogInOut(self.driver) loginout.logout() time.sleep(1) @@ -1102,53 +1103,217 @@ class ProfilesPublicOperations: res.append(i) assert len(res) == 1 - def audit_log_view(self, profiles_type, search_ID , import_verify=1): - user_name = self.driver.find_element(By.XPATH, '//*[@id="user_avator"]/span').text - self.driver.find_element(By.ID, mainPage_firstLevelMenu_System_posId).click() - self.driver.find_element(By.ID, mainPage_secondLevelMenu_auditLogs_posId).click() + def search_compare_item(self, profiles_type, search_id, operation_type, operation_flag): + # 跳转到系统audit_log页 + user_name = self.driver.find_element(By.XPATH, "(//*[@id='header-profile-button'])[last()]").text + self.driver.find_element(By.XPATH, main_page_first_level_menu_system_posxpath).click() + self.driver.find_element(By.XPATH, main_page_second_level_menu_audit_log_posxpath).click() time.sleep(3) - self.driver.find_element(By.ID, mainPage_profileSearch_selectLabel_posId).click() - # 选择Targrt ID - self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_TagrgetID_posXpath).click() - self.driver.find_element(By.XPATH, listPage_auditlogSearch_targetid_text_posXpath).send_keys( - search_ID + Keys.ENTER) - # 选择Target Type - self.driver.find_element(By.ID, mainPage_profileSearch_selectLabel_posId).click() - self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_TargetType_posXpath).click() + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_input_posxpath).click() + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_dropdown_item_posxpath.format( + replace_name='Target Type')).click() scrollable_div = self.driver.find_element(By.XPATH, - f"//div[@class='el-select-dropdown el-popper select-popper']//span[text()='{profiles_type}']") + f"//ul[@class='base-Popper-root MuiSelect-listbox Mui-expanded css-1wd16dk']//li[normalize-space(text())='{profiles_type}']") self.driver.execute_script("arguments[0].scrollIntoView();", scrollable_div) scrollable_div.click() # 选择当前用户 - self.driver.find_element(By.ID, mainPage_profileSearch_selectLabel_posId).click() - self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_UserName_posXpath).click() - self.driver.find_element(By.XPATH, listPage_auditlogSearch_username_text_posXpath).send_keys(user_name) - time.sleep(2) - self.driver.find_element(By.XPATH, f"//div[@x-placement='bottom-start']//span[text()='{user_name}']").click() - # 搜索 - self.driver.find_element(By.ID, mainPage_profileSearch_buttonSearch_posId).click() + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_input_posxpath).click() + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_input_posxpath).send_keys(user_name) + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_dropdown_item_posxpath.format( + replace_name='User Name')).click() + # self.driver.find_element(By.XPATH, f"//div[@x-placement='bottom-start']//span[text()='{user_name}']").click() + time.sleep(0.5) + if operation_flag == 0: # create / edit / delete / import / export + # 选择Targrt ID + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_input_posxpath).click() + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_input_posxpath).send_keys(search_id) + + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_dropdown_item_posxpath.format( + replace_name='Target ID')).click() + + # 选择Targrt Operation + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_input_posxpath).click() + + self.driver.find_element(By.XPATH, list_page_audit_log_search_select_dropdown_item_posxpath.format( + replace_name='Operation')).click() + operation_text = self.driver.find_element(By.XPATH, + f"//ul[@class='base-Popper-root MuiSelect-listbox Mui-expanded css-1wd16dk']//li[normalize-space(text())='{operation_type}']") + self.driver.execute_script("arguments[0].click()", operation_text) # 搜索 - time.sleep(1) - operation_text_elements = self.driver.find_elements(By.XPATH, - "(//table[@class='el-table__body'])[1]//tbody/tr/td[3]//span") - if import_verify == 0: - operation = ["Create", "Edit", "Delete", "Import", "Query Verbose"] + self.driver.find_element(By.XPATH, mainpage_profile_search_button_search_posxpath).click() + + def _check_audit_log_system_page(self, profiles_type, user_name, search_id, compare_time, operation_flag): + if operation_flag == 0: # 删除 + # 版本确认 + version = self.driver.find_element(By.XPATH, "//div[@class='row-text-border row-text-font el-col el-col-5']").text + pytest_check.equal(version, "Current (V.3)", + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Operation 确认 + operation = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[2]").text + pytest_check.equal(operation, 'Delete', + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # 时间确认 + _time = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[5]").text + total_seconds = self._compute_time_diff(_time, compare_time) + pytest_check.less_equal(total_seconds, 1, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + elif operation_flag == 1: # 详情页编辑 + # 版本确认 + version = self.driver.find_element(By.XPATH, "//div[@class='row-text-border row-text-font el-col el-col-5']").text + pytest_check.equal(version, "Current (V.2)", + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Operation 确认 + operation = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[2]").text + pytest_check.equal(operation, 'Edit', + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + _time = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[5]").text + pytest_check.equal(_time, compare_time, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + + # Target ID 确认 + target_id = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[1]").text + pytest_check.equal(target_id, search_id, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Target Type 确认 + target_type = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[3]").text + pytest_check.equal(target_type, profiles_type, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + parse_dir = os.path.join(self.workdir, "config", "loginout.ini") + self.config_parser.read(parse_dir, encoding="utf-8") + url = self.config_parser.get("remote_url", "url") + ip = url.split(':')[1].split('//')[-1] + # IP 确认 + source_ip = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[4]").text + pytest_check.equal(source_ip, ip, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # User 确认 + user = self.driver.find_element(By.XPATH, "(//div[@class='row-text-border el-col el-col-5'])[6]").text.replace(" ", "") + pytest_check.equal(user_name, user, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + + def _check_audit_log_detail_page(self, profiles_type, user_name, search_id, compare_time, operation_flag): + if operation_flag == 0: # 创建 + # 版本确认 + version = self.driver.find_element(By.XPATH, "//div[@class='row-text-font el-col el-col-5']").text + pytest_check.equal(version, "V.1", + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Operation 确认 + operation = self.driver.find_element(By.XPATH, "(//div[@class='el-col el-col-5'])[2]").text + pytest_check.equal(operation, 'Create', + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # 时间确认 + _time = self.driver.find_element(By.XPATH, "(//div[@class='el-col el-col-5'])[5]").text + pytest_check.equal(_time, compare_time, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + elif operation_flag == 1: # 详情页编辑 + # 版本确认 + version = self.driver.find_element(By.XPATH, "//div[@class='row-text-font el-col el-col-5']").text + pytest_check.equal(version, "V.2", + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Operation 确认 + operation = self.driver.find_element(By.XPATH, "(//div[@class='el-col el-col-5'])[2]").text + pytest_check.equal(operation, 'Edit', + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + _time = self.driver.find_element(By.XPATH, "(//div[@class='el-col el-col-5'])[5]").text + total_seconds = self._compute_time_diff(_time, compare_time) + pytest_check.less_equal(total_seconds, 1, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + elif operation_flag == 2: # Query Verbose + # 版本确认 + version = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[1]").text + pytest_check.equal(version, "V.1", + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Operation 确认 + operation = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[3]").text + pytest_check.equal(operation, 'Query Verbose', + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # 时间确认 + _time = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[6]").text + total_seconds = self._compute_time_diff(_time, compare_time) + pytest_check.less_equal(total_seconds, 1, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + elif operation_flag == 3: # Query List + # Operation 确认 + operation = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[3]").text + pytest_check.equal(operation, 'Query List', + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # 时间确认 + _time = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[6]").text + total_seconds = self._compute_time_diff(_time, compare_time) + pytest_check.less_equal(total_seconds, 1, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + + if operation_flag == 3: + pass else: - operation = ["Create", "Edit", "Delete", "Query Verbose"] - operation_text = [] - for i in range(len(operation_text_elements)): - text = self.driver.find_element(By.XPATH, - f"((//table[@class='el-table__body'])[1]//tbody/tr/td[3]//span)[{i + 1}]").text - operation_text.append(text) - if set(operation_text) != set(operation): - raise Exception("存在未记录日志") + # Target ID 确认 + target_id = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[2]").text + pytest_check.equal(target_id, search_id, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # Target Type 确认 + target_type = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[4]").text + pytest_check.equal(target_type, profiles_type, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + parse_dir = os.path.join(self.workdir, "config", "loginout.ini") + self.config_parser.read(parse_dir, encoding="utf-8") + url = self.config_parser.get("remote_url", "url") + ip = url.split(':')[1].split('//')[-1] + # IP 确认 + source_ip = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[5]").text + pytest_check.equal(source_ip, ip, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # User 确认 + user = self.driver.find_element(By.XPATH, "(//div[@class='MuiGrid-root MuiGrid-item MuiGrid-grid-xs-2.5 css-n8utul']/div)[7]").text.replace(" ", "") + pytest_check.equal(user_name, user, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + + def _audit_log_delete(self, profiles_type, search_id, operation_type): + click_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + # 用户 + user_name = self.driver.find_element(By.XPATH, "(//button[@id='header-profile-button'])[last()]").text + user_name = user_name + "@" + user_name + + self.search_compare_item(profiles_type, search_id, operation_type=operation_type, + operation_flag=0) + # 点击 Compare 对比 + self.driver.find_element(By.XPATH, + "//button[@class='el-button btn-style el-button--info el-button--mini']/span[normalize-space(text())='Compare']").click() + + # 对比 V.1 + self.driver.find_element(By.XPATH, "(//input[@class='PrivateSwitchBase-input css-1m9pwf3'])[last()]").click() + # 对比 V.2 + self.driver.find_element(By.XPATH, + "(//input[@class='PrivateSwitchBase-input css-1m9pwf3'])[1]").click() + + self.driver.find_element(By.XPATH, list_page_audit_log_search_button_compare_posxpath).click() + self._check_audit_log_system_page(profiles_type, user_name, search_id, click_time, operation_flag=0) + + def _audit_log_query_list(self, profiles_type, search_dict, operation_type): + click_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + # 用户 + user_name = self.driver.find_element(By.XPATH, "(//button[@id='header-profile-button'])[last()]").text + user_name = user_name + "@" + user_name + + self.search_compare_item(profiles_type, search_dict, operation_type=operation_type, + operation_flag=1) + time.sleep(0.5) + # 点击 Compare 对比 + self.driver.find_element(By.XPATH, + "(//button[normalize-space(text())='View'])[1]").click() + self._check_audit_log_detail_page(profiles_type, user_name, search_dict, click_time, operation_flag=3) + + def _compute_time_diff(self, _time, compare_time): + format_str = "%Y-%m-%d %H:%M:%S" + datetime1 = date_time.strptime(_time, format_str) + datetime2 = date_time.strptime(compare_time, format_str) + time_diff = datetime2 - datetime1 + # 提取时间差的总秒数 + total_seconds = time_diff.total_seconds() + return total_seconds def global_delete_method(self, pro_type): - # obj_and_posid = {"accounts":"Objects_account","flags":"Objects_flag"} - # if pro_type[-1] == "s": - # pro_type = pro_type[0:-1] - # common_menu_pos_id = f'Profiles_{pro_type}' + # link 执行自己的删除方法 if "link" in pro_type: return 0 chose_dict = { @@ -1172,7 +1337,7 @@ class ProfilesPublicOperations: "test_ssl_fingerprints.py": mainPage_secondLevelMenu_sslFingerprint_posId, "test_cached_intermediate_certificates.py":mainPage_secondLevelMenu_cachedIntermediateCertificates_posId, } - self.change_vsys() + self.change_vsys("UIAutoTestVsys") # 页面跳转 self.driver.find_element(By.ID, mainPage_firstLevelMenu_profiles_posId).click() try: @@ -1184,7 +1349,7 @@ class ProfilesPublicOperations: pass self.driver.find_element(By.ID, chose_dict[pro_type]).click() # 简单筛选 - self.clear_name_by_id(mainPage_ObjectSearch_selectLabel_posId) + self.clear_name_by_id(mainPage_profileSearch_selectLabel_posId) profiles_search_input_elem = self.wait.until( EC.presence_of_element_located((By.ID, mainPage_profileSearch_selectLabel_posId))) profiles_search_input_elem.send_keys("test") @@ -1224,6 +1389,15 @@ class ProfilesPublicOperations: element = self.driver.find_element(By.ID, id) element.send_keys(Keys.CONTROL + 'a') element.send_keys(Keys.DELETE) + + def random_substring(self, s): + length = len(s) + if length == 0: + return "" + start = random.randint(0, length - 1) + end = random.randint(start + 1, length) + return s[start:end] + def download_file(): my_file = ReadData() options = webdriver.ChromeOptions() @@ -1243,9 +1417,9 @@ def download_file(): driver.maximize_window() aut_username = loginout_parse.get("ui_account_1", "username") aut_pwd = loginout_parse.get("ui_account_1", "passwd") - driver.find_element(By.NAME, loginPage_userName_posName).send_keys(aut_username) - driver.find_element(By.NAME, loginPage_passwd_posName).send_keys(aut_pwd) - driver.find_element(By.ID, "login").click() + driver.find_element(By.XPATH, loginpage_username_posxpath).send_keys(aut_username) + driver.find_element(By.XPATH, loginpage_passwd_posxpath).send_keys(aut_pwd) + driver.find_element(By.XPATH, login_page_sign_in_posxpath).click() return driver @@ -1259,6 +1433,7 @@ def cached_intermediate_certificates_driver(): loginout_parse.read(loginout_parse_dir, encoding="utf-8") remote_url = loginout_parse.get("remote_url", "url") options.add_experimental_option('prefs', prefs) + # options.add_argument('--headless') # 启用Headless模式 options.add_argument("--incognito") driver = MyWebDriver( command_executor=remote_url, diff --git a/common/ui_common/profiles/response_pages.py b/common/ui_common/profiles/response_pages.py index fb481802..63a15fe1 100644 --- a/common/ui_common/profiles/response_pages.py +++ b/common/ui_common/profiles/response_pages.py @@ -1,5 +1,6 @@ # -*- coding: UTF-8 -*- import time +import datetime from common.driver_common.mywebdriver import MyWebDriver from selenium.webdriver.common.by import By from config.workpath import workdir @@ -29,20 +30,20 @@ class ResponsePages: def response_page_case(self, data: {}): self._create(data) #创建 time.sleep(3) - self._query(data, Name=self.random_name) #创建后查询 + self._query(data, require_assertion=1, Name=self.random_name) #创建后查询 if data["model"].strip().lower() == "modify": #修改测试时,执行修改方法 self._modify(data) time.sleep(2) - self._query(data, ID=self.first_row_ID_content) + self._query(data, require_assertion=2, Name=self.random_name) self._del() @screenshot_on_failure def _goto_subProfilePage(self, vsys_name_2=""): # 菜单操作,定位到responsePages列表页 - # self.driver.find_element(By.CSS_SELECTOR, mainPage_navigationBar_logo_posCss).click() + self.driver.find_element(By.XPATH, mainpage_navigation_bar_logo_posxpath).click() self.profiles_po.change_vsys(vsys_name=vsys_name_2) - self.driver.find_element(By.ID, mainPage_firstLevelMenu_profiles_posId).click() - self.driver.find_element(By.ID, mainPage_secondLevelMenu_responsePages_posId).click() + self.driver.find_element(By.XPATH, mainpage_first_level_menu_profiles_posxpath).click() + self.driver.find_element(By.XPATH, mainpage_second_level_menu_response_pages_posxpath).click() @screenshot_on_failure def _goto_vsysPage(self, vsys_name_2=""): @@ -55,48 +56,53 @@ class ResponsePages: self._goto_subProfilePage() #创建responsePages #点击create - self.driver.find_element(By.ID, listPage_profile_responsePages_createButton_posId).click() + self.driver.find_element(By.XPATH, listpage_profile_response_pages_create_button_posxpath).click() #在create resposne page页面操作 if source_name: self.random_name = source_name[0] - self.driver.find_element(By.ID, responsePage_input_Name_posId).send_keys(self.random_name) + self.driver.find_element(By.XPATH, response_page_input_name_posxpath).send_keys(self.random_name) else: self.random_name = self.my_random.random_name() - self.driver.find_element(By.ID, responsePage_input_Name_posId).send_keys(self.random_name) + self.driver.find_element(By.XPATH, response_page_input_name_posxpath).send_keys(self.random_name) #上传文件 create_file_ = data["file"].split("->")[0] #提取上传文件绝对路径 if create_file_ != "": print(create_file_) create_file_abs = self._abs_path(create_file_) print(create_file_abs) - self.driver.find_element(By.XPATH, responsePage_input_file_posXpath).send_keys(create_file_abs) + self.driver.find_element(By.XPATH, response_page_input_file_posxpath).send_keys(create_file_abs) if data["file"].split("->")[0].strip() == "error_type.txt": # 上传错误文件类型 pytest_check.equal(self.driver.find_element(By.CSS_SELECTOR, ".el-message__content").text.strip(), "\"html\" and \"htm\" only", msg="所在行数{}".format(inspect.currentframe().f_lineno)) - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_cancel_posCss).click() + self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveCancel_posCss).click() self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() else: # 校验name #点击OK - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_oK_posCss).click() - if len(self.random_name) < 4: # name不符合要求 - if self.driver.element_isExist(By.XPATH, "//div[@class='el-form-item__error']"): + self.driver.find_element(By.XPATH, response_page_button_ok_posxpath).click() + if len(self.random_name) == 0: + print("Name cannot be empty") + pytest_check.equal(self.driver.find_element(By.XPATH,"//div[@class='MuiFormHelperText-root css-1y20gt9']").text.strip(), + "Name cannot be empty", msg="所在行数{}".format(inspect.currentframe().f_lineno)) + self.driver.find_element(By.XPATH, response_page_button_cancel_posxpath).click() + if len(self.random_name) < 4 and len(self.random_name) > 0: # name不符合要求 + if self.driver.element_isExist(By.XPATH, "//div[@class='MuiFormHelperText-root css-1y20gt9']"): print("The length of the name is at most 128 characters and cannot be less than 4 characters") - pytest_check.equal(self.driver.find_element(By.XPATH, "//div[@class='el-form-item__error']").text.strip(), + pytest_check.equal(self.driver.find_element(By.XPATH, "//div[@class='MuiFormHelperText-root css-1y20gt9']").text.strip(), "The length of the name is at most 128 characters and cannot be less than 4 characters", msg="所在行数{}".format(inspect.currentframe().f_lineno)) else: print("name less than 4,no error message") - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_cancel_posCss).click() - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() - elif self.driver.find_element(By.XPATH, responsePage_input_file_posXpath).get_attribute("value") == "": # 未上传文件 - if self.driver.find_element(By.XPATH, "//p[contains(.,'Please choose to upload files')]").is_displayed(): - print("Please choose to upload files") - pytest_check.equal(self.driver.find_element(By.XPATH, "//p[contains(.,'Please choose to upload files')]").text.strip(), - "Please choose to upload files", msg="所在行数{}".format(inspect.currentframe().f_lineno)) - # 数据正确时操作 - elif self.driver.element_isExist(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss): - print(self.driver.element_isExist(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss)) - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() + self.driver.find_element(By.XPATH, response_page_button_cancel_posxpath).click() + # self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() + # elif self.driver.find_element(By.XPATH, response_page_input_file_posxpath).get_attribute("value") == "": # 未上传文件 + # if self.driver.find_element(By.XPATH, "//p[contains(.,'Please choose to upload files')]").is_displayed(): + # print("Please choose to upload files") + # pytest_check.equal(self.driver.find_element(By.XPATH, "//p[contains(.,'Please choose to upload files')]").text.strip(), + # "Please choose to upload files", msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # # 数据正确时操作 + # elif self.driver.element_isExist(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss): + # print(self.driver.element_isExist(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss)) + # self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() return self.random_name def _abs_path(self, file_name): @@ -123,34 +129,37 @@ class ResponsePages: #打开该列表 self._goto_subProfilePage(vsys_name_2=vsys_name_2) #first_row查询到的第一行内容。map_header_className为需要使用的到字典,用来提取第一行的结果。 - result = self.profiles_po.query(listPage_profileSearch_responsePages_selectLabel_posId, listPage_profileSearch_responsePages_dropDown_item_posXpath, - listPage_profileSearch_responsePages_input_itemContent_posXpath, listPage_profileSearch_responsePages_buttonSearch_posId, - listPage_profilTable_responsePages_tableTbody_posXpath, listPage_profilTable_responsePages_tableHeader_posXpath, **kwargs) + result = self.profiles_po.query(listpage_profile_search_response_pages_select_label_posxpath, listpage_profile_search_response_pages_drop_down_item_posxpath, + listpage_profile_search_response_pages_input_item_content_posxpath, listpage_profile_search_response_pages_button_search_posxpath, + listpage_profile_table_response_pages_table_tbody_posxpath, listpage_profile_table_response_pages_table_header_posxpath, **kwargs) if result == [0, 0]: return 0 else: - first_row, map_header_className =result + first_row , map_header_className = result #第一行的勾选定位,给修改、删除使用 - self.first_row_checkBox_element = first_row.find_element(By.XPATH, "//span[@class='el-checkbox__input']") - self.first_row_ID_content = first_row.find_element(By.XPATH, "//div[@class='table-status-item-id']/span").text.strip() - # 提取 ID Name VsysID - first_row_id_content = first_row.find_element(By.XPATH, "//div[@class='table-status-item-id']//span").text.strip() - first_row_Name_class = map_header_className["Name"] - first_row_Name_content = first_row.find_element(By.XPATH, f"//td[contains(@class, '{first_row_Name_class}')]//span").text.strip() + self.first_row_checkbox_element = first_row.find_element(By.XPATH, "//input[@class='MuiCheckbox-input css-1jj0cvj']") + # self.first_row_ID_content = first_row.find_element(By.XPATH, "//div[@class='table-status-item-id']/span").text.strip() + # 提取 UUID Name + column_allname = ["Vsys ID", "UUID", "Name", "File", "Usage", "Modified Time", "Operator"] + self._column_setting_help(column_allname, column_flags = 2) + first_row_uuid_content = self.driver.find_element(By.XPATH, "//div[@data-field='uuid' and @data-colindex=3]").text.strip() + # first_row_Name_class = map_header_className["Name"] + first_row_name_content = first_row.find_element(By.XPATH, "//div[@data-field='name' and @data-colindex=4]").text.strip() #first_row_VsysID_class = map_header_className["Vsys ID"] #first_row_VsysID_content = first_row.find_element(By.XPATH, f"//td[contains(@class, '{first_row_VsysID_class}')]//span").text.strip() - # #不同操作后的断言,创建后、修改后、无断言 - # if require_assertion == 1: #直接创建后,使用的断言 - # pytest_check.equal(first_row_Name_content, self.random_name, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - # elif require_assertion == 2 and data["model"].strip().lower() == "modify": #修改数据后,使用的断言 - # pytest_check.equal(first_row_Name_content, self.random_name, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - # else: #不适用断言 - # pass + #不同操作后的断言,创建后、修改后、无断言 + # print('first_row_name_content = ', first_row_name_content , self.random_name) + if require_assertion == 1: #直接创建后,使用的断言 + pytest_check.equal(first_row_name_content, self.random_name, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + elif require_assertion == 2 and data["model"].strip().lower() == "modify": #修改数据后,使用的断言 + pytest_check.equal(first_row_name_content, self.random_name, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + else: #不适用断言 + pass #强制点击清空查询按钮 - element_clear = self.driver.find_element(By.ID, listPage_profileSearch_responsePages_buttonClear_posId) - self.driver.execute_script("arguments[0].click()", element_clear) # 强制点击 + # element_clear = self.driver.find_element(By.XPATH, listPage_profileSearch_responsePages_buttonClear_posId) + # self.driver.execute_script("arguments[0].click()", element_clear) # 强制点击 - search_dict = {"ID": first_row_id_content, "Name": first_row_Name_content} + search_dict = {"UUID": first_row_uuid_content, "Name": first_row_name_content} print(search_dict) # 断言: search_key = list(kwargs.keys())[0] @@ -169,25 +178,25 @@ class ResponsePages: if data["model"].strip().lower() == "create": #如果是create参数用例,则不用执行修改方法 return 0 #点击勾选第一行选择框 - self.first_row_checkBox_element.click() #变量来自查询函数 - self.driver.find_element(By.ID, listPage_profile_responsePages_editButton_posId).click() + self.first_row_checkbox_element.click() #变量来自查询函数 + self.driver.find_element(By.XPATH, listpage_profile_response_pages_edit_button_posxpath).click() # 判断保存后内容是否丢失、是否不显示 - current_name = self.driver.find_element(By.ID, responsePage_input_Name_posId).get_attribute("value") + current_name = self.driver.find_element(By.XPATH, response_page_input_name_posxpath).get_attribute("value") print("current_name=", current_name) pytest_check.equal(current_name, self.random_name, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - assert self.driver.find_element(By.XPATH, "//a[@class='el-upload-list__item-name']").text.strip(), "内容未丢失" + assert self.driver.find_element(By.XPATH, "//div[@class='flex-1 truncate']").text.strip(), "内容未丢失" #根据修改数据,修改上次文件 modify_file = data["file"].split("->")[-1] #提取上传文件绝对路径 if modify_file != "不修改": modify_file_abs = self._abs_path(modify_file) - self.driver.find_element(By.XPATH, responsePage_input_file_posXpath).send_keys(modify_file_abs) + self.driver.find_element(By.XPATH, response_page_input_file_posxpath).send_keys(modify_file_abs) elif modify_file == "不修改": # 不修改file时,修改name new_Name = "(修改后)" - self.driver.find_element(By.ID, responsePage_input_Name_posId).send_keys(new_Name) + self.driver.find_element(By.XPATH, response_page_input_name_posxpath).send_keys(new_Name) #点击ok - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_oK_posCss).click() - if self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).is_displayed(): - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() + self.driver.find_element(By.XPATH, response_page_button_ok_posxpath).click() + # if self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).is_displayed(): + # self.driver.find_element(By.CSS_SELECTOR, responsePage_button_warningSaveYes_posCss).click() @screenshot_on_failure def _del(self, del_model=0): @@ -198,9 +207,9 @@ class ResponsePages: #点击勾选第一行选择框 if del_model == 0: #点击勾选第一行选择框 - self.first_row_checkBox_element.click() #变量来自查询函数 + self.first_row_checkbox_element.click() #变量来自查询函数 elif del_model == 1: # 勾选可以删除的选项,并删除;没有锁、没有被引用的对象 - rows = self.driver.find_element(By.XPATH, listPage_profilTable_dnsRecords_tableTbody_posXpath).find_elements(By.XPATH, "./tr") + rows = self.driver.find_element(By.XPATH, listpage_profile_table_response_pages_table_tbody_posxpath).find_elements(By.XPATH, "./tr") if len(rows) == 0: # 没有数据,直接返回 return else: @@ -208,8 +217,8 @@ class ResponsePages: if del_result == 1: # 1表示没有删除对象,直接返回 return 0 #调用profiles的功能删除方法 - self.profiles_po.delete(listPage_profile_responsePages_delButton_posId, listPage_dialogTips_responsePages_button_yes_posCss, - listPage_dialogTips_responsePages_button_no_posCss) + self.profiles_po.delete(listpage_profile_response_pages_del_button_posxpath, listpage_dialogtips_response_pages_button_yes_posxpath, + listpage_dialogtips_response_pages_button_no_posxpath) def _column_setting(self, column: (), column_flags=0): """ @@ -221,11 +230,21 @@ class ResponsePages: """ # 打开该列表 self._goto_subProfilePage() + self._column_setting_help(column, column_flags) + + def _column_setting_help(self, column: (), column_flags=0): + """ + 列设置函数, + column_flags: 0---保持当前状态 1---仅显示默认列 2---显示所有列 3---显示自定义列 + :param column_flags: + :param kwargs: + :return: + """ profiles = "Profile_ResponsePages" - column_click = column[2:] - current_column = self.profiles_po.column_setting(mainPage_profileColumn_columnSetting_posId, listPage_profileColumn_responsePages_button_columnAll_posXpath, listPage_profileColumn_responsePages_button_cancel_posId, - listPage_profileColumn_responsePages_button_ok_posId, profiles, column_flags, column_click) - pytest_check.equal(current_column, column, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + column_click = column[1:] + current_column = self.profiles_po.column_setting(mainpage_profile_column_setting_posxpath, + mainpage_profile_column_setting_show_all_posxpath, profiles, column_flags, column_click) + pytest_check.equal(set(current_column), set(column), msg="所在行数{}".format(inspect.currentframe().f_lineno)) def _file_download(self, **kwargs): """ @@ -235,15 +254,12 @@ class ResponsePages: """ self._goto_subProfilePage() first_row, map_header_className = \ - self.profiles_po.query(listPage_profileSearch_responsePages_selectLabel_posId, - listPage_profileSearch_responsePages_dropDown_item_posXpath, - listPage_profileSearch_responsePages_input_itemContent_posXpath, - listPage_profileSearch_responsePages_buttonSearch_posId, - listPage_profilTable_responsePages_tableTbody_posXpath, - listPage_profilTable_responsePages_tableHeader_posXpath, **kwargs) - first_row_file_class = map_header_className["File"] - print("first_row_File_class=", first_row_file_class) - first_row.find_element(By.XPATH, f"//td[contains(@class, '{first_row_file_class}')]//i").click() + self.profiles_po.query(listpage_profile_search_response_pages_select_label_posxpath, listpage_profile_search_response_pages_drop_down_item_posxpath, + listpage_profile_search_response_pages_input_item_content_posxpath, listpage_profile_search_response_pages_button_search_posxpath, + listpage_profile_table_response_pages_table_tbody_posxpath, listpage_profile_table_response_pages_table_header_posxpath, **kwargs) + # first_row_file_class = map_header_className["File"] + # print("first_row_File_class=", first_row_file_class) + self.driver.find_element(By.XPATH, "//div[@data-field='file_path' and @data-colindex=3]").click() def _turn_pages(self, pages): """ @@ -264,19 +280,19 @@ class ResponsePages: :return: """ self._goto_subProfilePage() - header_content = self.profiles_po.language_change(mainPage_language_change_posXpath, mainPage_language_chinese_posXpath, - mainPage_language_russian_posXpath, mainPage_language_english_posXpath, language) + header_content = self.profiles_po.language_change(mainpage_language_change_posxpath, mainpage_language_dropdown_item_posxpath.format(replace_language='中文'), + mainpage_language_dropdown_item_posxpath.format(replace_language='Русский'), mainpage_language_dropdown_item_posxpath.format(replace_language='English'), language) # 断言 time.sleep(2) if language == 0: - header_english = ['ID', 'Vsys ID', 'Name', 'File', 'Reference Count', 'Modified Time', 'Last Modified By'] - assert set(header_content).issubset(set(header_english)) + header_english = ['Vsys ID', 'Name', 'File', 'Usage', 'Modified Time', 'Operator'] + pytest_check.equal(header_content, header_english, msg="所在行数{}".format(inspect.currentframe().f_lineno)) if language == 1: - header_chinese = ['ID', '虚拟系统 ID', '名称', '文件', '引用计数', '操作时间', '最后一次修改者'] - assert set(header_content).issubset(set(header_chinese)) + header_chinese = ['虚拟系统 ID', '名称', '文件', '引用计数', '操作时间', '操作员'] + pytest_check.equal(header_content, header_chinese, msg="所在行数{}".format(inspect.currentframe().f_lineno)) if language == 2: - header_russian = ['ID', 'Vsys ID', 'Имя', 'Файл', 'Подсчет Ссылок', 'Время Изменения', 'Последний Раз Редактирован'] - assert set(header_content).issubset(set(header_russian)) + header_russian = ['Vsys ID', 'Имя', 'Файл', 'Время Изменения', 'Время Изменения', 'Оператор'] + pytest_check.equal(header_content, header_russian, msg="所在行数{}".format(inspect.currentframe().f_lineno)) def _vsys_case(self, data, c_vsys, c_type, c_supervisor, f_vsys, f_type, f_supervisor="None"): name = self._create(data, f_vsys) @@ -304,39 +320,18 @@ class ResponsePages: elif c_type =="Tvsys" and f_type =="Mvsys": # Tvsys查看Mvsys数据,不可查 pytest_check.equal(result, 0, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - @screenshot_on_failure - def _audit_log(self, operation): - """ - operation: Add---create; Update---modify - :param operation: - :return: - """ - self.first_row_checkBox_element.click() - self.driver.find_element(By.ID, listPage_profile_responsePages_editButton_posId).click() - time.sleep(2) - self.driver.find_element(By.XPATH, "//div[@class='audit_log']/span").click() - # 第一条记录勾选框 - self.driver.find_element(By.XPATH, "//tr[1]/td/div/label/span").click() - # 点击Compare - btn_compare = self.driver.find_element(By.ID, "test-compare-_AuditLogs_InfoRightProfile_VPanel_VEditPanel_interceptionadd_Home_App_anonymousComponent") - self.driver.execute_script("arguments[0].click()", btn_compare) # 强制点击 - time.sleep(0.5) - # 获取 operation content - current_operation = self.driver.find_element(By.XPATH, "//div[@class='compare-code-title']//div[3]/div[2]").text.strip() - pytest_check.equal(current_operation, operation, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - self.driver.find_element(By.CSS_SELECTOR, responsePage_button_cancel_posCss).click() def _policy_create(self, profile_name): # 进入Manipulation列表页 self._goto_vsysPage() - self.driver.find_element(By.ID, mainPage_firstLevelMenu_Policy_posId).click() - self.driver.find_element(By.ID, mainPage_secondLevelMenu_Proxy_Manipulation_posId).click() + self.driver.find_element(By.XPATH, mainpage_first_level_menu_policy_posxpath).click() + self.driver.find_element(By.XPATH, mainpage_second_level_menu_proxy_manipulation_posxpath).click() # 创建rule - policy_name = self.profiles_po.policy_create("Manipulation_Deny", profile_name, listPage_manipulation_create_button_posId, manipulation_input_Name_posXpath, - manipulation_action_label_Deny_posId, manipulation_source_add_posXpath, manipulation_button_oK_posId, manipulation_button_cancel_posId, + policy_name = self.profiles_po.policy_create("Manipulation_Deny", profile_name, listpage_manipulation_create_button_posxpath, manipulation_input_name_posxpath, + manipulation_action_label_deny_posxpath, manipulation_source_add_posxpath, manipulation_button_ok_posxpath, manipulation_button_cancel_posxpath, manipulation_button_warningSaveYes_posCss, "http", "", "", - deny_responseCode_dropDown_item_posCss, deny_responseCode_403_posXpath, deny_responseContent_dropDown_item_posCss, - deny_responseContent_Profile_posXpath, deny_responseContent_profile_dropDown_item_posXpath, deny_responseContent_profile_search_posXpath) + deny_response_code_drop_down_item_posxpath, deny_response_code_403_posxpath, deny_response_content_dropdown_item_posxpath, + deny_response_content_profile_posxpath, deny_response_content_profile_add_posxpath, deny_response_content_profile_search_posxpath) return policy_name @screenshot_on_failure @@ -349,13 +344,13 @@ class ResponsePages: """ # 打开该列表 self._goto_vsysPage() - self.driver.find_element(By.ID, mainPage_firstLevelMenu_Policy_posId).click() - self.driver.find_element(By.ID, mainPage_secondLevelMenu_Proxy_Manipulation_posId).click() + self.driver.find_element(By.XPATH, mainpage_first_level_menu_policy_posxpath).click() + self.driver.find_element(By.XPATH, mainpage_second_level_menu_proxy_manipulation_posxpath).click() # first_row查询到的第一行内容。map_header_className为需要使用的到字典,用来提取第一行的结果。 - result = self.profiles_po.query(listPage_manipulationSearch_selectLabel_posId, - listPage_manipulationSearch_dropDown_item_posXpath, + result = self.profiles_po.query(listpage_manipulation_search_button_search_posxpath, + listpage_manipulation_search_drop_down_item_posxpath, listPage_manipulationSearch_input_itemContent_posXpath, - listPage_manipulationSearch_buttonSearch_posId, + listpage_manipulation_search_button_search_posxpath, listPage_manipulationTable_tableTbody_posXpath, listPage_manipulationTable_tableHeader_posXpath, **kwargs) if result == [0, 0]: @@ -363,7 +358,7 @@ class ResponsePages: else: first_row, map_header_className = result # 第一行的勾选定位,给修改、删除使用 - self.first_row_checkBox_element = first_row.find_element(By.XPATH, "//span[@class='el-checkbox__input']") + self.first_row_checkbox_element = first_row.find_element(By.XPATH, "//input[@class='MuiCheckbox-input css-1jj0cvj']") # self.first_row_ID_content = first_row.find_element(By.XPATH, # "//span[@class='idWidth cursorDefault mouseSchedule el-popover__reference']/span").text.strip() @@ -374,9 +369,9 @@ class ResponsePages: :return: """ # 点击勾选第一行选择框 - self.first_row_checkBox_element.click() # 变量来自查询函数 + self.first_row_checkbox_element.click() # 变量来自查询函数 # 调用profiles的功能删除方法 - self.profiles_po.delete(listPage_manipulation_delete_button_posId, + self.profiles_po.delete(listpage_manipulation_delete_button_posxpath, listPage_dialogTips_manipulation_button_yes_posCss, listPage_dialogTips_manipulation_button_no_posCss) @@ -388,30 +383,25 @@ class ResponsePages: """ self._goto_subProfilePage() first_row, map_header_className = \ - self.profiles_po.query(listPage_profileSearch_responsePages_selectLabel_posId, - listPage_profileSearch_responsePages_dropDown_item_posXpath, - listPage_profileSearch_responsePages_input_itemContent_posXpath, - listPage_profileSearch_responsePages_buttonSearch_posId, - listPage_profilTable_responsePages_tableTbody_posXpath, - listPage_profilTable_responsePages_tableHeader_posXpath, **kwargs) - first_row_checkBox_element = first_row.find_element(By.XPATH, "//span[@class='el-checkbox__input']") - first_row_referenceCount_class = map_header_className["Reference Count"] - print("first_row_referenceCount_class=", first_row_referenceCount_class) + self.profiles_po.query(listpage_profile_search_response_pages_select_label_posxpath, listpage_profile_search_response_pages_drop_down_item_posxpath, + listpage_profile_search_response_pages_input_item_content_posxpath, listpage_profile_search_response_pages_button_search_posxpath, + listpage_profile_table_response_pages_table_tbody_posxpath, listpage_profile_table_response_pages_table_header_posxpath, **kwargs) + first_row_checkBox_element = first_row.find_element(By.XPATH, "//input[@class='MuiCheckbox-input css-1jj0cvj']") + # first_row_referenceCount_class = map_header_className["Reference Count"] + # print("first_row_referenceCount_class=", first_row_referenceCount_class) first_row_checkBox_element.click() - if first_row.find_element(By.XPATH, f"//td[contains(@class, '{first_row_referenceCount_class}')]/div").get_attribute("value") != "0": + if self.driver.find_element(By.XPATH, "//div[@data-field='referenced_by' and @data-colindex=4]//button").text.strip() != "0": print("数据被引用") # 校验该条数据是否可删除 - text_del = self.driver.find_element(By.ID, - listPage_profile_responsePages_delButton_posId).get_attribute("class") + text_del = self.driver.find_element(By.XPATH, + listpage_profile_response_pages_del_button_posxpath).get_attribute("class") print("text_del=", text_del) - disabled_class = text_del.split(" ")[-1].strip() - print("disabled_class=", disabled_class) - pytest_check.equal(disabled_class, "is-disabled", msg="所在行数{}".format(inspect.currentframe().f_lineno)) + pytest_check.is_in("Mui-disabled", text_del, msg="所在行数{}".format(inspect.currentframe().f_lineno)) # 校验是否弹出侧滑框 - first_row.find_element(By.ID, "ReferenceData-_Profile_ResponsePages_Home_App_anonymousComponent").click() - pytest_check.equal(self.driver.element_isExist(By.XPATH, "//div[@class='LocalationDraswer lstsub policy-right-show-edit']"), True, + first_row.find_element(By.XPATH, "//div[@data-field='referenced_by' and @data-colindex=6]//button").click() + pytest_check.equal(self.driver.element_isExist(By.XPATH, "//div[@class='MuiDrawer-content css-10lcz44']"), True, msg="所在行数{}".format(inspect.currentframe().f_lineno)) - self.driver.find_element(By.XPATH, "//div[@class='box-content']/div/div[1]").click() + self.driver.find_element(By.XPATH, "//tbody[@class='MuiTableBody-root css-1xnox0e']").click() @screenshot_on_failure def listPageBottom_allSelect(self): @@ -505,25 +495,27 @@ class ResponsePages: :param link_list_dict: :return: """ + tmp_name = self._create(data) + time.sleep(3) + search_dict = self._query(data, require_assertion=0, Name=tmp_name) + # 勾选第一行 + self.first_row_checkbox_element.click() + # 调用公共的link创建逻辑 + Des_ID_list, Request_ID, Sou_ID_list = self.profiles_po.linkdata(link_list_dict, + listpage_profile_response_pages_link_button_posxpath, + listPage_linkTips_responsePages_button_save_posXpath, + listPage_linkTips_responsePages_button_add_posXpath, + listPage_linkTips_responsePages_button_OK_posXpath) try: - tmp_name = self._create(data) - time.sleep(3) - search_dict = self._query(data, require_assertion=0, Name=tmp_name) - # 勾选第一行 - self.first_row_checkBox_element.click() - # 调用公共的link创建逻辑 - Des_ID_list, Request_ID, Sou_ID_list = self.profiles_po.linkdata(link_list_dict, - listPage_profile_responsePages_linkButton_posId, - listPage_linkTips_responsePages_button_save_posXpath, - listPage_linkTips_responsePages_button_add_posXpath, - listPage_linkTips_responsePages_button_OK_posXpath) # judge link success chk_lnk_name = [] - self._query(data, require_assertion=1, ID=search_dict["ID"]) + self._query(data, require_assertion=1, UUID=search_dict["ID"]) sou_value_name = self.driver.find_element(By.XPATH, - '//div[@class="cell"]//span[contains(@class, "el-tooltip white-space")]').text + '//div[@class="MuiDataGrid-virtualScrollerRenderZone css-1inm7gi"]//div[@data-field="name" and @data-colindex=2]').text self.driver.find_element(By.XPATH, - '//div[@class="cell"]//i[contains(@id, "dowmload")]').click() + '//div[@class="MuiDataGrid-virtualScrollerRenderZone css-1inm7gi"]//div[@data-field="file_path" and @data-colindex="3"]').click() + is_exist = self.driver.element_isExist(By.XPATH, "//div[contains(@class, 'el-message--error')]/p") + pytest_check.equal(is_exist,False, msg="所在行数{}".format(inspect.currentframe().f_lineno)) chk_lnk_name.append(sou_value_name) # 切换到目的源 loginout = LogInOut(self.driver) @@ -538,24 +530,28 @@ class ResponsePages: self._query(data, vsys_name_2=link_list_dict[link_index]["link_dst_vsys"], require_assertion=0, ID=Des_ID_list[0]) time.sleep(2) - self.driver.find_element(By.XPATH, "//i[contains(@id, 'dowmloadi')]").click() + self.driver.find_element(By.XPATH, '//div[@class="MuiDataGrid-virtualScrollerRenderZone css-1inm7gi"]//div[@data-field="file_path" and @data-colindex="3"]').click() + is_exist = self.driver.element_isExist(By.XPATH, "//div[contains(@class, 'el-message--error')]/p") + pytest_check.equal(is_exist, False, msg="所在行数{}".format(inspect.currentframe().f_lineno)) # 获取sync后的值 des_value_Name = self.driver.find_element(By.XPATH, - '//div[@class="cell"]//span[contains(@class, "el-tooltip white-space")]').text + '//div[@class="MuiDataGrid-virtualScrollerRenderZone css-1inm7gi"]//div[@data-field="name" and @data-colindex=2]').text chk_lnk_name.append(des_value_Name) self.profiles_po.lst_are_same(chk_lnk_name) # 切换到源 self.profiles_po.change_sou_vsys() # update data - self._query(data, require_assertion=1, ID=search_dict["ID"]) + self._query(data, require_assertion=1, UUID=search_dict["ID"]) self._modify(data) - self._query(data, require_assertion=2, ID=search_dict["ID"]) + self._query(data, require_assertion=2, UUID=search_dict["ID"]) # save data sou_value_name = self.driver.find_element(By.XPATH, - '//div[@class="cell"]//span[contains(@class, "el-tooltip white-space")]').text + '//div[@class="MuiDataGrid-virtualScrollerRenderZone css-1inm7gi"]//div[@data-field="name" and @data-colindex=2]').text self.driver.find_element(By.XPATH, - '//div[@class="cell"]//i[contains(@id, "dowmload")]').click() + '//div[@class="MuiDataGrid-virtualScrollerRenderZone css-1inm7gi"]//div[@data-field="file_path" and @data-colindex="3"]').click() + is_exist = self.driver.element_isExist(By.XPATH, "//div[contains(@class, 'el-message--error')]/p") + pytest_check.equal(is_exist, False, msg="所在行数{}".format(inspect.currentframe().f_lineno)) time.sleep(1) # click sync Request_ID = self.profiles_po.click_pol_lnk_sync(Request_ID) @@ -569,7 +565,8 @@ class ResponsePages: print(compare_list_name) self.profiles_po.lst_are_same(compare_list_name) except Exception as e: - assert e + print("Exception ============", e) + raise e finally: self._just_goto_response_page() self._delete_des(Des_ID_list, data) # 删除数据 @@ -595,6 +592,9 @@ class ResponsePages: self._query(data, vsys_name_2=link_list_dict[link_index]["link_dst_vsys"], require_assertion=0, ID=Des_ID_list[0]) time.sleep(2) self.driver.find_element(By.XPATH, "//i[contains(@id, 'dowmloadi')]").click() + self.driver.find_element(By.XPATH, "//i[contains(@id, 'dowmloadi')]").click() + is_exist = self.driver.element_isExist(By.XPATH, "//div[contains(@class, 'el-message--error')]/p") + pytest_check.equal(is_exist, False, msg="所在行数{}".format(inspect.currentframe().f_lineno)) # 获取sync后的值 des_value_Name = self.driver.find_element(By.XPATH, '//div[@class="cell"]//span[contains(@class, "el-tooltip white-space")]').text @@ -619,8 +619,12 @@ class ResponsePages: time.sleep(2) # 再次获取sync后的值 self.driver.find_element(By.XPATH, f"//i[contains(@id, 'dowmloadi')]").click() + self.driver.find_element(By.XPATH, "//i[contains(@id, 'dowmloadi')]").click() + is_exist = self.driver.element_isExist(By.XPATH, "//div[contains(@class, 'el-message--error')]/p") + pytest_check.equal(is_exist, False, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + second_des_value_name = self.driver.find_element(By.XPATH, - '//div[@class="cell"]//span[contains(@class, "el-tooltip white-space")]').text + '//div[@class="cell"]//span[contains(@class, "el-tooltip white-space")]').text compare_list_name.append(second_des_value_name) return Request_ID, compare_list_name @@ -642,13 +646,13 @@ class ResponsePages: self.driver.find_element(By.XPATH, "//li[starts-with(@id, '1-_FilteredSearch_ElRow_Profile')]//span[normalize-space(text())='ID']").click() self.driver.find_element(By.XPATH, '//input[contains(@placeholder, "Support")]').send_keys(Des_ID_list[0]) - self.driver.find_element(By.ID, mainPage_profileSearch_buttonSearch_posId).click() + self.driver.find_element(By.ID, mainpage_profile_search_button_search_posxpath).click() time.sleep(1) self.driver.find_element(By.XPATH, "//div[@class='el-checkbox-group']//span[@class='el-checkbox__input']/span[@class='el-checkbox__inner']").click() # 确认删除 self.driver.find_element(By.XPATH, "//p[normalize-space(text())='Delete']").click() - self.driver.find_element(By.CSS_SELECTOR, listPage_dialogTips_responsePages_button_yes_posCss).click() + # self.driver.find_element(By.CSS_SELECTOR, listPage_dialogTips_responsePages_button_yes_posCss).click() def _delete_source(self, Sou_ID_list, data): @@ -709,16 +713,152 @@ class ResponsePages: def _audit_log_all_operation(self, data): ran_name = self._create(data) try: - time.sleep(0.5) - search_dict = self._query(data, Name=ran_name) + profiles_type = "Response Page" + self._query(data, Name=ran_name) + self._audit_log_operation(profiles_type, operation_type='Create') + self._goto_subProfilePage() + self._query(data, Name=ran_name) + self._audit_log_operation(profiles_type, operation_type='Query Verbose') + self._goto_subProfilePage() + self._query(data, Name=ran_name) self._modify(data) - time.sleep(0.5) + self._query(data, Name=ran_name) + self._audit_log_operation(profiles_type, operation_type='Edit') + self._goto_subProfilePage() + self.profiles_po._audit_log_query_list(profiles_type, operation_type='Query List') + except Exception as e: + raise e + finally: + self._query(data, Name=ran_name) + self._del() + self.profiles_po._audit_log_delete(profiles_type, operation_type='Delete') + + + def _audit_log_operation(self, profiles_type, operation_type): + # 选中第一行 + self.first_row_checkbox_element.click() + # 点击编辑 + self.driver.find_element(By.XPATH, listpage_profile_response_pages_edit_button_posxpath).click() + if operation_type == 'Query Verbose': + click_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + if operation_type == 'Create': + # 创建时间 + compare_time = self.driver.find_element(By.XPATH, response_page_profile_page_create_time_posxpath).text + elif operation_type == 'Edit': + # 修改时间 + compare_time = self.driver.find_element(By.XPATH, response_page_profile_page_modify_time_posxpath).text + # 用户 + user_name = self.driver.find_element(By.XPATH, + "//div[normalize-space(text())='Last Modified By']/following-sibling::div").text + search_id = self.driver.find_element(By.XPATH, + "//div[normalize-space(text())='UUID']/following-sibling::div").text + + if operation_type == 'Query Verbose': + self.profiles_po.search_compare_item(profiles_type, search_id, operation_type=operation_type, + operation_flag=0) + else: + # 对比 Audit log 详情页 + # self.driver.find_element(By.XPATH, response_page_profile_page_audit_logs_posxpath).click() + # self.driver.find_element(By.XPATH, "(//span[@class='el-checkbox__inner'])[2]").click() + # # 点击 Compare + # self.driver.find_element(By.XPATH, response_page_profile_page_audit_logs_compare_posxpath).click() + # + # if operation_type == 'Create': + # self.profiles_po._check_audit_log_detail_page(profiles_type, user_name, search_name, compare_time, operation_flag=0) + # elif operation_type == 'Edit': + # self.profiles_po._check_audit_log_detail_page(profiles_type, user_name, search_name, compare_time, operation_flag=1) + # 对比系统 audit_log 页 + self.profiles_po.search_compare_item(profiles_type, search_id, operation_type=operation_type, + operation_flag=0) + time.sleep(1) + + if operation_type == 'Create': + # 点击 Compare 对比 + self.driver.find_element(By.XPATH, + "//button[normalize-space(text())='Compare']").click() + # 点击 V.1 + self.driver.find_element(By.XPATH, "//input[@class='PrivateSwitchBase-input css-1m9pwf3']") + self.driver.find_element(By.XPATH, list_page_audit_log_search_button_compare_posxpath).click() + + self.profiles_po._check_audit_log_detail_page(profiles_type, user_name, search_id, compare_time, operation_flag=0) + elif operation_type == 'Edit': + # 点击 Compare 对比 + self.driver.find_element(By.XPATH, + "//button[normalize-space(text())='Compare']").click() + # 对比 V.1 + self.driver.find_element(By.XPATH, "(//input[@class='PrivateSwitchBase-input css-1m9pwf3'])[last()]").click() + # 对比 V.2 + self.driver.find_element(By.XPATH, + "(//input[@class='PrivateSwitchBase-input css-1m9pwf3'])[1]").click() + + self.driver.find_element(By.XPATH, list_page_audit_log_search_button_compare_posxpath).click() + self.profiles_po._check_audit_log_system_page(profiles_type, user_name, search_id, compare_time, operation_flag=1) + elif operation_type == 'Query Verbose': + # 点击 Compare 对比 + time.sleep(1) + self.driver.find_element(By.XPATH, + "(//button[normalize-space(text())='View'])[1]").click() + self.profiles_po._check_audit_log_detail_page(profiles_type, user_name, search_id, click_time, operation_flag=2) + + + def _all_search_fields(self, data): + # 新建数据 + ran_name = self._create(data) + # 名字查询 + search_dict = self._query(data, Name=ran_name) + try: + # ID 唯一查询 + self._query(data, ID=search_dict['ID']) + # 只有一行记录并且ID一致 + id_eles = self.driver.find_elements(By.XPATH, "//div[@class='table-status-item-id']") + id_ele_lst = [e.text for e in id_eles] + pytest_check.equal(len(id_ele_lst), 1, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + for id_ele in id_ele_lst: + pytest_check.equal(id_ele, search_dict['ID'], msg="所在行数{}".format(inspect.currentframe().f_lineno)) + + # 名字模糊查询 + search_name = 'uitemp' + self._query(data, Name=search_name) + # 可以有多行记录都需要包含在名字里面 + name_eles = self.driver.find_elements(By.XPATH, "//td[contains(@class,'el-table_1_column_2 is-left')]") + name_ele_lst = [e.text for e in name_eles] + for name_ele in name_ele_lst: + pytest_check.equal(search_name in name_ele, True, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + # ID + Name组合查询 + self.driver.find_element(By.ID, listPage_profileSearch_dnsRecords_dropDown_search_clear_posId).click() + # ID + self.driver.find_element(By.ID, mainPage_profileSearch_selectLabel_posId).click() + self.driver.find_element(By.ID, listPage_profileSearch_responsePages_dropDown_id_posId).click() + self.driver.find_element(By.XPATH, listPage_profileSearch_responsePages_dropDown_id_text_posId).send_keys( + search_dict['ID'] + Keys.ENTER) + # Name + self.driver.find_element(By.ID, listPage_profileSearch_responsePages_dropDown_id_posId).click() + self.driver.find_element(By.XPATH, listPage_profileSearch_responsePages_dropDown_name_text_posId).send_keys( + search_name + Keys.ENTER) + # 点击查询 + self.driver.find_element(By.ID, mainPage_profileSearch_buttonSearch_posId).click() + + # 只有一行记录并且ID一致 + id_eles = self.driver.find_elements(By.XPATH, "//div[@class='table-status-item-id']") + id_ele_lst = [e.text for e in id_eles] + pytest_check.equal(len(id_ele_lst), 1, msg="所在行数{}".format(inspect.currentframe().f_lineno)) + for id_ele in id_ele_lst: + pytest_check.equal(id_ele, search_dict['ID'], msg="所在行数{}".format(inspect.currentframe().f_lineno)) + + # 可以有多行记录都需要包含在名字里面 + name_eles = self.driver.find_elements(By.XPATH, "//td[contains(@class,'el-table_1_column_2 is-left')]") + name_ele_lst = [e.text for e in name_eles] + for name_ele in name_ele_lst: + pytest_check.equal(search_name in name_ele, True, + msg="所在行数{}".format(inspect.currentframe().f_lineno)) + except Exception as e: + print("Exception ============", e) raise e finally: + # 删除数据 self._query(data, Name=ran_name) self._del() - self.profiles_po.audit_log_view("Response Page", search_dict["ID"]) create = _create query = _query @@ -731,7 +871,6 @@ class ResponsePages: goto_subProfilePage = _goto_subProfilePage vsys_case = _vsys_case vsys_check = _vsys_check - audit_log = _audit_log policy_create = _policy_create policy_query = _policy_query policy_delete = _policy_del @@ -745,9 +884,9 @@ if __name__ == '__main__': ) a.get("http://192.168.44.72") a.maximize_window() - a.find_element(By.XPATH,"//*[@id='app']/div/div[1]/div[2]/div[2]/div[1]/div/input").send_keys("AUTO_UI_TEST_KG") - a.find_element(By.XPATH,"//*[@id='app']/div/div[1]/div[2]/div[2]/div[2]/div/input").send_keys("kongweibin1") - a.find_element(By.ID,"login").click() + a.find_element(By.XPATH , loginpage_username_posxpath).send_keys("AUTO_UI_TEST_KG") + a.find_element(By.XPATH, loginpage_passwd_posxpath).send_keys("kongweibin1") + a.find_element(By.XPATH,login_page_sign_in_posxpath).click() time.sleep(2) # 测试修改数据 r = ResponsePages(a) @@ -756,27 +895,26 @@ if __name__ == '__main__': # model=0/1 ====0:单个 1group # type =IMSI/Phone_Number/IMEI data= { - "ids": "创建respose_page文件再修改", - "model": "modify", - "file": "testa.html->testb.html", - "modify_des_name": "tst_response_files_kg" + "ids": "创建respose_page文件20M大小", + "model": "create", + "file": "20MFile.html->" } # 测试link - link_parse = configparser.ConfigParser() - link_parse_dir = os.path.join(workdir, "config", "linkcluster.ini") - link_parse.read(link_parse_dir, encoding="utf-8") - link_list_dict = [] - link_list = [1] # 可取值 1、2、 3、4、5 #这些取值来自linkcluster.ini配置文件 - for i in link_list: - tmp_dict = {} - link_index = "link_{}".format(i) - tmp_dict["link_dst_cluster"] = link_parse.get(link_index, "link_dst_cluster") - tmp_dict["link_dst_vsys"] = link_parse.get(link_index, "link_dst_vsys") - tmp_dict["url"] = link_parse.get(link_index, "url") - tmp_dict["username"] = link_parse.get(link_index, "username") - tmp_dict["passwd"] = link_parse.get(link_index, "passwd") - link_list_dict.append(copy.deepcopy(tmp_dict)) - print(link_list_dict) + # link_parse = configparser.ConfigParser() + # link_parse_dir = os.path.join(workdir, "config", "linkcluster.ini") + # link_parse.read(link_parse_dir, encoding="utf-8") + # link_list_dict = [] + # link_list = [1] # 可取值 1、2、 3、4、5 #这些取值来自linkcluster.ini配置文件 + # for i in link_list: + # tmp_dict = {} + # link_index = "link_{}".format(i) + # tmp_dict["link_dst_cluster"] = link_parse.get(link_index, "link_dst_cluster") + # tmp_dict["link_dst_vsys"] = link_parse.get(link_index, "link_dst_vsys") + # tmp_dict["url"] = link_parse.get(link_index, "url") + # tmp_dict["username"] = link_parse.get(link_index, "username") + # tmp_dict["passwd"] = link_parse.get(link_index, "passwd") + # link_list_dict.append(copy.deepcopy(tmp_dict)) + # print(link_list_dict) """ 传参查考 link_list_dict = [ { @@ -788,4 +926,4 @@ if __name__ == '__main__': }, ] """ - r.chk_lnk_mod_case(data, link_list_dict=link_list_dict)
\ No newline at end of file + r.response_page_case(data)
\ No newline at end of file |
