import configparser import datetime import os import inspect import socket import pytest_check from selenium.common.exceptions import StaleElementReferenceException from selenium.webdriver import ActionChains from selenium.webdriver.remote.webelement import WebElement from common.driver_common.random_name import RandomName import pytest from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By import random import time from common.ui_common.login_logout import loginout from common.driver_common.mywebdriver import MyWebDriver from common.driver_common.screenshot import screenshot_on_failure from common.read_data.read_data import ReadData from common.ui_common.profiles.profiles_public_operations import ProfilesPublicOperations from config.workpath import workdir from page_element.admin_area_element_position import * from page_element.objects_element_position import * from page_element import objects_element_position from selenium import webdriver # from cases.conftest import demo_fixture from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from page_element.ln_objects_element_position import * from page_element.policies_element_position import * import shutil from common.ui_common.login_logout.loginout import LogInOut from page_element.profiles_element_position import mainpage_button_menu_posxpath # 下载文件《不需要实例化类》不写在类方法下 def download_files(): my_files = ReadData() options = webdriver.ChromeOptions() # options.add_argument("--incognito") # 添加启用无痕模式的选项 options.add_argument("--window-size=1920,1080") # 启动时默认大小窗口 # options.add_argument('--headless') # 启用Headless模式 options.add_argument('--disable-gpu') # 禁用 GPU 硬件加速 prefs = {'download.default_directory': my_files._obj_files_dowload_path()} options.add_experimental_option('prefs', prefs) loginout_parse = configparser.ConfigParser() loginout_parse_dir = os.path.join(workdir, "config", "loginout.ini") loginout_parse.read(loginout_parse_dir, encoding="utf-8") driver = MyWebDriver( command_executor=loginout_parse.get("remote_url", "url"), options=options) tsglogin_url = loginout_parse.get("tsg_url", "login_url") driver.get(tsglogin_url) driver.maximize_window() # Login # 需要判断,遇到https不安全时,点击高级-继续登录才可以访问https-tsg if "https" in tsglogin_url: print(2) driver.isElementExist("//*[@id='details-button']") if driver.Exist: print(3) if "高级" in driver.find_element(By.XPATH, "//*[@id='details-button']").text.strip(): print(4) driver.find_element(By.XPATH, "//*[@id='details-button']").click() driver.find_element(By.XPATH, "//*[@id='proceed-link']").click() # 输入账户和密码 driver.find_element(By.XPATH, '//input[@placeholder="User name"]').send_keys(loginout_parse.get("ui_account_1", "username")) driver.find_element(By.XPATH, '//input[@placeholder="Password"]').send_keys(loginout_parse.get("ui_account_1", "passwd")) driver.find_element(By.XPATH, '//*[@id=":r0:"]').click() myloginout = LogInOut # 消除右上角弹框 close_button_elem_Xpath = '(//i[@class="iconfont icon-Delete_X"])[last()]' # 全局右上提示窗关闭按钮(最新的一个) driver.isElementExist(close_button_elem_Xpath) loop_count = 2 while loop_count > 0: try: driver.isElementExist(close_button_elem_Xpath) if driver.Exist: driver.find_element(By.XPATH, close_button_elem_Xpath).click() loop_count -= 1 except: loop_count -= 1 pass # 切换至默认ui_vsys # loginout_parse = configparser.ConfigParser() # loginout_parse_dir = os.path.join(workdir, "config", "loginout.ini") # loginout_parse.read(loginout_parse_dir, encoding="utf-8") # # 切换UI自动化使用vsys # vsys_name = loginout_parse.get("vsys", "vsys_name") # 登录后vsys切换为UIAutoTestVsys # # print(vsys_name) # profile_pub = ProfilesPublicOperations(driver) # profile_pub.change_vsys(vsys_name=vsys_name) # 默认更改为英语 # myloginout._default_language() return driver def _vsys_account(): options = webdriver.ChromeOptions() loginout_parse = configparser.ConfigParser() loginout_parse_dir = os.path.join(workdir, "config", "loginout.ini") loginout_parse.read(loginout_parse_dir, encoding="utf-8") driver = MyWebDriver( command_executor=loginout_parse.get("remote_url", "url"), options=options) tsglogin_url = loginout_parse.get("tsg_url", "login_url") driver.get(tsglogin_url) driver.maximize_window() driver.find_element(By.XPATH, "//div[1]/div/div[1]/div[2]/div[2]/div/input").send_keys( loginout_parse.get("ui_vsys_Case_1", "username")) driver.find_element(By.XPATH, "//div/div[1]/div[2]/div[3]/div/input").send_keys( loginout_parse.get("ui_vsys_Case_1", "passwd")) driver.find_element(By.ID, "login").click() login = LogInOut(driver) login.dismiss_right_top_tips() return driver def get_txt_filenames(path): # 《不需要实例化类》不写在类方法下 filenames = [] for filename in os.listdir(path): if filename.endswith('.txt'): filenames.append(filename) return str(filenames[0]) def get_lua_filenames(path): # 《不需要实例化类》不写在类方法下 filenames = [] for filename in os.listdir(path): if filename.split('.lua'): filenames.append(filename) return str(filenames[0]) class ObjectsPublicOperations: def __init__(self, demo_fixture): self.driver = demo_fixture self.my_files = ReadData() self.my_random = RandomName() self.loginout_parse = configparser.ConfigParser() self._query = 1 loginout_parse_dir = os.path.join(workdir, "config", "loginout.ini") self.loginout_parse.read(loginout_parse_dir, encoding="utf-8") self.vsys_name = self.loginout_parse.get("vsys", "vsys_name") # 登录后vsys切换为UIAutoTestVsys self.profile_pub = ProfilesPublicOperations(self.driver) self.wait = WebDriverWait(self.driver, 5) # 最多等待5秒 self.instances = {} ##geolocation、http_signatures、moible_identities、subscriber_ids等文件下的类名需更改 self.obj_class_dict = { "accounts": "Accounts", "apns": "APNs", "asns": "ASNs", "categories": "Categories", "flags": "Flags", "intervals": "Intervals", "tunnels": "Tunnels", "urls": "URLs", "app_attributes": "Attributes", "app_signatures": "Signature", "application_groups": "AppGroup", "applications": "App", "fqdns": "FQDNs", "geolocation": "Geolocation", "http_signatures": "HTTP_Signatures", "ip_address": "IPAddress", "keywords": "Keywords", "moible_identities": "MobileIdentiities", "ports": "Ports", "subscriber_ids": "BaseSubscriberIDs" } def get_instance(self, obj_type): """ 检查 instances 字典中是否已经存在对应 obj_type 的实例。如果不存在,则导入模块、获取类并实例化,然后将实例存储在 instances 字典中。 :param obj_type: :return: """ if obj_type not in self.instances: import importlib class_name = self.obj_class_dict[obj_type] module_name = f'common.ui_common.objects.{obj_type}' module = importlib.import_module(module_name) class_obj = getattr(module, class_name) instance = class_obj(self.driver) self.instance = instance self.instances[obj_type] = instance return self.instances[obj_type] def object_operation(self, obj_type, obj_action, data): """ 根据obj_type和obj_action执行对应方法 :param obj_type: 对象类型 eg:accounts :param obj_action:对象动作 eg:create/query/delete :param data:执行上述动作所需要的data :return: """ instance = self.get_instance(obj_type) # 动态调用方法 method = getattr(instance, obj_action) method(data) # 修改内容时,当内容为value,不是text时使用 def clear_Name(self, path): """ 清除输入框内容 :param path: path 也可是Selenium元素 XD :return: """ # print("goTo_input {}".format(pathOrElement), type(pathOrElement)) if isinstance(path, WebElement): # 变量是WebElement类型 element = path else: # path element = self.driver.find_element(By.XPATH, path) # element.send_keys(Keys.CONTROL + 'a') element.send_keys(Keys.CONTROL + 'A') element.send_keys(Keys.DELETE) def assert_len_Name(self, data): j = 0 for i in data["Name"]: j += 1 return j def clear_name_by_id(self, xpath): element = self.driver.find_element(By.XPATH, xpath) element.send_keys(Keys.CONTROL + 'a') element.send_keys(Keys.DELETE) # 提取ID、Name、Description、Detail def extract_ele(self, need_exclude=1): """ :param need_exclude: 是否需要获取exclude,默认1则获取,不为1则略过 :return: """ # self.driver.isElementExist(Element='//div/div[3]/table/tbody/tr[1]') # 查看第一行是否存在数据 self.driver.isElementExist( Element='//div[@aria-rowindex="2"]') # 查看第一行是否存在数据 if self.driver.Exist: # 展示所有列 column_setting_btn = self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath) # 列设置按钮 self.driver.execute_script("arguments[0].scrollIntoView();", column_setting_btn) column_setting_btn.click() # 点击列设置 self.driver.find_element(By.XPATH, '//span[text()="Vsys ID"]').click() self.driver.find_element(By.XPATH, '//span[text()="UUID" and contains(@class,"MuiTypography-body1")]').click() # self.driver.find_element(By.XPATH, "//input[@name='Show/Hide All']").click() # self.driver.find_element(By.XPATH, "//input[@name='Show/Hide All']").click() self.driver.find_element(By.XPATH, '//div[text()="Name"]').click() # all_checked_xpath = '//*[@class="all-btn"]//*[@class="el-checkbox__input is-checked"]' # if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_click_Cancel_Button_posXpath).click() # 点击Cancel按钮 # else: # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # 全选 # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按钮 # 公共方法 Detail特殊,需要使用时特殊提取 # list_headers_template = '//div[@class="el-table__header-wrapper"]//span[text()="{}"]' # list_firstRow_values_template = '//div[contains(@class,"el-table__body-wrapper")]//tr[1]//td[count({a}/../../../preceding-sibling::th)+1]{b}' # # list_headers_id_posXpath = list_headers_template.format("ID") # list_headers_vsys_id_posXpath = list_headers_template.format("Vsys ID") # list_headers_name_posXpath = list_headers_template.format("Name") # # list_headers_description_posXpath = list_headers_template.format("Description") # list_headers_refer_count_posXpath = list_headers_template.format("Reference Count") # # list_firstRow_values_id_posXpath = list_firstRow_values_template.format(a=list_headers_id_posXpath, # b='//div[@class="table-status-item-id"]//span') # list_firstRow_values_vsys_id_posXpath = list_firstRow_values_template.format( # a=list_headers_vsys_id_posXpath, b='//*[text()]') # list_firstRow_values_name_posXpath = list_firstRow_values_template.format(a=list_headers_name_posXpath, # b='//span') # # list_firstRow_values_description_posXpath = list_firstRow_values_template.format( # a=list_headers_description_posXpath, b='//span') + "|" + list_firstRow_values_template.format( # a=list_headers_description_posXpath, b='//p') # list_firstRow_values_refer_count_posXpath = list_firstRow_values_template.format( # a=list_headers_refer_count_posXpath, b='//div[contains(@class,"textCenter")]') # self.key_id = self.driver.find_element(By.XPATH, list_headers_id_posXpath).text # self.value_id = self.driver.find_element(By.XPATH, list_firstRow_values_id_posXpath).text self.uuid_name = self.driver.find_element(By.XPATH, '//div[text()="UUID"]').text self.uuid_value = self.driver.find_element(By.XPATH,'//div[@aria-rowindex="2"]//div[@data-field="uuid"]').text self.key_vsys_id = self.driver.find_element(By.XPATH, '//div[text()="Vsys ID"]').text self.value_vsys_id = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="vsys"]').text self.key_name = self.driver.find_element(By.XPATH, '//div[text()="Name"]').text self.value_name = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//span[@class="truncate"]').text self.key_des = self.driver.find_element(By.XPATH, '//div[text()="Description"]').text self.value_des = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="description"]').text # self.key_refer_count = self.driver.find_element(By.XPATH, '//div[@class="MuiDataGrid-columnHeaderTitle css-mh3zap" and text()="Usage"]').text # self.value_refer_count = self.driver.find_element(By.XPATH, list_firstRow_values_refer_count_posXpath).text if need_exclude == 1: # list_headers_exclude_posXpath = list_headers_template.format("Exclude Members") # list_firstRow_values_exclude_posXpath = list_firstRow_values_template.format( # a=list_headers_exclude_posXpath, # b='//div[@class="bifangWidth"]|div[@class="three-row list-popover-click"]') self.key_exclude = self.driver.find_element(By.XPATH, '//div[text()="Exclude Members"]').text self.value_exclude = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="exclude_sub_object_list"]').text self.table_dict = {self.key_vsys_id: self.value_vsys_id,self.uuid_name:self.uuid_value,self.key_name: self.value_name, self.key_exclude: self.value_exclude, self.key_des: self.value_des,"Details": "null"} else: self.table_dict = {self.uuid_name:self.uuid_value,self.key_vsys_id: self.value_vsys_id,self.key_name: self.value_name, self.key_des: self.value_des, "Details": "null"} # print("extract_ele TEST:{}".format(self.table_dict)) return self.table_dict # try: # self.driver.isElementExist(Element=list_second_row_sixth_column_posXpath) # if self.driver.Exist: # self.value26 = self.driver.find_element(By.XPATH, list_second_row_sixth_column_posXpath).text # else: # self.driver.isElementExist(Element='//table/tbody/tr[1]/td[6]/div/span') # if self.driver.Exist: # self.value26 = self.driver.find_element(By.XPATH, '//table/tbody/tr[1]/td[6]/div/span').text # else: # self.value26 = "null" # except: # pass # self.table_dict = {self.key11: self.value12, self.key12: self.value22, self.key13: self.value23, # "Datails": "null", self.key15: self.value25, self.key16: self.value26} # else: # assert self.driver.Exist # def extract_ele(self): # # self.driver.isElementExist(Element='//div/div[3]/table/tbody/tr[1]') # 查看第一行是否存在数据 # self.driver.isElementExist(Element='((//div[@class!="itemDetails cursor"]//table[@class="el-table__body"])[1]//tr)[1]') # 查看第一行是否存在数据 # if self.driver.Exist: # # 公共方法 Detail特殊,需要使用时特殊提取 # # ID # self.key11 = self.driver.find_element(By.XPATH, list_first_row_first_column_posXpath).text # self.value12 = self.driver.find_element(By.XPATH, list_second_row_first_column_posXpath).text # # Vsy_ID # self.key12 = self.driver.find_element(By.XPATH, list_first_row_second_column_posXpath).text # self.value22 = self.driver.find_element(By.XPATH, list_second_row_second_column_posXpath).text # # Name # self.key13 = self.driver.find_element(By.XPATH, list_first_row_third_column_posXpath).text # self.value23 = self.driver.find_element(By.XPATH, list_second_row_third_column_posXpath).text # # Exclude Members # self.key15 = self.driver.find_element(By.XPATH, list_first_row_fifth_column_posXpath).text # self.value25 = self.driver.find_element(By.XPATH, list_second_row_fifth_column_posXpath).text # # Description # self.key16 = self.driver.find_element(By.XPATH, list_first_row_sixth_column_posXpath).text # try: # self.driver.isElementExist(Element=list_second_row_sixth_column_posXpath) # if self.driver.Exist: # self.value26 = self.driver.find_element(By.XPATH, list_second_row_sixth_column_posXpath).text # else: # self.driver.isElementExist(Element='//table/tbody/tr[1]/td[6]/div/span') # if self.driver.Exist: # self.value26 = self.driver.find_element(By.XPATH, '//table/tbody/tr[1]/td[6]/div/span').text # else: # self.value26 = "null" # except: # pass # self.table_dict = {self.key11: self.value12, self.key12: self.value22, self.key13: self.value23, # "Datails": "null", self.key15: self.value25, self.key16: self.value26} # else: # assert self.driver.Exist # print(self.table_dict) # if data["Createmodel"] == "0" and data["Createtype"] != "IP_Learnig": # self.Details = self.driver.find_element(By.XPATH,listPage_object_mobileIdentities_new_Details_extract_posXpath).text # self.ID = self.driver.find_element(By.XPATH,listPage_object_mobileIdentities_new_ID_extract_posXpath).text # self.Name = self.driver.find_element(By.XPATH,listPage_object_mobileIdentities_new_Name_extract_posXpath).text # self.Description = self.driver.find_element(By.XPATH,listPage_object_mobileIdentities_new_Description_extract_posXpath).text def extract_ele_flag(self, need_exclude=1): """ :param need_exclude: 是否需要获取exclude,默认1则获取,不为1则略过 :return: """ # self.driver.isElementExist(Element='//div/div[3]/table/tbody/tr[1]') # 查看第一行是否存在数据 self.driver.isElementExist( Element='//div[@aria-rowindex="2"]') # 查看第一行是否存在数据 if self.driver.Exist: # 展示所有列 column_setting_btn = self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath) # 列设置按钮 self.driver.execute_script("arguments[0].scrollIntoView();", column_setting_btn) column_setting_btn.click() # 点击列设置 # self.driver.find_element(By.XPATH, '//span[text()="Vsys ID"]').click() self.driver.find_element(By.XPATH, '//span[text()="UUID"]').click() self.driver.find_element(By.XPATH, '//div[text()="Name"]').click() # self.driver.find_element(By.XPATH, '//div[text()="Vsys ID"]').click() # all_checked_xpath = '//*[@class="all-btn"]//*[@class="el-checkbox__input is-checked"]' # if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_click_Cancel_Button_posXpath).click() # 点击Cancel按钮 # else: # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # 全选 # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按钮 # 公共方法 Detail特殊,需要使用时特殊提取 # list_headers_template = '//div[@class="el-table__header-wrapper"]//span[text()="{}"]' # list_firstRow_values_template = '//div[contains(@class,"el-table__body-wrapper")]//tr[1]//td[count({a}/../../../preceding-sibling::th)+1]{b}' # # list_headers_id_posXpath = list_headers_template.format("ID") # list_headers_vsys_id_posXpath = list_headers_template.format("Vsys ID") # list_headers_name_posXpath = list_headers_template.format("Name") # # list_headers_description_posXpath = list_headers_template.format("Description") # list_headers_refer_count_posXpath = list_headers_template.format("Reference Count") # # list_firstRow_values_id_posXpath = list_firstRow_values_template.format(a=list_headers_id_posXpath, # b='//div[@class="table-status-item-id"]//span') # list_firstRow_values_vsys_id_posXpath = list_firstRow_values_template.format( # a=list_headers_vsys_id_posXpath, b='//*[text()]') # list_firstRow_values_name_posXpath = list_firstRow_values_template.format(a=list_headers_name_posXpath, # b='//span') # # list_firstRow_values_description_posXpath = list_firstRow_values_template.format( # a=list_headers_description_posXpath, b='//span') + "|" + list_firstRow_values_template.format( # a=list_headers_description_posXpath, b='//p') # list_firstRow_values_refer_count_posXpath = list_firstRow_values_template.format( # a=list_headers_refer_count_posXpath, b='//div[contains(@class,"textCenter")]') # self.key_id = self.driver.find_element(By.XPATH, list_headers_id_posXpath).text # self.value_id = self.driver.find_element(By.XPATH, list_firstRow_values_id_posXpath).text self.uuid_name = self.driver.find_element(By.XPATH, '//div[text()="UUID"]').text self.uuid_value = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="uuid"]').text self.key_vsys_id = self.driver.find_element(By.XPATH, '//div[text()="Vsys ID"]').text self.value_vsys_id = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="vsys"]').text # self.uuid_name = self.driver.find_element(By.XPATH, '//div[text()="UUID"]').text # self.uuid_value = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="uuid"]').text self.key_name = self.driver.find_element(By.XPATH, '//div[text()="Name"]').text self.value_name = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//span[@class="truncate"]').text self.key_des = self.driver.find_element(By.XPATH, '//div[text()="Description"]').text self.value_des = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="description"]').text # self.key_refer_count = self.driver.find_element(By.XPATH, '//div[@class="MuiDataGrid-columnHeaderTitle css-mh3zap" and text()="Usage"]').text # self.value_refer_count = self.driver.find_element(By.XPATH, list_firstRow_values_refer_count_posXpath).text if need_exclude == 1: # list_headers_exclude_posXpath = list_headers_template.format("Exclude Members") # list_firstRow_values_exclude_posXpath = list_firstRow_values_template.format( # a=list_headers_exclude_posXpath, # b='//div[@class="bifangWidth"]|div[@class="three-row list-popover-click"]') self.key_exclude = self.driver.find_element(By.XPATH, '//div[text()="Exclude Members"]').text self.value_exclude = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="exclude_sub_object_list"]').text self.table_dict = {self.uuid_name:self.uuid_value,self.key_vsys_id: self.value_vsys_id,self.key_name: self.value_name, self.key_exclude: self.value_exclude, self.key_des: self.value_des,"Details": "null"} else: self.table_dict = {self.uuid_name:self.uuid_value,self.key_vsys_id: self.value_vsys_id,self.key_name: self.value_name, self.key_des: self.value_des, "Details": "null"} # print("extract_ele TEST:{}".format(self.table_dict)) return self.table_dict def licenese_Check(self): try: self.driver.isElementExist(Element='//div/div[1]/div[2]/div/div/div[3]/i') if self.driver.Exist: self.driver.find_element(By.XPATH, '//div/div[1]/div[2]/div/div/div[3]/i').click() else: pass except: pass # 修改后元素===》断言 def assert_ele(self): self.driver.isElementExist(Element='//div/div[3]/table/tbody/tr[1]') # 查看第一行是否存在数据 if self.driver.Exist: # ID self.key11 = self.driver.find_element(By.XPATH, list_first_row_first_column_posXpath).text self.value12 = self.driver.find_element(By.XPATH, list_second_row_first_column_posXpath).text # Vsy_ID self.key12 = self.driver.find_element(By.XPATH, list_first_row_second_column_posXpath).text self.value22 = self.driver.find_element(By.XPATH, list_second_row_second_column_posXpath).text # Name self.key13 = self.driver.find_element(By.XPATH, list_first_row_third_column_posXpath).text self.value23 = self.driver.find_element(By.XPATH, list_second_row_third_column_posXpath).text # Details特殊,需要使用时特殊提取 # Exclude Members self.key15 = self.driver.find_element(By.XPATH, list_first_row_fifth_column_posXpath).text self.value25 = self.driver.find_element(By.XPATH, list_second_row_fifth_column_posXpath).text # Description self.key16 = self.driver.find_element(By.XPATH, list_first_row_sixth_column_posXpath).text try: self.driver.isElementExist(Element=list_second_row_sixth_column_posXpath) if self.driver.Exist: self.value26 = self.driver.find_element(By.XPATH, list_second_row_sixth_column_posXpath).text else: self.driver.isElementExist(Element='//table/tbody/tr/td[6]/div//span') if self.driver.Exist: self.value26 = self.driver.find_element(By.XPATH, '//table/tbody/tr/td[6]/div//span').text except: self.value26 = "null" self.edit_table_dict = {self.key11: self.value12, self.key12: self.value22, self.key13: self.value23, "Datails": "null", self.key15: self.value25, self.key16: self.value26} else: assert self.driver.Exist # 根据"->"进行分割,进行修改 def Modify_object(self, data: {}): self.output = data.get("Name") self.Name_list = self.output.split("->") # 判断是否需要修改Name self.create_name = self.Name_list[0] try: self.modify_name = self.Name_list[1] except: self.modify_name = None # 下载文件 def download_files(self): my_files = ReadData() options = webdriver.ChromeOptions() prefs = {'download.default_directory': my_files._obj_files_dowload_path()} options.add_experimental_option('prefs', prefs) driver = MyWebDriver( command_executor=self.loginout_parse.get("remote_url", "url"), options=options) return driver def _split_assert(self, assert_content): self.count = assert_content.split("Total:") self.after_count = int(self.count[1]) + 1 return "Total:{}".format(self.after_count) def Column_settings(self, Column): # 24.02待修改-已修改 # 点击列设置 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 全不选并确认 # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_Cancel_Button_posXpath).click() self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_CheckBox_posXpath).click() self.driver.find_element(By.XPATH, mainPage_Object_Title_Name_posXpath).click() # 全不选,选择展示Column并确认 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() self.Column_text = self.driver.find_element(By.XPATH, Column).text # print(self.Column_text) self.driver.find_element(By.XPATH, Column).click() # 选择目标Column self.driver.find_element(By.XPATH, mainPage_Object_Title_Name_posXpath).click() # self.driver.find_element(By.XPATH,mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按钮 self.Column_ele_ex(Column_text=self.Column_text) # 调用校验方法 # 全选并确认 # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_All_Button_posXpath).click() # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_CheckBox_posXpath).click() self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_CheckBox_posXpath).click() self.driver.find_element(By.XPATH, mainPage_Object_Title_Name_posXpath).click() # 全选并取消 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_CheckBox_posXpath).click() self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_CheckBox_posXpath).click() self.driver.find_element(By.XPATH, mainPage_Object_Title_Name_posXpath).click() def View_statistics(self, edit_element): # 主界面View验证 self.driver.find_element(By.XPATH, main_listPage_object_statistics_view_postXpath).click() self.driver.isElementExist(Element='//i[@class="iconfont icon-Clear_aNormal close-icon"]') assert self.driver.Exist, "Statistics界面打开" self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() time.sleep(2) # 详情界面Statistics验证 # self.driver.find_element(By.XPATH, listPage_select_first_object_posXpath).click() self.driver.find_element(By.XPATH, edit_element).click() self.driver.find_element(By.XPATH, '(//button[text()="Statistics"])[1]').click() self.driver.isElementExist(Element='(//i[@class="iconfont icon-Clear_aNormal close-icon"])[2]') assert self.driver.Exist, "Statistics界面打开" time.sleep(2) self.driver.find_element(By.XPATH, '(//i[@class="iconfont icon-Clear_aNormal close-icon"])[2]').click() time.sleep(2) def Duplicate_check(self, data): self.driver.isElementExist(Element=listPage_object_reprtition_check_postXpath) assert self.driver.Exist, "未存在重复标识" if data["repetition_type"] == "0": # 侧滑部分校验 self.driver.find_element(By.XPATH, listPage_object_reprtition_check_postXpath).click() self.total_count = self.driver.find_element(By.XPATH,listPage_object_reprtition_total_postXpath).text self.count = self.total_count.split("Total:") print(self.count[1]) assert self.count[1] == '1' # 悬浮框内容校验 element_to_hover_over = self.driver.find_element(By.XPATH, "//div[@class='TableList floatleft overflow-y-auto width100']//div[@class='reference-box el-popover__reference']/span") ActionChains(self.driver).move_to_element(element_to_hover_over).perform() tooltip = WebDriverWait(self.driver, 10).until( EC.visibility_of_element_located((By.XPATH, '//div[@x-placement="right-start"]')) ) # 行符分割为列表 hover_tooltip = tooltip.text.splitlines() # 列表转换为字典 result_dict = {} for i in range(0, len(hover_tooltip), 2): if i + 1 < len(hover_tooltip): # 确保存在下一行 key = hover_tooltip[i].strip() # 去除首尾空格作为键 value = hover_tooltip[i + 1].strip() # 去除首尾空格作为值 result_dict[key] = value try: assert data["Create"]["item"][0] == result_dict["Item"].split()[0],"校验悬浮框item值" except KeyError: assert list(data["Create"]["item"].values())[0] == result_dict["Item"].split()[0],"校验悬浮框item值" # Gary‘s Duplicate_check def verify_duplicate_items(self, data, obj_type): self.driver.isElementExist(Element=listPage_object_reprtition_check_postXpath) assert self.driver.Exist, "校验失败!!重复标志不存在!!" if data["repetition_type"] == "0": # 侧滑部分校验 self.driver.find_element(By.XPATH, listPage_object_reprtition_check_postXpath).click() total_count = self.driver.find_element(By.XPATH, listPage_object_reprtition_total_postXpath).text count = total_count.split("Total:") assert int(count[1]) >= 1, "校验失败!" # 悬浮框内容校验 # element_to_hover_over = self.driver.find_element(By.XPATH, # "//div[@class='TableList floatleft overflow-y-auto width100']//div[@class='reference-box el-popover__reference']/span") # ActionChains(self.driver).move_to_element(element_to_hover_over).perform() # tooltip = WebDriverWait(self.driver, 10).until( # EC.visibility_of_element_located((By.XPATH, '//div[contains(@x-placement,"-start")]'))) # # 行符分割为列表 # hover_tooltip = tooltip.text.splitlines() # # 列表转换为字典 # result_dict = {} # for i in range(0, len(hover_tooltip), 2): # if i + 1 < len(hover_tooltip): # 确保存在下一行 # key = hover_tooltip[i].strip() # 去除首尾空格作为键 # value = hover_tooltip[i + 1].strip() # 去除首尾空格作为值 # result_dict[key] = value # if obj_type == "asns": # data_item = data["Items"]["IPv4"][0].split("->")[0].strip() # tooltip_item = result_dict["Item"].split(" ")[-1].strip() # elif obj_type == "flags": # # todo 修改验证 # data_item = data["Items"][0][0].split("->")[0].strip() # tooltip_item = data_item # elif obj_type == "intervals": # data_item = data["Items"][0].split("->")[0].strip() # if type(data_item) == type("abc"): # l = eval(data_item) # 将字符串转换为列表 # elif type(data_item) == type([1, 2]): # l = data_item # a = l[0] # 获取列表的第一个元素 # b = l[1] # 获取列表的第二个元素 # int_items_values = str(a) + " - " + str(b) # 将两个元素用"-"连接,并转换为字符串 # data_item = int_items_values # "11-22" # tooltip_item = result_dict["Item"] # else: # data_item = data["Items"][0].split("->")[0].strip() # tooltip_item = result_dict["Item"].strip() # try: # assert data_item == tooltip_item # except KeyError: # # assert list(data["Create"]["item"].values())[0] == result_dict["Item"].strip()[0] # raise KeyError # 判断列元素 def Column_ele_ex(self, Column_text): data = "//*[@id='root']/div/div/main/div[1]/div[2]/div[2]/div[1]/div[1]/div/div/div['replace']/div[1]/div/div/div" # for i in range(1, 13): self.result = True i = 1 while self.result == False: if i == 1: self.title = data.replace("div['replace']/div[1]/div/div/div", "div[{}]/div[1]/div/div/div".format(i)) self.title_text = self.driver.find_element(By.XPATH, self.title) if Column_text == self.title_text: self.result = True print("校验通过") break else: i += 1 else: self.title = data.replace("div['replace']/div[1]/div/div/div", "div[{}]/div[1]/div/div/div".format(i)) self.title_text = self.driver.find_element(By.XPATH, self.title) if Column_text == self.title_text: self.result = True break else: i += 1 # 翻页操作 def pages_turning(self, data, page_flag=1): """ 页码跳转 :param data: :param page_flag: 1-Object列表页,2-对象组添加对象时的侧滑列表页 :return: data示例:{ "ids": "翻页操作T014-1", "//": "注释!直接跳转至对应页面,如destination_page为0则进行随机遍历跳转", "turn_mode": 1, "destination_page": "0" }, :param page_flag: 1-Object列表页,2-对象组添加对象时的侧滑列表页 """ # self.driver.implicitly_wait(5) turn_mode = data["turn_mode"] # data中翻页模式 destination_page_number = data["destination_page"] # data中目标页码 self.turn_page_falg = 1 listPage_max_page_elem_is_exist = self.driver.element_isExist(By.XPATH, listPage_object_pages_maxPageNumber_posXpath) DrawerlistPage_max_page_elem_is_exist = self.driver.element_isExist(By.XPATH, DrawerlistPage_object_pages_maxPageNumber_posXpath) if listPage_max_page_elem_is_exist or DrawerlistPage_max_page_elem_is_exist: # 存在页码 if page_flag == 1: # 1-Object列表页 # 拿翻页前后的同一元素,用于校验翻页后页面内容是否刷新 page_elem_posXpath = listPage_fist_object_id_poxXpath # 取列表页第一个Object的ID # 获取页面中最大页码 max_page_elem_Xpath = listPage_object_pages_maxPageNumber_posXpath max_page_number = self.driver.find_element(By.XPATH, max_page_elem_Xpath).text # print("max_page_number:{}".format(max_page_number)) # 前一页按钮 previousPage_button = self.driver.find_element(By.XPATH, listPage_object_pages_previousPage_button_poxXpath) # 后一页按钮 nextPage_button = self.driver.find_element(By.XPATH, listPage_object_pages_nextPage_button_poxXpath) # Goto 输入框 goTo_input = self.driver.find_element(By.XPATH, listPage_object_pages_goTo_input_poxXpath) # 当前页码元素 currentPageNumber_posXpath = listPage_object_pages_currentPageNumber_posXpath # 页面中目标页码元素模板 destination_page_elem_XpathTemple = '//div[@class="page-box-containcheck"]//li[text()={}]' # # 快速后翻页按钮Xpath # quicNext_button_Xpath = listPage_object_pages_quickNextPage_button_poxXpath # # 快速前翻页按钮Xpath # quickPrevious_button_Xpath = listPage_object_pages_quickPreviousPage_button_poxXpath else: # 2-对象组添加对象时的侧滑列表页 # 拿翻页前后的同一元素,用于校验翻页后页面内容是否刷新 page_elem_posXpath = '(//div[@class="ToggleDraw"]//span[@class="ellipsis list-popover-click"])[1]' # 取列表页第一个Object的name # 获取页面中最大页码 max_page_elem_Xpath = DrawerlistPage_object_pages_maxPageNumber_posXpath max_page_number = self.driver.find_element(By.XPATH, max_page_elem_Xpath).text # print("max_page_number:{}".format(max_page_number)) # 前一页按钮 previousPage_button = self.driver.find_element(By.XPATH, DrawerlistPage_object_pages_previousPage_button_poxXpath) # 后一页按钮 nextPage_button = self.driver.find_element(By.XPATH, DrawerlistPage_object_pages_nextPage_button_poxXpath) # Goto 输入框 goTo_input = self.driver.find_element(By.XPATH, DrawerlistPage_object_pages_goTo_input_poxXpath) # 当前页码元素 currentPageNumber_posXpath = DrawerlistPage_object_pages_currentPageNumber_posXpath # 页面中目标页码元素模板 destination_page_elem_XpathTemple = '//div[@class="ToggleDraw"]//li[text()={}]' # # 快速后翻页按钮Xpath # quicNext_button_Xpath = listPage_object_pages_quickNextPage_button_poxXpath # # 快速前翻页按钮Xpath # quickPrevious_button_Xpath = listPage_object_pages_quickPreviousPage_button_poxXpath if int(max_page_number) == 1: # 只有1页则跳过 self.turn_page_falg = 0 # try: # # 切换至Vsys0 # loginout_parse_dir = os.path.join(workdir, "config", "loginout.ini") # self.loginout_parse.read(loginout_parse_dir, encoding="utf-8") # vsys_name = self.loginout_parse.get("vsys0", "vsys_name") # profile_pub = ProfilesPublicOperations(self.driver) # profile_pub.change_vsys(vsys_name=vsys_name) # # self.driver.implicitly_wait(4) # # max_page_number_elem = WebDriverWait(self.driver, 10).until( # EC.visibility_of_element_located((By.XPATH, max_page_elem_Xpath)) # ) # max_page_number = max_page_number_elem.text # if int(max_page_number) == 1: # 只有1页则跳过 # self.driver.refresh() # raise Exception("页码仅为1页,无法进行翻页操作!") # # pytest.skip("页码仅为1页,无法进行翻页操作!") # else: # self._turn_page(page_elem_posXpath, turn_mode, destination_page_number, max_page_number, # previousPage_button, # nextPage_button, # goTo_input, currentPageNumber_posXpath, destination_page_elem_XpathTemple) # except Exception as e: # print(e) else: self._turn_page(page_elem_posXpath, turn_mode, destination_page_number, max_page_number, previousPage_button, nextPage_button, goTo_input, currentPageNumber_posXpath, destination_page_elem_XpathTemple) else: print(" 无页码元素,无法进行翻页操作--跳过") pass def _turn_page(self, page_elem_posXpath, turn_mode, destination_page_number, max_page_number, previousPage_button, nextPage_button, goTo_input, currentPageNumber_posXpath, destination_page_elem_XpathTemple): if turn_mode == 1: # 直接跳转至对应页面,如destination_page为0则进行随机跳转 if destination_page_number == "0" or int(destination_page_number) > int(max_page_number): # 如destination_page为0或大于最大页码则进行随机跳转 # 随机页码list # random_list = [(lambda a, b: random.randrange(a, b + 1))(1, int(max_page_number)) for i in # range(int(int(max_page_number) / 2))] list_lenth = int(int(max_page_number) / 2) if list_lenth > 10: list_lenth = 10 random_list = [(lambda a, b: random.randrange(a, b + 1))(1, int(max_page_number)) for i in range(list_lenth)] # 10个随机页码,视情况自定义 else: random_list = [(lambda a, b: random.randrange(a, b + 1))(1, int(max_page_number)) for i in range(list_lenth)] print("--------------------------------random_list:{}".format(random_list)) for i in random_list: # 或取页面中目标页码元素 destination_page_elem_Xpath = destination_page_elem_XpathTemple.format(i) print("--------------------------------before _operate_turn_pages") self._operate_turn_pages(i, destination_page_elem_Xpath, currentPageNumber_posXpath, goTo_input) print("--------------------------------after _operate_turn_pages") destination_page_elem = self.driver.find_element(By.XPATH, destination_page_elem_Xpath) # previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text previous_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text destination_page_elem.click() # next_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text loop_count = 3 for loop in range(loop_count): try: next_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text break except: time.sleep(1) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text if current_page_number != str(i): assert previous_page_elem != next_page_elem current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text # print("current_page_number:{a}|destination_page_number:{b}".format(a=current_page_number, b=str(i))) assert current_page_number == str(i), "校验页码跳转失败!!dst= {}| crt ={} ".format(str(i), current_page_number) else: # 正常跳转至目标页 destination_page_elem_Xpath = destination_page_elem_XpathTemple.format( destination_page_number) self._operate_turn_pages(destination_page_number, destination_page_elem_Xpath, currentPageNumber_posXpath, goTo_input) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text destination_page_elem = self.driver.find_element(By.XPATH, destination_page_elem_Xpath) previous_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text destination_page_elem.click() loop_count = 5 for loop in range(loop_count): try: next_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text break except: time.sleep(1) # next_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text if current_page_number != destination_page_number: assert previous_page_elem != next_page_elem, "翻页数据未刷新,previous_page_elem={},next_page_elem".format( previous_page_elem, next_page_elem) assert self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text == str( destination_page_number), "校验页码跳转失败!!" print("翻页成功,{}".format(current_page_number)) elif turn_mode == 2: # 使用前一页或后一页按钮进行翻页,如destination_page为0则进行随机跳转 if destination_page_number == "0" or int(destination_page_number) > int( max_page_number): # 如destination_page为0或大于最大页码则进行随机跳转 random_page_number = random.randint(1, int(max_page_number)) if random_page_number >= 10: # print(f"destination_page{destination_page}") self.clear_Name(goTo_input) goTo_input.send_keys(int(random_page_number) - 4) # 确认并执行跳转 goTo_input.send_keys(Keys.ENTER) # 输入框中执行回车 # print("random_page_number:{}".format(random_page_number)) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text while int(current_page_number) != random_page_number: if int(current_page_number) < random_page_number: previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text nextPage_button.click() loop_count = 5 for loop in range(loop_count): try: next_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text break except: time.sleep(1) assert previous_page_elem != next_page_elem, "翻页数据未刷新,previous_page_elem={},next_page_elem".format( previous_page_elem, next_page_elem) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text elif int(current_page_number) > random_page_number: previousPage_button.click() current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text else: break # print("current_page_number:{a}|destination_page_number:{b}".format(a=current_page_number, # b=str(random_page_number))) assert self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text == str( random_page_number), "校验页码跳转失败!!" else: # 正常跳转至目标页 current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text while current_page_number != destination_page_number: if int(current_page_number) < int(destination_page_number): previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text nextPage_button.click() loop_count = 5 for loop in range(loop_count): try: next_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text break except: time.sleep(1) assert previous_page_elem != next_page_elem, "翻页数据未刷新,previous_page_elem={},next_page_elem".format( previous_page_elem, next_page_elem) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text elif int(current_page_number) > int(destination_page_number): previousPage_button.click() current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text else: break # print("current_page_number:{a}|destination_page_number:{b}".format(a=current_page_number, # b=destination_page_number)) assert self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text == str( destination_page_number), "校验页码跳转失败!!" elif turn_mode == 3: # 使用Go to页码数进行翻页,如destination_page为0则进行随机跳转 if destination_page_number == "0" or int(destination_page_number) > int( max_page_number): # 如destination_page为0或大于最大页码则进行随机跳转 random_page_number = random.randint(1, int(max_page_number)) self.clear_Name(goTo_input) # 搜索框中键入搜索值 goTo_input.send_keys(random_page_number) # 确认并执行跳转 previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text goTo_input.send_keys(Keys.ENTER) # 输入框中执行回车 loop_count = 5 for loop in range(loop_count): try: next_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text break except: time.sleep(1) if random_page_number != 1: assert previous_page_elem != next_page_elem, "翻页数据未刷新" # current_page_number = self.driver.find_element(By.XPATH, # currentPageNumber_posXpath).text # print("current_page_number:{a}|destination_page_number:{b}".format(a=current_page_number, # b=str(random_page_number))) assert self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text == str( random_page_number), "校验页码跳转失败!!" else: # 正常跳转至目标页 self.clear_Name(goTo_input) # 搜索框中键入搜索值 goTo_input.send_keys(destination_page_number) # 确认并执行跳转 previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text goTo_input.send_keys(Keys.ENTER) # 输入框中执行回车 next_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text assert previous_page_elem != next_page_elem, "翻页数据未刷新" # current_page_number = self.driver.find_element(By.XPATH, # currentPageNumber_posXpath).text # print("current_page_number:{a}|destination_page_number:{b}".format(a=current_page_number, # b=str(destination_page_number))) assert self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text == str( destination_page_number), "校验页码跳转失败!!" elif turn_mode == 4: # 使用快速翻页按钮进行翻页,如destination_page为0则进行随机跳转 if int(max_page_number) <= 6: pass else: if destination_page_number == "0" or int(destination_page_number) > int( max_page_number): # 如destination_page为0或大于最大页码则进行随机跳转 list_lenth = int(int(max_page_number) / 2) if list_lenth > 10: list_lenth = 10 # 随机页码list random_list = [(lambda a, b: random.randrange(a, b + 1))(6, int(max_page_number)) for i in range(list_lenth)] else: random_list = [(lambda a, b: random.randrange(a, b + 1))(1, int(max_page_number)) for i in range(list_lenth)] # print("random_list:{}".format(random_list)) for i in random_list: # 或取页面中目标页码元素 destination_page_elem_Xpath = destination_page_elem_XpathTemple.format( i) self._operate_turn_pages(i, destination_page_elem_Xpath, currentPageNumber_posXpath, goTo_input) destination_page_elem = self.driver.find_element(By.XPATH, destination_page_elem_Xpath) previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text destination_page_elem.click() loop_count = 5 for loop in range(loop_count): try: next_page_elem = self.wait.until( EC.presence_of_element_located((By.XPATH, page_elem_posXpath))).text break except: time.sleep(1) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text if current_page_number != str(i): assert previous_page_elem != next_page_elem current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text # print("current_page_number:{a}|destination_page_number:{b}".format(a=current_page_number, # b=str(i))) assert current_page_number == str(i), "校验页码跳转失败!!dst= {}| crt ={} ".format(str(i), current_page_number) else: # 正常跳转至目标页 destination_page_elem_Xpath = destination_page_elem_XpathTemple.format( destination_page_number) self._operate_turn_pages(destination_page_number, destination_page_elem_Xpath, currentPageNumber_posXpath, goTo_input) destination_page_elem = self.driver.find_element(By.XPATH, destination_page_elem_Xpath) destination_page_elem.click() assert self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text == str( destination_page_number), "校验页码跳转失败!!" def _operate_turn_pages(self, destination_page, destination_page_elem_Xpath, currentPageNumber_posXpath, goTo_input): """ 针对页码快速跳转操作 :param destination_page: 上层传递的目标页码 :param destination_page_elem_Xpath: 上层传递的目标页码元素的Xpath :param currentPageNumber_posXpath: 上层传递的当前页码元素的Xpath :param goTo_input: 上层传递的Goto输入框元素的Xpath :return: """ if int(destination_page) > 20: # print(f"destination_page{destination_page}") self.clear_Name(goTo_input) goTo_input.send_keys(int(destination_page) - 9) # 确认并执行跳转 # previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text goTo_input.send_keys(Keys.ENTER) # 输入框中执行回车 # next_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text # assert previous_page_elem != next_page_elem, "翻页数据未刷新" while True: # 判断目标页码元素是否存在 print("----------------In while") self.driver.isElementExist(Element=destination_page_elem_Xpath) # print("isElementExist:{}".format(self.driver.Exist)) current_page_number = self.driver.find_element(By.XPATH, currentPageNumber_posXpath).text if not self.driver.Exist: print("-----------quick exist!!!!") if int(destination_page) > int(current_page_number): # time.sleep(0.1) # previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text self.driver.find_element(By.XPATH, listPage_object_pages_quickNextPage_button_poxXpath).click() # next_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text # assert previous_page_elem != next_page_elem, "翻页数据未刷新" elif int(destination_page) < int(current_page_number): # time.sleep(0.1) # previous_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text self.wait.until(EC.presence_of_element_located, ((By.XPATH, listPage_object_pages_quickPreviousPage_button_poxXpath))) self.driver.find_element(By.XPATH, listPage_object_pages_quickPreviousPage_button_poxXpath).click() # next_page_elem = self.driver.find_element(By.XPATH, page_elem_posXpath).text # assert previous_page_elem != next_page_elem, "翻页数据未刷新" else: print("-----------quick not exist!!!! break") break # def pages_turning_case(self): # # 1、获取当前页码 2、点击下一页翻页 3、断言翻页后,页码为当前页码+1 # self.current_page = int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageNumber_posXpath).text) # self.max_page = int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageArea_MaxNumber_posXpath).text) # if self.max_page > self.current_page: # self.driver.find_element(By.XPATH, listPage_object_pages_nextPage_button_poxXpath).click() # assert self.current_page + 1 == int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageNumber_posXpath).text) # # 2、获取当前页码 2、点击上一页翻页 3、断言翻页后,页码展示为当前页码-1 # self.current_page = int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageNumber_posXpath).text) # if self.current_page > 1: # self.driver.find_element(By.XPATH, listPage_object_pages_previousPage_button_poxXpath).click() # assert self.current_page - 1 == int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageNumber_posXpath).text) # # 3、输入页码回车进行翻页 # self.max_page = int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageArea_MaxNumber_posXpath).text) # if self.max_page <= 2: # pass # elif self.max_page > 2: # self.clear_Name(path=listPage_object_pages_goTo_input_poxXpath) # self.driver.find_element(By.XPATH, listPage_object_pages_goTo_input_poxXpath).send_keys( # str(self.max_page / 2 + 1) + Keys.ENTER) # assert int(self.max_page / 2 + 1) == int(self.driver.find_element(By.XPATH, # listPage_object_pages_currentPageNumber_posXpath).text), "断言所翻页码处于当前页" # # 4、点击第五页进行翻页 # self.driver.isElementExist(Element=listPage_object_pages_currentPageAreaMaxNumber_posXpath) # if self.driver.Exist: # self.last_page = int( # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageAreaMaxNumber_posXpath).text) # self.driver.find_element(By.XPATH, listPage_object_pages_currentPageAreaMaxNumber_posXpath).click() # assert self.last_page == int(self.driver.find_element(By.XPATH, # listPage_object_pages_currentPageNumber_posXpath).text), "断言所翻页码处于当前页" # else: # pass # 判断元素是否可点击 def is_element_clickable(self, elm, elm_type="XPATH", timeout=2): """判断元素是否存在 :param elm: 元素定位 :param elm_type: 元素定位方式 :return: 是否可点击 """ try: # 设置一个最大等待时间 timeout = WebDriverWait(self.driver, timeout) if elm_type == 'ID': # 等待元素可点击 timeout.until(EC.element_to_be_clickable((By.ID, elm))) return True elif elm_type == 'XPATH': # 等待元素可点击 timeout.until(EC.element_to_be_clickable((By.XPATH, elm))) return True elif elm_type == 'CSS_SELECTOR': # 等待元素可点击 timeout.until(EC.element_to_be_clickable((By.CSS_SELECTOR, elm))) return True elif elm_type == 'NAME': # 等待元素可点击 timeout.until(EC.element_to_be_clickable((By.NAME, elm))) return True except: return False # 消除右上提示弹窗 def dismiss_rightTopTips(self, close_button_elem_Xpath=mainPage_rightTopTips_closeButton_posXpath): """ :param close_button_elem_Xpath: :return: """ # print("消除弹窗") # time.sleep(3) self.driver.isElementExist(close_button_elem_Xpath) loop_count = 2 while loop_count > 0: try: self.driver.isElementExist(close_button_elem_Xpath) if self.driver.Exist: self.driver.find_element(By.XPATH, close_button_elem_Xpath).click() loop_count -= 1 except: loop_count -= 1 pass # try: # self.driver.isElementExist(Element="//div/div[1]/div[2]/div/div[2]/div[3]/i") # if self.driver.Exist: # self.driver.find_element(By.XPATH,'//div/div[1]/div[2]/div/div[2]/div[3]/i').click() # except: # pass # try: # self.driver.isElementExist(Element="//div/div[1]/div[2]/div/div/div[3]/i") # if self.driver.Exist: # self.driver.find_element(By.XPATH,'//div/div[1]/div[2]/div/div/div[3]/i').click() # except: # pass # self.driver.implicitly_wait(5) # self.driver.isElementExist(close_button_elem_Xpath) # flag = self.driver.Exist # loop_count = 2 # while flag and loop_count > 0: # try: # self.driver.isElementExist(close_button_elem_Xpath) # flag = self.driver.Exist # # close_button_elem = self.driver.find_element(By.XPATH, close_button_elem_Xpath) # if flag: # # 1 # # for i in self.driver.find_elements(By.XPATH,close_button_elem_Xpath): # # i.click() # # 2 # close_button_elem = self.driver.find_element_by_xpath(close_button_elem_Xpath) # close_button_elem.click() # except: # self.driver.refresh() # loop_count -= 1 # # break # 删除选中对象 def delete(self, listPage_object_subObjects_delButton_posXpath, listPage_dialogTips_subObjects_button_yes_posXpath, listPage_dialogTips_subObjects_button_no_posXpath, ): self.driver.find_element(By.XPATH, listPage_object_subObjects_delButton_posXpath).click() # 点击删除按钮 random_yes_or_no = random.randint(0, 1) if random_yes_or_no == 0: # 点击yes,删除 self.driver.find_element(By.XPATH, listPage_dialogTips_subObjects_button_yes_posXpath).click() # 直接删除 else: self.driver.find_element(By.XPATH, listPage_dialogTips_subObjects_button_no_posXpath).click() # 先取消,再删除 self.driver.find_element(By.XPATH, listPage_object_subObjects_delButton_posXpath).click() # 点击删除按钮 self.driver.find_element(By.XPATH, listPage_dialogTips_subObjects_button_yes_posXpath).click() # 点击yes,删除 time.sleep(0.5) def common_delete(self): # 点击删除按钮 del_button = self.wait.until(EC.presence_of_element_located((By.XPATH, listPage_deleteButton_posXpath))) del_button.click() # self.driver.find_element(By.XPATH, listPage_deleteButton_posXpath).click() # 点击删除按钮 # 确认弹窗确认 yes_button = self.wait.until( EC.presence_of_element_located((By.CSS_SELECTOR, listPage_object_delete_yesButton_posCss))) yes_button.click() # self.driver.find_element(By.CSS_SELECTOR, # listPage_object_delete_yesButton_posCss).click() # 点击yes,删除 # 判断某目录下是否为空 def delete_folder_contents(self, folder): # time.sleep(3) # 判断文件夹是否为空 if os.listdir(folder): print('不为空') # 遍历文件夹下的所有文件和子文件夹 for item in os.listdir(folder): # 拼接完整的路径 path = os.path.join(folder, item) # 判断是文件还是文件夹 if os.path.isfile(path): # 删除文件 os.remove(path) elif os.path.isdir(path): # 删除文件夹及其内容 shutil.rmtree(path) else: # 文件夹为空,不做任何操作 print('该目录为空') pass def extract_ele_userdefinedAttributesAndSignatures(self): # self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 # all_checked_xpath = '//*[@class="all-btn"]//*[@class="el-checkbox__input is-checked"]' # if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_click_Cancel_Button_posXpath).click() # 点击Cancel按钮 # else: # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # 全选 # self.driver.find_element(By.XPATH, # mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按钮 # 公共方法 Detail特殊,需要使用时特殊提取 # ID # self.key11 = self.driver.find_element(By.XPATH, Userdefined_first_row_first_column_posXpath).text # self.value12 = self.driver.find_element(By.XPATH, Userdefined_second_row_first_column_posXpath).text # # Vsy_ID # self.key12 = self.driver.find_element(By.XPATH, Userdefined_first_row_second_column_posXpath).text # self.value22 = self.driver.find_element(By.XPATH, Userdefined_second_row_second_column_posXpath).text # Name column_setting_btn = self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath) # 列设置按钮 self.driver.execute_script("arguments[0].scrollIntoView();", column_setting_btn) column_setting_btn.click() self.driver.find_element(By.XPATH, '//span[text()="UUID"]').click() self.driver.find_element(By.XPATH, '//div[text()="Attribute Name"]').click() self.uuid_name = self.driver.find_element(By.XPATH, '//div[text()="UUID"]').text self.uuid_value = self.driver.find_element(By.XPATH, '//div[@aria-rowindex="2"]//div[@data-field="uuid"]').text self.key13 = self.driver.find_element(By.XPATH, Userdefined_first_row_third_column_posXpath).text self.value23 = self.driver.find_element(By.XPATH, Userdefined_second_row_third_column_posXpath).text # 字典 self.table_dict1 = {self.uuid_name:self.uuid_value,self.key13: self.value23} print(self.table_dict1) # 提取Attributes的ID、Name def assert_ele_userdefined_attributes_and_signatures(self): # 公共方法 Detail特殊,需要使用时特殊提取 # ID # self.key11 = self.driver.find_element(By.XPATH, Userdefined_first_row_first_column_posXpath).text # self.value12 = self.driver.find_element(By.XPATH, Userdefined_second_row_first_column_posXpath).text # # Vsy_ID # self.key12 = self.driver.find_element(By.XPATH, Userdefined_first_row_second_column_posXpath).text # self.value22 = self.driver.find_element(By.XPATH, Userdefined_second_row_second_column_posXpath).text # Name self.key13 = self.driver.find_element(By.XPATH, Userdefined_first_row_third_column_posXpath).text self.value23 = self.driver.find_element(By.XPATH, Userdefined_second_row_third_column_posXpath).text # 字典 self.edit_table_dict1 = {self.key13: self.value23} print(self.edit_table_dict1) def new_security_policy(self, data: {}): # 跳转到安全策略创建页面 self.driver.find_element(By.ID, mainPage_firstLevelMenu_Policy_posId).click() self.driver.find_element(By.ID, mainPage_secondLevelMenu_Security_posId).click() # 1、点击创建 2、输入Name 3、选择IMSI\IMEI\Phone_Number self.driver.find_element(By.XPATH, listpage_create_button_posXpath).click() self.driver.find_element(By.XPATH, security_create_Name_input_frame_PosXpath).send_keys(data['Name']) self.driver.find_element(By.XPATH, security_policy_add_condition_button_by_xpath).click() # 选择Condition按钮 self.driver.find_element(By.XPATH, security_policy_add_device_button_by_xpath).click() # 选择Device self.driver.find_element(By.XPATH, security_policy_add_button_by_xpath).click() # 添加Device if data["Createtype"] == "IMSI": self.driver.find_element(By.XPATH, security_create_add_source_button_select_IMSI_PosXpath).click() self.driver.find_element(By.XPATH, security_create_add_source_button_IMSI_search_frame_PosXpath).send_keys( data['Name'] + Keys.ENTER) elif data["Createtype"] == "Phone_Number": self.driver.find_element(By.XPATH, security_create_add_source_button_select_Phone_Number_PosXpath).click() self.driver.find_element(By.XPATH, security_create_add_source_button_Phone_Number_search_frame_PosXpath).send_keys( data['Name'] + Keys.ENTER) elif data["Createtype"] == "IMEI": self.driver.find_element(By.XPATH, security_create_add_source_button_select_IMEI_PosXpath).click() self.driver.find_element(By.XPATH, security_create_add_source_button_IMEI_search_frame_PosXpath).send_keys( data['Name'] + Keys.ENTER) time.sleep(3) self.driver.isElementExist(Element=security_create_add_source_button_select_first_object_PosXpath) if self.driver.Exist: # 如果存在,就进行创建 assert self.driver.Exist == True print('正常找到Object,正常进行引用创建') self.driver.find_element(By.XPATH, security_create_add_source_button_select_first_object_PosXpath).click() self.driver.find_element(By.XPATH, security_create_ok_click_posXpath).click() self.driver.find_element(By.XPATH, security_create_Warn_ok_click_posXpath).click() else: # 不存在就跳过 assert self.driver.Exist == False # 未找到元素 print('未找到Object,无法进行引用创建') pass def new_intercept_policy(self, data: {}): # 跳转到安全策略创建页面 self.driver.find_element(By.ID, mainPage_firstLevelMenu_Policy_posId).click() self.driver.find_element(By.ID, mainPage_secondLevelMenu_Proxy_intercept_posId).click() # 1、点击创建 2、输入Name 3、选择IMSI\IMEI\Phone_Number self.driver.find_element(By.XPATH, intercept_create_Button_posXpath).click() self.driver.find_element(By.XPATH, intercept_create_Name_input_frame_PosXpath).send_keys(data['Name']) self.driver.find_element(By.XPATH, intercept_create_add_source_button_click_PosXpath).click() self.driver.find_element(By.XPATH, intercept_create_add_source_button_right_click_PosXpath).click() if data["Createtype"] == "IMSI": self.driver.find_element(By.XPATH, intercept_create_add_source_button_select_IMSI_PosXpath).click() self.driver.find_element(By.XPATH, intercept_create_add_source_button_IMSI_search_frame_PosXpath).send_keys( data['Name'] + Keys.ENTER) elif data["Createtype"] == "Phone_Number": self.driver.find_element(By.XPATH, intercept_create_add_source_button_select_Phone_Number_PosXpath).click() self.driver.find_element(By.XPATH, intercept_create_add_source_button_Phone_Number_search_frame_PosXpath).send_keys( data['Name'] + Keys.ENTER) elif data["Createtype"] == "IMEI": self.driver.find_element(By.XPATH, intercept_create_add_source_button_select_IMEI_PosXpath).click() self.driver.find_element(By.XPATH, intercept_create_add_source_button_IMEI_search_frame_PosXpath).send_keys( data['Name'] + Keys.ENTER) time.sleep(3) self.driver.isElementExist(Element=intercept_create_add_source_button_select_first_object_PosXpath) if self.driver.Exist: # 如果存在,就进行创建 assert self.driver.Exist == True print('正常找到Object,正常进行引用创建') self.driver.find_element(By.XPATH, intercept_create_add_source_button_select_first_object_PosXpath).click() # 添加application self.driver.find_element(By.XPATH, intercept_create_add_application__posXpath).click() self.driver.find_element(By.XPATH, intercept_create_application_select_first_http_posXpath).click() # 确认创建 self.driver.find_element(By.XPATH, intercept_create_ok_click_posXpath).click() self.driver.find_element(By.XPATH, intercept_create_Warn_ok_click_posXpath).click() else: # 不存在就跳过 assert self.driver.Exist == False print('未找到Object,无法进行引用创建') pass def _del_policy(self, data: {}): if data['delete_mode'] == "security": # 跳转到安全策略创建页面 self.driver.find_element(By.XPATH, mainPage_firstLevelMenu_Policy_posXpath).click() self.driver.find_element(By.XPATH, mainPage_secondLevelMenu_Security_posXpath).click() # 1、点击安全策略输入框 2、选择Name 3、输入Name 4、点击搜索 5、选择第一个元素 6、点击删除 self.driver.find_element(By.XPATH, listpage_search_input_posXpath).click() self.driver.find_element(By.XPATH, listpage_search_input_posXpath).send_keys(data['Name']) self.driver.find_element(By.XPATH, listPage_objectSearch_select_Name_posXpath).click() self.driver.find_element(By.XPATH, listpage_search_button_posXpath).click() self.driver.isElementExist(Element=list_security_select_first_element_posXpath) if self.driver.Exist: # 如果存在,就进行创建 time.sleep(2) self.driver.find_element(By.XPATH, listPage_select_first_object_posXpath).click() self.driver.find_element(By.XPATH, listpage_delete_button_posXpath).click() self.driver.find_element(By.XPATH, listpage_delete_yes_button_posXpath).click() else: assert self.driver.Exist == False # 未找到元素 print('未找到Object,无法删除') pass elif data['delete_mode'] == "intercept": # 跳转到安全策略创建页面 self.driver.find_element(By.ID, mainPage_firstLevelMenu_Policy_posId).click() self.driver.find_element(By.ID, mainPage_secondLevelMenu_Proxy_intercept_posId).click() # 1、点击安全策略输入框 2、选择Name 3、输入Name 4、点击搜索 5、选择第一个元素 6、点击删除 self.driver.find_element(By.XPATH, list_intercept_select_frame_click_posXpath).click() self.driver.find_element(By.XPATH, list_intercept_select_frame_Name_click_posXpath).click() self.driver.find_element(By.XPATH, list_intercept_select_frame_Name_input_posXpath).send_keys(data['Name']) self.driver.find_element(By.XPATH, list_intercept_select_frame_click_search_posXpath).click() self.driver.find_element(By.XPATH, list_intercept_select_first_element_posXpath).click() self.driver.find_element(By.XPATH, delete_intercept_delete_button_posXpath).click() self.driver.find_element(By.XPATH, delete_intercept_delete_confirm_button_posXpath).click() else: pass self.driver.isElementExist(Element=listpage_no_data_posXpath) time.sleep(3) self.del_content = self.driver.find_element(By.XPATH, listpage_no_data_posXpath).text time.sleep(2) assert self.driver.Exist, "断言策略是否删除成功,No Data" assert self.del_content == "No rows" def Export_different_types(self): try: time.sleep(3) self.driver.find_element(By.XPATH, mobileIdentitiesObjectPage_Export_Mobile_Identity_files_OK_Button_posXpath).click() self.driver.isElementExist(Element=mobileIdentitiesObjectPage_Export_Mobile_type_imsi_posXpath) # imsi导出展示 assert self.driver.Exist self.driver.isElementExist( Element=mobileIdentitiesObjectPage_Export_Mobile_type_phone_number_posXpath) # imsi导出展示 assert self.driver.Exist self.driver.isElementExist(Element=mobileIdentitiesObjectPage_Export_Mobile_type_imei_posXpath) # imsi导出展示 assert self.driver.Exist self.driver.find_element(By.XPATH, '//div/div[3]/span/button[2]').click() print("点击导出按钮,断言可以导出多个不同type类型 == Sucess") except: print("点击导出按钮,断言可以导出多个不同type类型 == Fail") ''' data:{ "vsys_opearte": {"step1": "super_Tvsys1->create", "step2": "super_Mvsys3->search"}, # 操作模式:可以引用本vsys方法操作 "delete_mode":"intercept" # 清理数据 清理模式 } ''' def Switch_vsys(self, vsys_id): time.sleep(2) self.driver.find_element(By.XPATH, objects_element_position.mainPage_navigationBar_Menu_posXpath).click() try: self.driver.isElementExist(Element=mobile_Identities_Group_confirm_leave_posXpath) time.sleep(2) if self.driver.Exist: time.sleep(3) self.driver.find_element(By.XPATH, mobile_Identities_Group_confirm_leave_posXpath).click() except: pass time.sleep(2) if vsys_id == "Tvsys2": self.driver.find_element(By.XPATH, mainPage_navigationBar_Tvsys10_posXpath).click() elif vsys_id == "Mvsys2": self.driver.find_element(By.XPATH, test_mainPage_navigationBar_Mvsys2_Tvsys4_posXpath).click() elif vsys_id == "Tvsys3": self.driver.find_element(By.XPATH, test_mainPage_navigationBar_Tvsys3_posXpath).click() elif vsys_id == "super_Mvsys3": # print("切换为super_Mvsys3") self.driver.find_element(By.XPATH, objects_element_position.mainPage_navigationBar_Mvsys3_Tvsys5_posXpath).click() # print("切换为super_Mvsys3",objects_element_position.mainPage_navigationBar_Mvsys3_Tvsys5_posXpath) elif vsys_id == "super_Tvsys10": self.driver.find_element(By.XPATH, mainPage_navigationBar_super_Tvsys10_posXpath).click() elif vsys_id == "super_Tvsys3": self.driver.find_element(By.XPATH, mainPage_navigationBar_super_Tvsys3_posXpath).click() def Watch_list(self): self.extract_ele() # 清空watch列表页 self.driver.find_element(By.XPATH, listPage_objectSearch_mobileIdentities_right_list_watch_posXpath).click() self.driver.find_element(By.XPATH, listPage_objectSearch_mobileIdentities_right_list_watch_object_posXpath).click() self.driver.find_element(By.XPATH, listPage_objectSearch_mobileIdentities_right_list_watch_select_all_posXpath).click() self.driver.find_element(By.XPATH, listPage_objectSearch_mobileIdentities_right_list_watch_select_clear_posXpath).click() # 添加watch列表页 self.driver.find_element(By.XPATH, listPage_object_mobileIdentities_select_First_object_posXpath).click() self.driver.find_element(By.XPATH, listPage_objectSearch_mobileIdentities_add_watch_posXpath).click() # 查看watch_list time.sleep(3) self.watch_ID = self.driver.find_element(By.XPATH, '//ul/li[1]/div/label/span[2]/p[1]').text self.watch_Name = self.driver.find_element(By.XPATH, '//ul/li[1]/div/label/span[2]/p[2]').text assert self.table_dict["ID"] == self.watch_ID, "断言添加到watch列表中的ID是否正确" assert self.table_dict["Name"] == self.watch_Name, "断言添加到watch列表中的Name是否正确" @screenshot_on_failure def assert_del(self): time.sleep(3) self.driver.isElementExist(Element=listPage_object_mobileIdentities_select_First_object_posXpath) if self.driver.Exist == False: self.Page_Tips = self.driver.find_element(By.XPATH, listPage_object_mobileIdentities_del_after_ele_posXpath).text try: assert self.Page_Tips == "No rows", "校验是否删除成功生效" print("未查询到该Object,该Object不存在,断言成功") except: print("仍然可以查询到Object,断言失败") else: pass def compare_vsys(self, vsys1, vsys2): # _query=1,则可查询、断言ID、Name、查看操作权限 # _query=0,不可查询,del断言,引用断言 if vsys1[0] == vsys2[0] == "T" and vsys1 != vsys2: # T1 T2 self._query = 0 # 不可查询 elif vsys1[0] == vsys2[0] == "T" and vsys1 == vsys2: # T1 == T1 self._query = 1 # 相同vsys,可查询 elif vsys1[0] == vsys2[0] == "M" and vsys1 == vsys2: # M1 = M1 self._query = 1 # 相同Mvsys,可查询 elif vsys1[0] == "M" and vsys2[0] == "T": # M1 T1 self._query = 0 # Tvsys只能查看当前Vsys elif vsys1[0] == "T" and vsys2[0] == "M": # T1 M1 self._query = 0 # Mvsys没有supervisor权限,无法查看下层vsys elif vsys1[0] == vsys2[0] == "s" and vsys1[6] == vsys2[6] == "T" and vsys1 != vsys2: # ST1 ST2 self._query = 0 # 不可查询 elif vsys1[0] == vsys2[0] == "s" and vsys1[6] == vsys2[6] == "T" and vsys1 == vsys2: # ST1 ST1 self._query = 1 # 可查询 elif vsys1[0] == vsys2[0] == "s" and vsys1[6] == "M" and vsys2[6] == "T": # SM1 ST2 self._query = 0 # 不可查询 elif vsys1[0] == vsys2[0] == "s" and vsys1[6] == "T" and vsys2[6] == "M": # ST1 SM2 self._query = 1 # 可查询、断言ID、Name、查看操作权限 else: pass # 没有编辑权限 def Unauthorized_operation(self): self.driver.find_element(By.XPATH, listPage_object_mobileIdentities_allButton_posId).click() # 1、导出按钮置灰 try: self.driver.isElementExist( Element=mobileIdentitiesObjectPage_Export_Mobile_Identity_Button_posXpath) # 导出按钮置灰 assert self.driver.Exist, "导出按钮置灰" print("导出按钮置灰,测试 == Success") except: print("导出按钮置灰,测试 == Fail") # 2、编辑按钮置灰 try: self.driver.isElementExist( Element=mobileIdentitiesObjectPage_Edit_Mobile_Identity_Button_posXpath) # 编辑按钮置灰 assert self.driver.Exist, "编辑按钮置灰" print("编辑按钮置灰,测试 == Success") except: print("编辑按钮置灰,测试 == Fail") # 3、删除按钮置灰 try: self.driver.isElementExist( Element=mobileIdentitiesObjectPage_Delete_Mobile_Identity_Button_posXpath) # 删除按钮置灰 assert self.driver.Exist, "删除按钮置灰" print("删除按钮置灰,测试 == Success") except: print("删除按钮置灰,测试 == Fail") # 刷新、翻页后元素不为选中状态 def Clear_selection(self): try: self.driver.find_element(By.XPATH, listPage_object_mobileIdentities_allButton_posId).click() # 选择all time.sleep(5) self.driver.find_element(By.ID, mainPage_secondLevelMenu_Mobile_Identities_posId).click() # 刷新 self.driver.isElementExist(Element=mobileIdentitiesObjectPage_selete_Mobile_Identity_Button_posXpath) time.sleep(5) assert self.driver.Exist, "刷新导致元素不勾选" print("刷新后元素不勾选,测试 == Success") time.sleep(5) self.driver.find_element(By.XPATH, listPage_object_mobileIdentities_allButton_posId).click() # 选择all self.driver.find_element(By.XPATH, listPage_object_pages_nextPage_button_poxXpath).click() # 第二页 self.driver.isElementExist(Element=mobileIdentitiesObjectPage_selete_Mobile_Identity_Button_posXpath) time.sleep(5) assert self.driver.Exist, "翻页导致元素不勾选" print("翻页后元素不勾选,测试 == Success") except: print("翻页后元素不勾选,测试 == Fail") def Unable_to_upload(self): try: # 选择创建1 self.driver.find_element(By.ID, listPage_object_mobileIdentities_createButton_posXpath).click() self.driver.find_element(By.ID, listPage_object_mobileIdentities_create_Mobile_Identity_Button_posId).click() self.driver.find_element(By.ID, mainPage_ObjectSearch_buttonAddItem_posId).click() time.sleep(3) self.driver.isElementExist(Element=mobileIdentitiesObjectPage_import_files_Mobile_Identity_Button_posXpath) assert self.driver.Exist print("导入按钮置灰,测试 == Success") except: print("导入按钮未置灰,测试 == Fail") def download_delete_import_files(self, data: {}): try: # 选择创建1 self.driver.find_element(By.ID, listPage_object_mobileIdentities_createButton_posXpath).click() self.driver.find_element(By.ID, listPage_object_mobileIdentities_create_Mobile_Identity_Button_posId).click() # 上传文件 self.driver.find_element(By.XPATH, mobileIdentitiesObjectPage_Button_Import_Mobile_Identity_files_posXpath).click() self.driver.find_element(By.XPATH, mobileIdentitiesObjectPage_Input_path_Import_Mobile_Identity_files_posXpath).send_keys( self.my_files._obj_files_path(file_name=data["files_name"])) self.driver.find_element(By.XPATH, mobileIdentitiesObjectPage_Import_Mobile_Identity_files_OK_Button_posXpath).click() self.driver.isElementExist(Element='//li/i[@class="iconfont icon-DownNormal fontsize16"]') assert self.driver.Exist print("存在下载按钮,测试 == Success") self.driver.isElementExist(Element='//li/i[@class="el-icon-close fontsize18"]') assert self.driver.Exist print("存在删除按钮,测试 == Success") except: print("测试失败,不存在下载、删除按钮") def switch_checked(self): # 选择创建2 Group self.driver.find_element(By.ID, listPage_object_mobileIdentities_createButton_posXpath).click() self.driver.find_element(By.ID, listPage_object_mobileIdentities_create_Mobile_Identity_Group_Button_posId).click() # 查看可以开启Exclude/Include开关 self.driver.isElementExist( Element=mobileIdentitiesObjectPage_Exclude_Objects_close_Mobile_Identity_Button_posXpath) if self.driver.Exist: print("Exclude_Objects按钮开关为关,测试 == Success") else: print("Exclude_Objects按钮开关为开,测试 == Fail") # 查看可以开启Exclude/Include开关 self.driver.find_element(By.XPATH, mobileIdentitiesObjectPage_Exclude_Objects_operation_Mobile_Identity_Button_posXpath).click() self.driver.isElementExist( Element=mobileIdentitiesObjectPage_Exclude_Objects_open_Mobile_Identity_Button_posXpath) if self.driver.Exist: print("Exclude_Objects按钮开关为关,测试 == Success") else: print("Exclude_Objects按钮开关为开,测试 == Fail") def random_object_statistics(self): random_object_statistic = random.choice(["Elaborate", "Brief", "None"]) print(random_object_statistic) return random_object_statistic def linkdata(self, link_list_dict, port_listpage_linkButton_posId, port_listpage_linkSave_posXpath, port_listpage_linkAdd_posXpath, port_listpage_linkOk_posXpath): """ :param link_dict: [{"link_dst_cluster": "42.49-User4Link", "link_dst_vsys":"Vsys2test"}] :param link_dst_cluster: :param link_dst_vsys: :return: """ # 点击 link 按钮 # {"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, port_listpage_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"] link_dst_vsys = link_list_dict[link_index]["link_dst_vsys"] # 选择cluster self.driver.find_element(By.XPATH, port_listPage_linkTips_input_clusterSelect_posXpath).click() el_cluster_path = port_listPage_linkTips_dropitem_clusterDrop_posXpath.format(replaceName=link_dst_cluster) # 下拉列表元素移动到页面显示,在执行js强制点击 actions = ActionChains(self.driver) element_item = self.driver.find_element(By.XPATH, el_cluster_path) actions.move_to_element(element_item).perform() self.driver.execute_script("arguments[0].click();", element_item) # 选择vsys id self.driver.find_element(By.XPATH, port_listPage_linkTips_input_vsysSelect_posXpath).click() el_vsys_path = port_listPage_linkTips_dropitem_vsysSelect_posXpath.format(replaceName=link_dst_vsys) # 下拉列表元素移动到页面显示,在执行js强制点击 element_item2 = self.driver.find_element(By.XPATH, el_vsys_path) actions.move_to_element(element_item2).perform() self.driver.execute_script("arguments[0].click();", element_item2) # 点击 保存 if link_index == 0: self.driver.find_element(By.XPATH, port_listpage_linkSave_posXpath).click() else: self.driver.find_element(By.XPATH, "//*[@id='clusterSave']/i").click() if link_index != link_count - 1: # 不是最后一个cluster 需要添加添加按钮 self.driver.find_element(By.XPATH, port_listpage_linkAdd_posXpath).click() # 点击 OK self.driver.find_element(By.XPATH, port_listpage_linkOk_posXpath).click() time.sleep(3) # 状态断言 status_info = "color: rgb(141, 203, 75);" rows = self.driver.find_element(By.XPATH, port_listPage_objectTable_tableTbody_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") print(status_style) pytest_check.is_in(status_info, status_style, msg="所在行数{}".format(inspect.currentframe().f_lineno)) time.sleep(1) self.driver.isElementExist( Element='((//div[@class!="itemDetails cursor"]//table[@class="el-table__body"])[1]//tr)[1]') # 查看第一行是否存在数据 if self.driver.Exist: # 展示所有列 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 all_checked_xpath = '//*[@class="all-btn"]//*[@class="el-checkbox__input is-checked"]' if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_Cancel_Button_posXpath).click() # 点击Cancel按钮 else: self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # 全选 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按 Des_ID_list = [] # 获取所有Dst ID Dst_IDs = self.driver.find_elements(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr//td[count(//div[@class='el-table__header-wrapper']//span[text()='Destination ID']/../../../preceding-sibling::th)+1]//span") for Dst_ID in Dst_IDs: Des_ID_list.append(Dst_ID.text) print(Des_ID_list) # 获取Request_ID Request_ID = self.driver.find_element(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr[1]//td[count(//div[@class='el-table__header-wrapper']//span[text()='Request ID']/../../../preceding-sibling::th)+1]//span").text return Des_ID_list, Request_ID def _linkdata(self, link_list_dict, port_listpage_linkButton_posId, port_listpage_linkSave_posXpath, port_listpage_linkAdd_posXpath, port_listpage_linkOk_posXpath): """ :param link_dict: [{"link_dst_cluster": "42.49-User4Link", "link_dst_vsys":"Vsys2test"}] :param link_dst_cluster: :param link_dst_vsys: :return: """ # 点击 link 按钮 # {"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, port_listpage_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"] link_dst_vsys = link_list_dict[link_index]["link_dst_vsys"] # 选择cluster self.driver.find_element(By.XPATH, port_listPage_linkTips_input_clusterSelect_posXpath).click() el_cluster_path = port_listPage_linkTips_dropitem_clusterDrop_posXpath.format(replaceName=link_dst_cluster) # 下拉列表元素移动到页面显示,在执行js强制点击 actions = ActionChains(self.driver) element_item = self.driver.find_element(By.XPATH, el_cluster_path) actions.move_to_element(element_item).perform() self.driver.execute_script("arguments[0].click();", element_item) # 选择vsys id self.driver.find_element(By.XPATH, port_listPage_linkTips_input_vsysSelect_posXpath).click() el_vsys_path = port_listPage_linkTips_dropitem_vsysSelect_posXpath.format(replaceName=link_dst_vsys) # 下拉列表元素移动到页面显示,在执行js强制点击 element_item2 = self.driver.find_element(By.XPATH, el_vsys_path) # actions.move_to_element(element_item2).perform() # self.driver.execute_script("arguments[0].click();", element_item2) self.driver.execute_script("arguments[0].scrollIntoView();", element_item2) element_item2.click() # 点击 保存 if link_index == 0: self.driver.find_element(By.XPATH, port_listpage_linkSave_posXpath).click() else: self.driver.find_element(By.XPATH, "//*[@id='clusterSave']/i").click() if link_index != link_count - 1: # 不是最后一个cluster 需要添加添加按钮 self.driver.find_element(By.XPATH, port_listpage_linkAdd_posXpath).click() # 点击 OK self.driver.find_element(By.XPATH, port_listpage_linkOk_posXpath).click() time.sleep(3) # 状态断言 status_info = "color: rgb(141, 203, 75);" rows = self.driver.find_element(By.XPATH, port_listPage_objectTable_tableTbody_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") print(status_style) pytest_check.is_in(status_info, status_style, msg="所在行数{}".format(inspect.currentframe().f_lineno)) time.sleep(1) self.driver.isElementExist( Element='((//div[@class!="itemDetails cursor"]//table[@class="el-table__body"])[1]//tr)[1]') # 查看第一行是否存在数据 if self.driver.Exist: # 展示所有列 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 time.sleep(1) all_checked_xpath = '//*[@class="all-btn"]//*[@class="el-checkbox__input is-checked"]' if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 time.sleep(1) self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_Cancel_Button_posXpath).click() # 点击Cancel按钮 else: time.sleep(1) self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # 全选 time.sleep(1) self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按钮 Des_ID_list = [] Sou_ID_list = [] Sou_IDS = self.driver.find_elements(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr//td[count(//div[@class='el-table__header-wrapper']//span[text()='Source ID']/../../../preceding-sibling::th)+1]//span[@class='table-hide']") for Sou_ID in Sou_IDS: Sou_ID_list.append(Sou_ID.text) print(Sou_ID_list) # 获取所有Dst ID Dst_IDs = self.driver.find_elements(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr//td[count(//div[@class='el-table__header-wrapper']//span[text()='Destination ID']/../../../preceding-sibling::th)+1]//span") for Dst_ID in Dst_IDs: Des_ID_list.append(Dst_ID.text) print(Des_ID_list) # 获取Request_ID Request_ID = self.driver.find_element(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr[1]//td[count(//div[@class='el-table__header-wrapper']//span[text()='Request ID']/../../../preceding-sibling::th)+1]//span").text return Des_ID_list, Request_ID, Sou_ID_list def _del_policy_links(self, Request_ID): username = self.driver.find_element(By.XPATH, '//*[@id="user_avator"]/span').text if username == "admin": loginout = LogInOut(self.driver) loginout.logout() time.sleep(1) loginout.login_other(url="http://192.168.44.72/#/login", username="guouitest", passwd="jMIfnvhc1U") else: pass # 跳转至Federation-Policy Links # 点击Menu按钮 self.driver.find_element(By.CSS_SELECTOR, mainPage_button_menu_posXCss).click() # 点击Admin area self.driver.find_element(By.XPATH, mainPage_navigationBar_Menu_adminArea_posXpath).click() # 点击Federation self.driver.find_element(By.XPATH, mainPage_firstLevelMenu_federation_posXpath).click() # 点击policy links self.driver.find_element(By.XPATH, mainPage_secondLevelMenu_policy_link_posXpath).click() # 点击输入框 self.driver.find_element(By.ID, mainPage_common_search_selectLabel_posId).click() # 选择查询方式为Request ID,输入Request ID self.driver.find_element(By.XPATH, federation_policy_link_drop_requestID_posXpath).click() self.driver.find_element(By.XPATH, federation_policy_link_input_value_posXpath).send_keys(Request_ID) # 点击搜索 self.driver.find_element(By.ID, listPage_federation_policy_link_buttonSearch_posId).click() # 删除Policy Links记录 self.driver.find_element(By.XPATH, federation_policy_link_all_select_posXpath).click() self.driver.find_element(By.ID, federation_policy_link_list_button_delete_posId).click() self.driver.find_element(By.XPATH, federation_policy_link_delete_yes_posXpath).click() # 校验no data文本 self.driver.implicitly_wait(5) self.driver.isElementExist(Element=url_listPage_noDataText_posXpath) no_data_elem = self.driver.Exist print("No Data {}".format(no_data_elem)) def click_sync(self, Request_ID): username = self.driver.find_element(By.XPATH, '//*[@id="user_avator"]/span').text if username == "admin": loginout = LogInOut(self.driver) loginout.logout() time.sleep(1) loginout.login_other(url="http://192.168.44.72/#/login", username="guouitest", passwd="jMIfnvhc1U") else: pass # 跳转至Federation-Policy Links # 点击Menu按钮 self.driver.find_element(By.CSS_SELECTOR, mainPage_button_menu_posXCss).click() # 点击Admin area self.driver.find_element(By.XPATH, mainPage_navigationBar_Menu_adminArea_posXpath).click() # 点击Federation self.driver.find_element(By.XPATH, mainPage_firstLevelMenu_federation_posXpath).click() # 点击policy links self.driver.find_element(By.XPATH, mainPage_secondLevelMenu_policy_link_posXpath).click() # 点击输入框 self.driver.find_element(By.ID, mainPage_common_search_selectLabel_posId).click() # 选择查询方式为Request ID,输入Request ID self.driver.find_element(By.XPATH, federation_policy_link_drop_requestID_posXpath).click() time.sleep(1) self.driver.find_element(By.XPATH, federation_policy_link_input_value_posXpath).send_keys(Request_ID) # 点击搜索 self.driver.find_element(By.ID, listPage_federation_policy_link_buttonSearch_posId).click() time.sleep(1) ele = self.driver.find_element(By.XPATH, federation_policy_link_list_first_button_sync_posId) # self.driver.execute_script("arguments[0].style.zIndex = '999'", ele) ele.click() # self.driver.execute_script("arguments[0].click()", ele) time.sleep(1) self.driver.isElementExist( Element='((//div[@class!="itemDetails cursor"]//table[@class="el-table__body"])[1]//tr)[1]') # 查看第一行是否存在数据 time.sleep(1) if self.driver.Exist: # 展示所有列 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_posXpath).click() # 点击列设置 all_checked_xpath = '//*[@class="all-btn"]//*[@class="el-checkbox__input is-checked"]' if self.driver.element_isExist(By.XPATH, all_checked_xpath): # 如果全选被选中 time.sleep(1) self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_Cancel_Button_posXpath).click() # 点击Cancel按钮 else: self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_select_allCheckBox_posXpath).click() # 全选 self.driver.find_element(By.XPATH, mainPage_ObjectSearch_Column_settings_click_OK_Button_posXpath).click() # 点击OK按钮 time.sleep(1) Request_ID = self.driver.find_element(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr[1]//td[count(//div[@class='el-table__header-wrapper']//span[text()='Request ID']/../../../preceding-sibling::th)+1]//span").text return Request_ID def only_linkdata(self, link_list_dict, port_listpage_linkButton_posId, port_listpage_linkSave_posXpath, port_listpage_linkAdd_posXpath, port_listpage_linkOk_posXpath): """ :param link_dict: [{"link_dst_cluster": "42.49-User4Link", "link_dst_vsys":"Vsys2test"}] :param link_dst_cluster: :param link_dst_vsys: :return: """ # 点击 link 按钮 # {"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, port_listpage_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"] link_dst_vsys = link_list_dict[link_index]["link_dst_vsys"] # 选择cluster self.driver.find_element(By.XPATH, port_listPage_linkTips_input_clusterSelect_posXpath).click() el_cluster_path = port_listPage_linkTips_dropitem_clusterDrop_posXpath.format(replaceName=link_dst_cluster) # 下拉列表元素移动到页面显示,在执行js强制点击 actions = ActionChains(self.driver) element_item = self.driver.find_element(By.XPATH, el_cluster_path) actions.move_to_element(element_item).perform() self.driver.execute_script("arguments[0].click();", element_item) # 选择vsys id self.driver.find_element(By.XPATH, port_listPage_linkTips_input_vsysSelect_posXpath).click() el_vsys_path = port_listPage_linkTips_dropitem_vsysSelect_posXpath.format(replaceName=link_dst_vsys) # 下拉列表元素移动到页面显示,在执行js强制点击 element_item2 = self.driver.find_element(By.XPATH, el_vsys_path) # actions.move_to_element(element_item2).perform() # self.driver.execute_script("arguments[0].click();", element_item2) self.driver.execute_script("arguments[0].scrollIntoView();", element_item2) element_item2.click() # 点击 保存 if link_index == 0: self.driver.find_element(By.XPATH, port_listpage_linkSave_posXpath).click() else: self.driver.find_element(By.XPATH, "//*[@id='clusterSave']/i").click() if link_index != link_count - 1: # 不是最后一个cluster 需要添加添加按钮 self.driver.find_element(By.XPATH, port_listpage_linkAdd_posXpath).click() # 点击 OK self.driver.find_element(By.XPATH, port_listpage_linkOk_posXpath).click() time.sleep(3) # 状态断言 status_info = "color: rgb(141, 203, 75);" rows = self.driver.find_element(By.XPATH, port_listPage_objectTable_tableTbody_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") print(status_style) pytest_check.is_in(status_info, status_style, msg="所在行数{}".format(inspect.currentframe().f_lineno)) Des_ID_list = [] Sou_ID_list = [] # 获取所有Sou ID Sou_IDS = self.driver.find_elements(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr//td[count(//div[@class='el-table__header-wrapper']//span[text()='Source ID']/../../../preceding-sibling::th)+1]//span") for Sou_ID in Sou_IDS: Sou_ID_list.append(Sou_ID.text) print(Sou_ID_list) # 获取所有Dst ID Dst_IDs = self.driver.find_elements(By.XPATH, "//div[contains(@class,'el-table__body-wrapper')]//tr//td[count(//div[@class='el-table__header-wrapper']//span[text()='Destination ID']/../../../preceding-sibling::th)+1]//span") for Dst_ID in Dst_IDs: Des_ID_list.append(Dst_ID.text) # 删除policy links记录 self.driver.find_element(By.XPATH, federation_policy_link_all_select_posXpath).click() self.driver.find_element(By.ID, federation_policy_link_list_button_delete_posId).click() self.driver.find_element(By.XPATH, federation_policy_link_delete_yes_posXpath).click() # 校验no data文本 self.driver.implicitly_wait(5) self.driver.isElementExist(Element=url_listPage_noDataText_posXpath) no_data_elem = self.driver.Exist print("No Data {}".format(no_data_elem)) return Sou_ID_list, Des_ID_list def screen_shot(self): formatted_time = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S') file = "{}.png".format(formatted_time) file_path = os.path.join(workdir, "results", "screenshot", file) file_path_work = os.path.join(workdir, "results", "screenshot") if not os.path.exists(file_path_work): os.makedirs(file_path_work) if not os.path.exists(file_path): print(f"截图保存于:{file_path}") self.driver.save_screenshot(file_path) def different_vsys_check(self, obj_type, data): # vsys10中创建 self.object_operation(obj_type, "create", data) # 切换Vsys至Vsys0 self.profile_pub.change_vsys(vsys_name="vsys0") # 判断并处理data中必须唯的一字段 data = self.opr_unique_fields(data) # vsys0中创建 self.object_operation(obj_type, "create", data) # vsys_zero_object = self.extract_ele() try: # vsys0中查询 self.object_operation(obj_type, "query", data) self.view_check("vsys0") # 切换Vsys至Vsys3 self.profile_pub.change_vsys(vsys_name="PerformanceTestVsys") # vsys3中查询 self.object_operation(obj_type, "query", data) self.view_check("PerformanceTestVsys") # 切换Vsys至Vsys10 self.profile_pub.change_vsys(vsys_name="UIAutoTestVsys") # vsys10中查询 self.object_operation(obj_type, "query", data) self.view_check("UIAutoTestVsys") except Exception as e: raise e finally: # 清理测试数据 if obj_type == "tunnels": self.object_operation(obj_type, "delete_created_ip_bymself", data) # self.object_operation(obj_type, "delete", data) self.profile_pub.change_vsys(vsys_name="vsys0") self.object_operation(obj_type, "delete", data) def view_check(self, vsys_name): table_dict = self.extract_ele() time.sleep(1) total = self.driver.find_element(By.XPATH, "//div[@class='page-box-containcheck']//span[contains(text(),'Total')]").text count = total.split("Total:") if vsys_name == "PerformanceTestVsys": # vsys3中仅可查看Vsys0中的数据,而无Vsys10的数据 assert int(count[1]) == 1 and table_dict["Vsys ID"] == "0" # todo 需校验Vsys elif vsys_name == "vsys0": # Vsys0中可查看Vsys0中的数据,与Vsys10的数据 # abc = table_dict["Vsys ID"] assert int(count[1]) == 2 and table_dict["Vsys ID"] == "0", "校验失败!count={},VsysID={}".format( int(count[1]), table_dict["Vsys ID"]) self.driver.find_element(By.XPATH, listPage_second_row_checkBox_posXpat).click() # 选择第二行的checkbox(vsys10中创建的数据) self.driver.find_element(By.XPATH, listPage_viewButton_posXpath).click() # 点击View按钮 # 校验Vsys0下查看Vsys10的数据 assert len(self.driver.find_elements(By.XPATH, '//div[contains(@class,"IconBtn") and contains(@class," disabled-btn")]')) >= 3 is_ok_exist = self.driver.element_isExist(By.XPATH, ObjectDetailPage_mainOkButton_poXpath) assert is_ok_exist == False self.driver.find_element(By.XPATH, ObjectDetailPage_mainCancelButton_poXpath).click() # 点击Cancel 按钮 elif vsys_name == "UIAutoTestVsys": # Vsys10中可查看Vsys0中的数据,与Vsys10的数据 try: assert int(count[1]) == 2 and table_dict["Vsys ID"] == "0" self.driver.find_element(By.XPATH, listPage_first_row_checkBox_posXpath).click() # 选择第一行的checkbox(vsys0中创建的数据) self.driver.find_element(By.XPATH, listPage_viewButton_posXpath).click() # 点击View按钮 add_item_disable = self.driver.element_isExist(by=By.XPATH, value='(//div[contains(@class,"IconBtn") and contains(@class," disabled-btn")])[1]') edit_item_disable = self.driver.element_isExist(by=By.XPATH, value='(//div[contains(@class,"IconBtn") and contains(@class," disabled-btn")])[2]') del_item_disable = self.driver.element_isExist(by=By.XPATH, value='(//div[contains(@class,"IconBtn") and contains(@class," disabled-btn")])[3]') assert add_item_disable == edit_item_disable == del_item_disable == True self.driver.isElementExist(ObjectDetailPage_mainOkButton_poXpath) assert self.driver.Exist == False except Exception as e: raise e finally: # 清理Vsys10中的测试数据 self.driver.find_element(By.XPATH, ObjectDetailPage_mainCancelButton_poXpath).click() # 点击Cancel 按钮返回列表页 self.driver.find_element(By.XPATH, listPage_second_row_checkBox_posXpat).click() # 选择第二行的checkbox(vsys10中创建的数据) self.driver.find_element(By.XPATH, listPage_deleteButton_posXpath).click() # 点击Delete按钮 self.driver.find_element(By.XPATH, listPage_object_FQDNs_del_yes_Button_posXpath).click() # 删除确认弹窗中确认 def attr_audit_log_check(self, type, operation): # 点击audit Logs self.driver.find_element(By.XPATH, '//*[@id="id"]//div[@class="audit_log"]/span').click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() # 勾选第一行log CheckBox self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_compareButton_posXpath).click() # 点击compare 按钮 source_ip = self.loginout_parse.get("remote_url", "url").replace("http://", "").split(":")[ 0] # 获取字符串http://192.168.39.77:4444地址中的ip assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_version_posXpath).text != "", "断言版本不为空" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath).text == \ self.table_dict1["ID"] assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath).text == operation assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath).text == type assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath).text == source_ip assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath).text != "" assert self.loginout_parse.get("ui_account_1", "username") in self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath).text if operation == "Edit": self.driver.find_element(By.XPATH, '//*[@id="interceptionadd_allcancelobject10-_AuditLogs_anonymousComponent_Attribute_Home_App_anonymousComponent"]').click() self.driver.find_element(By.XPATH, '//*[@id="id"]//div[@class="audit_log"]/span').click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_compareButton_posXpath).click() # 点击compare 按钮 assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath + "[2]").text) assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath + "[1]").text == "Create" assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath + "[2]").text == "Edit" def sign_audit_log_check(self, type, operation): # 点击audit Logs self.driver.find_element(By.XPATH, '//*[@id="router-view-container"]//div[@class="audit_log"]/span').click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() # 勾选第一行log CheckBox self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_compareButton_posXpath).click() # 点击compare 按钮 source_ip = self.loginout_parse.get("remote_url", "url").replace("http://", "").split(":")[ 0] # 获取字符串http://192.168.39.77:4444地址中的ip assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_version_posXpath).text != "", "断言版本不为空" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath).text == \ self.table_dict1["ID"] assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath).text == operation assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath).text == type assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath).text == source_ip assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath).text != "" assert self.loginout_parse.get("ui_account_1", "username") in self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath).text if operation == "Edit": self.driver.find_element(By.XPATH, '//*[@id="interceptionadd_allcancelobject10-_AuditLogs_anonymousComponent_VPanel_VEditPanel_ApplicationSignaturesAdd_Home_App_anonymousComponent"]').click() self.driver.find_element(By.XPATH, '//*[@id="router-view-container"]//div[@class="audit_log"]/span').click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_compareButton_posXpath).click() # 点击compare 按钮 assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath + "[2]").text) assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath + "[1]").text == "Create" assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath + "[2]").text == "Edit" def opr_unique_fields(self, data): # ASN不可重复 try: data_asn = data["ASN"] if data_asn or data_asn == '': # 存在ans data_asn = self.my_random.random_asn() data["ASN"] = data_asn except: pass # # 其他条件 # try: # pass # except: # pass return data def audit_log_view(self, object_type, import_verify=1, export_verify=1): user_name = self.loginout_parse.get("ui_account_1", "username") self.driver.find_element(By.XPATH, mainPage_firstLevelMenu_System_posXpath).click() self.driver.find_element(By.XPATH, mainPage_secondLevelMenu_auditLogs_posXpath).click() time.sleep(3) self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).click() ###校验["Create", "Edit", "Delete", "Import", "Query Verbose"] # 选择Targrt ID if object_type in ["Signature", "Application", "Attribute"]: self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).send_keys(self.table_dict1["UUID"] + Keys.ENTER) self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_TagrgetID_posXpath).click() else: self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).send_keys(self.table_dict["UUID"] + Keys.ENTER) self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_TagrgetID_posXpath).click() # 选择Target Type self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).click() self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_TargetType_posXpath).click() scrollable_div = self.driver.find_element(By.XPATH,f"//ul[@class='base-Popper-root MuiSelect-listbox Mui-expanded css-1wd16dk']//li[text()='{object_type}']") self.driver.execute_script("arguments[0].scrollIntoView();", scrollable_div) scrollable_div.click() # 选择当前用户 # self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).click() # self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).send_keys(user_name) # self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_UserName_posXpath).click() # time.sleep(2) # element_user_name = self.driver.find_element(By.XPATH,f"//div[@x-placement='bottom-start']//span[text()='{user_name}']") # self.driver.execute_script("arguments[0].click()", element_user_name) # 强制点击搜索出来的Name # 搜索 self.driver.find_element(By.XPATH, listPage_auditlogSearch_buttonSearch_posXpath).click() # 搜索 assert len(self.driver.find_elements(By.XPATH,"//div[@data-field='op_type']//span[text()='Create']")) == 1,"Create日记大于1" assert len(self.driver.find_elements(By.XPATH,"//div[@data-field='op_type']//span[text()='Edit']")) >= 1,"Edit日志大于1" assert len(self.driver.find_elements(By.XPATH,"//div[@data-field='op_type']//span[text()='Delete']")) == 1,"Delete日志大于1" time.sleep(1) operation_text_elements = self.driver.find_elements(By.XPATH,"//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='op_type']") if import_verify == 1: operation = ["Create", "Edit", "Delete", "Import", "Query Verbose"] else: operation = ["Create", "Edit", "Delete", "Query Verbose"] operation_text = [] for i in range(1,len(operation_text_elements)+1): text = self.driver.find_element(By.XPATH,f"(//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='op_type']/span)[{i}]").text operation_text.append(text) self.check_audit_log_detail("0") if set(operation_text) != set(operation): raise Exception("存在未记录日志") ###校验["Export","Query List"] # 清除筛选框 # search_clear_btn = self.driver.find_element(By.XPATH,listPage_auditlogSearch_input_posXpath) # self.driver.execute_script("arguments[0].scrollIntoView();", search_clear_btn) # search_clear_btn.click() self.driver.find_element(By.XPATH, '//span[text()="Audit Logs"]').click() self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).click() self.driver.find_element(By.XPATH, listPage_auditlogSearch_select_TargetType_posXpath).click() scrollable_div = self.driver.find_element(By.XPATH,f"//ul[@class='base-Popper-root MuiSelect-listbox Mui-expanded css-1wd16dk']//li[text()='{object_type}']") self.driver.execute_script("arguments[0].scrollIntoView();", scrollable_div) scrollable_div.click() # 选择当前用户 # self.driver.find_element(By.XPATH, listPage_auditlogSearch_input_posXpath).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.XPATH, listPage_auditlogSearch_buttonSearch_posXpath).click() time.sleep(7) operation_text_elements = self.driver.find_elements(By.XPATH,"//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='op_type']") other_operation_text = [] if export_verify == 1: other_operation = ["Export", "Query List"] else: other_operation = ["Query List"] for i in range(len(operation_text_elements)): text = self.driver.find_element(By.XPATH,f"(//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='op_type'])[{i + 1}]").text other_operation_text.append(text) self.check_audit_log_detail("1") print(other_operation_text, set(other_operation_text), len(operation_text_elements)) assert other_operation in set(other_operation_text) def check_audit_log_detail(self, type): if type == "0": # 首次对operation = ["Create", "Edit", "Delete", "Import", "Query Verbose"]的校验 detaile_elements = self.driver.find_elements(By.XPATH, "//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='details']") for i in range(1,len(detaile_elements)): detaile_text = self.driver.find_element(By.XPATH, f"(//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='details'])[{i + 1}]").text self.driver.find_element(By.XPATH, f"(//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='details'])[{i + 1}]").click() if detaile_text == "Compare": compare_verision = self.driver.find_elements(By.XPATH, "//div[@class='overflow-hidden']//tbody//tr") assert len(compare_verision) != 0, "Compare存在修改信息" elif detaile_text == "View": assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath1).text != "" self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() elif type == "1": # 对 other_operation = ["Export", "Query List"]的校验 detaile_elements = self.driver.find_elements(By.XPATH,"//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='details']") detaile_index = random.randint(1, len(detaile_elements)) self.driver.find_element(By.XPATH,f"(//div[@class='MuiDataGrid-virtualScrollerContent css-0']//div[@data-field='details'])[{detaile_index + 1}]").click() assert self.driver.find_element(By.XPATH,url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath1).text != "" assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath1).text != "" # self.driver.find_element(By.XPATH,"(//button[@id='test-compareHistorical-_system_PolicyConfigurationLog_Home_App_anonymousComponent']//span[normalize-space(text())='Compare'])[1]").click() # compare_verision = self.driver.find_elements(By.XPATH,"//div[@class='rm-content']//div[@class='el-table__body-wrapper is-scrolling-none']//tr[@class='el-table__row']") # assert len(compare_verision) != 0,"Compare存在修改信息" # self.driver.find_element(By.ID,"interceptionadd_allcancelobject10-_AuditLogs_system_PolicyConfigurationLog_Home_App_anonymousComponent").click() # self.driver.find_element(By.XPATH,"(//button[@id='test-compareHistorical-_system_PolicyConfigurationLog_Home_App_anonymousComponent']//span[normalize-space(text())='View'])[1]").click() # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath).text != "" # assert self.driver.find_element(By.XPATH,url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath).text !="" # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath).text != "" # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath).text != "" # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath).text != "" # assert self.driver.find_element(By.XPATH,ObjectDetailPage_audit_log_compare_user_posXpath).text != "" def verify_import_drawer_result(self, data_file_name): time.sleep(10) """ import 侧滑页面校验 :param data_file_name: :return: """ from collections import Counter value_pos = acc_ObjectDetailPage_importDrawer_importTipsValue_posXpath_template # 页面Import Tips中获取结果 valid_num = int(self.driver.find_element(By.XPATH, ObjectDetailPage_importDrawer_importTipsValue_Valid_posXpath).text) self.invalid_format_num = int(self.driver.find_element(By.XPATH,ObjectDetailPage_importDrawer_importTipsValue_InvalidFormat_posXpath).text) duplicate_within_file_num = int(self.driver.find_element(By.XPATH, ObjectDetailPage_importDrawer_importTipsValue_Duplicates_current_file_posXpath).text) duplicate_within_existing_num = int(self.driver.find_element(By.XPATH, ObjectDetailPage_importDrawer_importTipsValue_Duplicates_global_objects_posXpath).text) total_num = int(self.driver.find_element(By.XPATH,ObjectDetailPage_importDrawer_importTipsValue_Total_posXpath).text) # 页面 importTable中获取结果 failed_items_num_in_import_table = len(self.driver.find_elements(By.XPATH, ObjectDetailPage_importDrawer_importTable_Failed_items_posXpath)) total_num_in_import_table = int(self.driver.find_element(By.XPATH,ObjectDetailPage_importDrawer_importTable_Total_posXpath).text[6:]) # 文件中统计结果 with open(self.my_files._obj_files_path(file_name=data_file_name), "r", encoding='utf-8') as f: # 打开文件 lines = f.readlines() total_num_in_file = len(lines) # 对应total_num # 统计每行出现的次数 line_counts = Counter(lines) # 重复数据条数 duplicate_num_in_file = sum( count - 1 for count in line_counts.values() if count > 1) # 对应duplicate_within_file_num print(valid_num,total_num,duplicate_within_file_num,self.invalid_format_num,total_num_in_file,duplicate_num_in_file,self.invalid_format_num,total_num_in_import_table,failed_items_num_in_import_table) # 对比结果 assert valid_num == total_num - (duplicate_within_file_num + self.invalid_format_num) == total_num_in_file - ( duplicate_num_in_file + self.invalid_format_num) == total_num_in_import_table - failed_items_num_in_import_table def audit_log_check(self, type, operation): # 点击audit Logs self.driver.find_element(By.XPATH, main_button_audit_button_posXpath).click() if operation == 'Create': assert len(self.driver.find_elements(By.XPATH,"//div[@class='el-table__body-wrapper is-scrolling-none']//tbody/tr")) == 1 elif operation == 'Edit': assert len(self.driver.find_elements(By.XPATH,"//div[@class='el-table__body-wrapper is-scrolling-none']//tbody/tr")) == 2 self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() # 勾选第一行log CheckBox self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_compareButton_posXpath).click() # 点击compare 按钮 source_ip = self.loginout_parse.get("remote_url", "url").replace("http://", "").split(":")[ 0] # 获取字符串http://192.168.39.77:4444地址中的ip if source_ip == 'localhost': source_ip = str(socket.gethostbyname(socket.gethostname())) assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_version_posXpath).text != "", "断言版本不为空" if type == "Application Object": assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath).text == \ self.table_dict1["ID"] else: assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath).text == \ self.table_dict["ID"] # 页面获取元素文本 operation_text = self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath).text type_text = self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath).text source_ip_text = self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath).text time_text = self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath).text user_text = self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath).text assert operation_text == operation, "校验失败!预期:{},页面实际:{}".format(operation, operation_text) assert type_text == type, "校验失败!预期:{},页面实际:{}".format(type, type_text) assert source_ip_text == source_ip, "校验失败!预期:{},页面实际:{}".format(source_ip, source_ip_text) assert time_text != "", "校验失败!页面实际:{}".format(time_text) user_name = self.loginout_parse.get("ui_account_1", "username") assert user_name in user_text, "校验失败!预期:{},页面实际:{}".format(user_name, user_text) # assert self.driver.find_element(By.XPATH, # url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath).text == operation # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath).text == type # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath).text == source_ip # assert self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_time_posXpath).text != "" # assert self.loginout_parse.get("ui_account_1", "username") in self.driver.find_element(By.XPATH, # ObjectDetailPage_audit_log_compare_user_posXpath).text if operation == "Edit": self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_cancel_posXpath).click() self.driver.find_element(By.XPATH, main_button_audit_button_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_firstRowLog_checkBox_posXpath).click() self.driver.find_element(By.XPATH, acc_ObjectDetailPage_auditLogsDrawer_compareButton_posXpath).click() # 点击compare 按钮 assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_id_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_type_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_ip_posXpath + "[2]").text) assert (self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath + "[1]").text == self.driver.find_element(By.XPATH, ObjectDetailPage_audit_log_compare_user_posXpath + "[2]").text) assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath + "[1]").text == "Create" assert self.driver.find_element(By.XPATH, url_ObjectDetailPage_auditLogsDrawer_compareDrawer_operationText_posXpath + "[2]").text == "Edit" def verify_obj_reference_count(self, button_disabled): reference_count_elem_posXpath = '(//div[contains(@class,"obj-charts-btn") and text()>0])[last()]' count = self.driver.find_element(By.XPATH, reference_count_elem_posXpath).text # 点击reference count self.driver.find_element(By.XPATH, reference_count_elem_posXpath).click() # 点击reference count,弹出侧滑页面 # 校验reference count usage_policies_elems = self.driver.find_elements(By.XPATH, listPage_referenceCount_drawerList_ruleOrObject_posXpaths) usage_count = len(usage_policies_elems) # print(usage_count, count) assert int(usage_count) == int(count), "reference count数目不匹配!!!{}--{}".format(usage_count, count) edit_button_pos = '//button[@id="objectEdit_slider" and @disabled="disabled"]' if button_disabled: # 引用条目不可点击,Edit按钮不可点击 # 校验权限 is_item_disabled = self.driver.element_isExist(By.XPATH, listPage_referenceCount_drawerList_disabledRuleOrObject_posXpaths) is_button_disabled = self.driver.element_isExist(By.XPATH, edit_button_pos) assert is_button_disabled == button_disabled == is_item_disabled, "校验失败!Edit按钮是否可点击预期为{},实际为{}".format( button_disabled, is_button_disabled) else: # 校验权限 self.driver.find_element(By.XPATH, listPage_referenceCount_drawerList_ruleOrObject_posXpaths_template.format( 1)).click() # 点击第一个引用项目 is_button_disabled = self.driver.element_isExist(By.XPATH, edit_button_pos) assert is_button_disabled == button_disabled, "校验失败!Edit按钮是否可点击预期为{},实际为{}".format( button_disabled, is_button_disabled) # 验证页面跳转 self.driver.find_element(By.XPATH, '//button[@id="objectEdit_slider"]').click() # 点击EditButton,跳转至引用对象详情页 is_page_right = self.driver.element_isExist(By.XPATH, '//div[@class="panel-header"]') assert is_page_right, "校验失败!页面未成功开启!!" def add_sub_objects_by_search(self): # self.driver.implicitly_wait(5) while True: self.driver.isElementExist('//div[@class="EditDraw"]//div[@class="el-loading-mask"]') if not self.driver.Exist: break self.driver.find_element(By.XPATH, '//div[@data-desc="subObject"]/label').click() # 判断是否存在Subordinate Objects 下的"+"按钮 if self.is_element_clickable(acc_ObjectGroupDetailPage_subObjects_addButton_normalAdd_posXpath, "XPATH"): print("有数据新建") # 点击Subordinate Objects 下的"+"按钮 self.driver.find_element(By.XPATH, acc_ObjectGroupDetailPage_subObjects_addButton_normalAdd_posXpath).click() else: print("无数据新建") # 点击Subordinate Objects 下的"+"按钮 self.driver.find_element(By.XPATH, acc_ObjectGroupDetailPage_subObjects_addButton_newAdd_posXpath).click() # 侧滑页面搜索并添加对应Object self.driver.find_element(By.XPATH, urlGroup_ObjectDetailPage_subItemSearch_posXpath).send_keys("test_ui") self.driver.find_element(By.XPATH, urlGroup_ObjectDetailPage_subItemSearch_posXpath).send_keys(Keys.ENTER) self.driver.find_element(By.XPATH, url_ObjectDetailPage_firstUrlObject).click() # 选择第一个Object def global_delete_method(self, obj_type): # obj_and_posid = {"accounts":"Objects_account","flags":"Objects_flag"} if "link" in obj_type: return 0 objects = { "accounts": "Objects_account", "apns": "Objects_apn", "app_attributes": "Application_customizedAttr", "app_signatures": "Application_appSignatures", "applications": "Application_applications", "applicationgroups": "Application_appGroups", "asns": "Objects_asn", "categories": "Objects_fqdn_category", "flags": "Objects_flag", "fqdns": "Objects_fqdn", "geolocation": "Advanced/IP_Libraries", "http_signatures": "Objects_http_signature", "intervals": "Objects_interval", "ip_address": "Objects_ip", "keywords": "Objects_keywords", "moible_identities": "Objects_mobile_identity", "ports": "Objects_port", "subscriber_ids": "Objects_subscriberid", "tunnels": "Objects_tunnel", "urls": "Objects_url" } # if obj_type[-1] == "s": # obj_type = obj_type[0:-1] # Vsys切换 # 切换UI自动化使用vsys self.profile_pub.change_vsys(vsys_name=self.vsys_name) # 页面跳转 self.driver.find_element(By.ID, mainPage_firstLevelMenu_Objects_posId).click() try: is_leave_this_page_exist = self.driver.element_isExist(By.XPATH, asn_ObjectDetailPage_leaveThisPage_yesButton_posXpath) if is_leave_this_page_exist: self.driver.find_element(By.XPATH, asn_ObjectDetailPage_leaveThisPage_yesButton_posXpath).click() except: pass self.driver.find_element(By.ID, objects[obj_type]).click() # if objects[obj_type] == "Application_appGroups": # self.driver.find_element(By.ID, listPage_objectSearch_Attributes_selectLabel_posId).click() # 选中查询框 # self.driver.find_element(By.ID, listPage_objectSearch_app_group_select_Name_posId).click() # 选中Name # self.driver.find_element(By.XPATH, listPage_objectSearch_Attributes_input_Name_posXpath).send_keys( # ""test) # 输入Name # self.driver.find_element(By.ID, mainPage_ObjectSearch_buttonSearch_posId).click() # elif objects[obj_type] == "Application_applications": # self.driver.find_element(By.ID, listPage_objectSearch_Attributes_selectLabel_posId).click() # 选中查询框 # time.sleep(1) # self.driver.find_element(By.ID, application_search_by_name).click() # 选中Name # time.sleep(1) # self.driver.find_element(By.XPATH, listPage_objectSearch_Attributes_input_Name_posXpath).send_keys( # "test") # 输入Name # time.sleep(1) # self.driver.find_element(By.ID, mainPage_ObjectSearch_buttonSearch_posId).click() # elif objects[obj_type] == "Application_appSignatures": # self.driver.find_element(By.ID, listPage_objectSearch_Attributes_selectLabel_posId).click() # 选中查询框 # self.driver.find_element(By.ID, listPage_objectSearch_signature_select_Name_posId).click() # 选中Name # self.driver.find_element(By.XPATH, listPage_objectSearch_Attributes_input_Name_posXpath).send_keys("test") # self.driver.find_element(By.ID, mainPage_ObjectSearch_buttonSearch_posId).click() # elif objects[obj_type] == "Application_customizedAttr": # self.driver.find_element(By.ID, listPage_objectSearch_Attributes_selectLabel_posId).click() # 选中查询框 # self.driver.find_element(By.ID, listPage_objectSearch_Attributes_select_Name_posId).click() # 选中Name # self.driver.find_element(By.XPATH, listPage_objectSearch_Attributes_input_Name_posXpath).send_keys( # "test") # 输入Name # self.driver.find_element(By.ID, mainPage_ObjectSearch_buttonSearch_posId).click() # else: # # 简单筛选 # self.clear_name_by_id(listPage_auditlogSearch_input_posXpath) # objects_search_input_elem = self.wait.until( # EC.presence_of_element_located((By.ID, listPage_auditlogSearch_input_posXpath))) # objects_search_input_elem.send_keys("test") # self.wait.until( # EC.presence_of_element_located( # (By.XPATH, '//div[contains(@x-placement,"bottom-start")]//span[text()="Name"]'))).click() # # objects_search_input_elem.send_keys(Keys.ENTER) # 确认输入框内容 # self.driver.find_element(By.ID, mainPage_ObjectSearch_buttonSearch_posId).click() # 点击搜索按钮 # 删除数据(删除第一页所有可删除的数据,循环loop_count次) delable_objs_exist = self.driver.element_isExist(By.XPATH, listPage_object_tableCheckbox_localVsysAndReferenceEqualO_objectOrGroup_posXpaths) ## 列表页中本Vsys的Object 或Group(不包含其他Vsys)且Reference Count==0 loop_count = 5 while loop_count > 0 and delable_objs_exist: try: time.sleep(1) delable_objs = self.driver.find_elements(By.XPATH, listPage_object_tableCheckbox_localVsysAndReferenceEqualO_objectOrGroup_posXpaths) ## 列表页中本Vsys的Object 或Group(不包含其他Vsys)且Reference Count==0 if len(delable_objs) == 0: break else: for i in range(len(delable_objs)): try: # 使用显式等待确保元素可点击 element = self.wait.until(EC.presence_of_element_located((By.XPATH, listPage_object_tableCheckbox_localVsysAndReferenceEqualO_objectOrGroup_posXpaths_template.format( i + 1)))) self.driver.execute_script("arguments[0].scrollIntoView();", element) element.click() except StaleElementReferenceException: # 如果发生StaleElementReferenceException,重新获取元素并尝试点击 delable_objs = self.driver.find_elements(By.XPATH, listPage_object_tableCheckbox_localVsysAndReferenceEqualO_objectOrGroup_posXpaths) ## 列表页中本Vsys的Object 或Group(不包含其他Vsys)且Reference Count==0 delable_objs[i].click() self.common_delete() finally: loop_count -= 1 def policy_create(self, object_type, rule, rule_element): self.driver.implicitly_wait(5) # try: # self.driver.find_element(By.XPATH, '//span[text()="{}"]'.format(rule_element)).click() # except: if rule == "Security": self.driver.find_element(By.XPATH, "//span[text()='Policies']").click() else: pass self.driver.find_element(By.XPATH, '//span[text()="{}"]'.format(rule_element)).click() self.driver.find_element(By.XPATH, listpage_create_button_posXpath).click() self.driver.find_element(By.XPATH, ObjectDetailPage_input_Name_posXpath).send_keys("test_policy") self.get_policy_conditions(object_type) if rule == "Statistics": self.driver.find_element(By.XPATH,statistics_policy_template_add_button_posXpath).click() time.sleep(2) self.driver.find_element(By.XPATH,statistics_policy_template_first_template_posXpath).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() # self.driver.execute_script("arguments[0].click()", first_statistics_template) # self.driver.find_element(By.XPATH,"//div[@class='FlagList list-box']//span[normalize-space(text())='Close']").click() elif rule == "DoS Protection": self.driver.find_element(By.XPATH, '//div[@class="dos-protection-policy-group_by"]//button').click() self.driver.find_element(By.XPATH, '//div[@class="dos-protection-policy-group_by"]//ul[@role="listbox"]/li[1]').click() self.driver.find_element(By.XPATH, '//div[@class="dos-protection-policy-concurrent_sessions"]//input').send_keys("1") self.driver.find_element(By.XPATH, '//button[text()="None"]').click() elif rule == "Intercept": time.sleep(1) self.driver.find_element(By.XPATH,'//label[normalize-space(text())="Application"]/ancestor::div[@class="intercept-policy-application"]//button/i').click() self.driver.find_element(By.XPATH, "//span[normalize-space(text())='http']").click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() # self.driver.find_element(By.XPATH,"//div[@class='AppList list-box']//span[normalize-space(text())='Close']").click() self.driver.find_element(By.XPATH, '//label[normalize-space(text())="TCP Proxy Profile"]/following-sibling::div//button/i').click() self.driver.find_element(By.XPATH, statistics_policy_template_first_template_posXpath).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() elif rule == "Shaping": self.driver.find_element(By.XPATH,shaping_policy_profile_add_button_posXpath).click() self.driver.find_element(By.XPATH,statistics_policy_template_first_template_posXpath).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() # self.driver.find_element(By.XPATH,"//div[@class='SFFList list-box']//span[normalize-space(text())='Close']").click() elif rule == "Service Chaining": self.driver.find_element(By.XPATH,service_chaining_policy_ssf_add_button_posID).click() self.driver.find_element(By.XPATH,statistics_policy_template_first_template_posXpath).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() # self.driver.find_element(By.XPATH,"//div[@class='SFFList list-box']//span[normalize-space(text())='Close']").click() scrollable_div = self.driver.find_element(By.XPATH, '//label[normalize-space(text())="Enabled"]/following-sibling::div/span') self.driver.execute_script("arguments[0].scrollIntoView();", scrollable_div) self.driver.find_element(By.XPATH, '//label[normalize-space(text())="Enabled"]/following-sibling::div/span').click() self.driver.find_element(By.XPATH, '//button[text()="OK"]').click() def get_policy_conditions(self, object_type): if object_type == "ip_address": self.driver.find_element(By.XPATH, "(//div[@class='MultipleSelect SourceSelect'])[1]").click() elif object_type == "fqdns": self.driver.find_element(By.XPATH, policy_button_add_contions_posXpath).click() self.driver.find_element(By.XPATH,policy_list_add_contions_posXpath.format(replaceValue='Server FQDN')).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() self.driver.find_element(By.XPATH, policy_button_type_add_contions_posXpath.format(replaceValue="Server FQDN")).click() elif object_type == "subscriber_ids": self.driver.find_element(By.XPATH, policy_button_add_contions_posXpath).click() self.driver.find_element(By.XPATH, policy_list_add_contions_posXpath.format(replaceValue='User')).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() self.driver.find_element(By.XPATH,policy_button_type_add_contions_posXpath.format(replaceValue="User")).click() elif object_type == "imsi" or object_type == "phone_number" or object_type == "imei" or object_type == "apn": self.driver.find_element(By.XPATH, policy_button_add_contions_posXpath).click() self.driver.find_element(By.XPATH, policy_list_add_contions_posXpath.format(replaceValue='Device')).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() self.driver.find_element(By.XPATH,policy_button_type_add_contions_posXpath.format(replaceValue="Device")).click() if object_type == "phone_number": self.driver.find_element(By.XPATH,"//div[@class='el-tabs__header is-top']//div[text()='Phone Number']").click() else: self.driver.find_element(By.XPATH,f"//button[text()='{object_type.upper()}']").click() elif object_type == "keywords": self.driver.find_element(By.XPATH, policy_button_add_application_posXpath).click() self.driver.find_element(By.XPATH,"//ul[@class='row-container tableList apptableList']//span[text()='http']").click() self.driver.find_element(By.XPATH, policy_button_add_contions_posXpath).click() self.driver.find_element(By.XPATH,policy_list_add_contions_posXpath.format(replaceValue='Request Body')).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() self.driver.find_element(By.XPATH,policy_button_add_filter_psXpath.format(replaceValue='Request Body')).click() elif object_type == "http_signatures": self.driver.find_element(By.XPATH, policy_button_add_application_posXpath).click() self.driver.find_element(By.XPATH,"//ul[@class='row-container tableList apptableList']//span[text()='http']").click() self.driver.find_element(By.XPATH, policy_button_add_contions_posXpath).click() self.driver.find_element(By.XPATH,policy_list_add_contions_posXpath.format(replaceValue='Request Header')).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() self.driver.find_element(By.XPATH,policy_button_add_filter_psXpath.format(replaceValue='Request Header')).click() elif object_type == "ports": self.driver.find_element(By.XPATH, policy_button_add_contions_posXpath).click() self.driver.find_element(By.XPATH, policy_list_add_contions_posXpath.format(replaceValue='Port')).click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() self.driver.find_element(By.XPATH, policy_button_add_filter_psXpath.format(replaceValue='Port')).click() self.driver.find_element(By.XPATH,'//input[@class="MuiInput-input css-za5rna"]').send_keys(self.table_dict["Name"] + Keys.ENTER) self.driver.find_element(By.XPATH, '//ul[@class="MuiList-root MuiList-vertical MuiList-variantPlain MuiList-colorNeutral MuiList-sizeMd css-1cklc3"]/li[1]').click() self.driver.find_element(By.XPATH, '//i[@class="iconfont icon-Clear_aNormal close-icon"]').click() # self.driver.find_element(By.XPATH,"//div[@class='SourceList list-box']//span[normalize-space(text())='Close']").click() def policy_delete(self,rule_element): self.driver.implicitly_wait(5) self.driver.find_element(By.XPATH, "//span[text()='Policies']").click() self.driver.find_element(By.XPATH, '//span[text()="{}"]'.format(rule_element)).click() time.sleep(3) self.driver.find_element(By.XPATH, listpage_search_input_posXpath).click() self.driver.find_element(By.XPATH,listpage_search_input_posXpath).send_keys("test_policy") self.driver.find_element(By.XPATH, listPage_objectSearch_select_Name_posXpath).click() self.driver.find_element(By.XPATH, listpage_search_button_posXpath).click() time.sleep(2) self.driver.find_element(By.XPATH,listPage_select_first_object_posXpath).click() self.driver.find_element(By.XPATH,listpage_delete_button_posXpath).click() self.driver.find_element(By.XPATH,listpage_delete_yes_button_posXpath).click() # path = my_files._obj_files_dowload_path() # 替换为你的路径 # txt_filenames = get_txt_filenames(path) # print(txt_filenames)