diff options
| author | zhaokun <[email protected]> | 2024-11-28 16:50:57 +0800 |
|---|---|---|
| committer | zhaokun <[email protected]> | 2024-11-28 16:50:57 +0800 |
| commit | 83661e91f8abd64f6b0ecee8e9e69e784a72e5d8 (patch) | |
| tree | 1aa4b4365efdf9bed886056f3ba67c0941260b6b /support/ui_utils/profiles/create_lua_script.py | |
| parent | 06fa53634037ae81bfb5b24e97a48697061cb083 (diff) | |
| parent | c9deae84b3d26ca19242a95d8a8c9a18974bdcc9 (diff) | |
Diffstat (limited to 'support/ui_utils/profiles/create_lua_script.py')
| -rw-r--r-- | support/ui_utils/profiles/create_lua_script.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/support/ui_utils/profiles/create_lua_script.py b/support/ui_utils/profiles/create_lua_script.py new file mode 100644 index 000000000..03b29c452 --- /dev/null +++ b/support/ui_utils/profiles/create_lua_script.py @@ -0,0 +1,69 @@ +import os +import sys +import time +from selenium.webdriver.common.by import By +from support.ui_utils.element_position.profile_element_position import * +from datetime import datetime + +class CreateLuaScript: + def __init__(self, driver): + self.driver = driver + + def create_lua_script(self, data): + profile_name = data["name"] + self.driver.find_element(By.XPATH, tsgProxyScripts_input_Name_posXpath).clear() + self.driver.find_element(By.XPATH, tsgProxyScripts_input_Name_posXpath).send_keys(profile_name) + self.driver.find_element(By.XPATH, "//label[text()='Name']").click() + #页面其它选项操作 + self._operate_page(data, operation_type="create") + #点击OK + self.driver.find_element(By.XPATH, tsgProxyScripts_button_oK_posXpath).click() + if self.driver.is_element_exist_by_value(By.XPATH,tsgProxyScripts_button_warningSaveYes_posXpath): + self.driver.find_element(By.XPATH, tsgProxyScripts_button_warningSaveYes_posXpath).click() + + def _operate_page(self, data, operation_type="create"): + """ + 除name的其它选项操作,共创建、修改逻辑调用 + :param data: + :param operation_type: create modify。创建 修改时调用 + :return: + """ + if operation_type == "create": + data_index = 0 #新增数据索引 + else: + data_index = -1 #编辑数据索引 + no_modify = "不修改" + #File文件上传操作 + file = self._get_value_from_data(data, key="script", data_index=data_index) #解析file文件名称 + if file != no_modify: #判断修改时不修改时跳过操作。 + if file != "": + #上传文件 + create_file = data["script"].split("->")[data_index] # 提取上传文件绝对路径 + profile_path = os.path.dirname(os.path.abspath(__file__)) # ...support\ui_utils\profile + file_abs = os.path.join(profile_path, "profile_file", "tsg_proxy_scripts", create_file) + #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], file_abs) + self.driver.find_element(By.XPATH, tsgProxyScripts_input_runScripts_posXpath).send_keys(file_abs) + elif file == "" and data_index == -1: + element_del = self.driver.find_element(By.XPATH, "//div[@id='runScriptTitleUpload']//i[@class='el-icon-close']") + self.driver.execute_script("arguments[0].click()", element_del) #强制点击 + #maximum execution time 操作 + max_exec_time = self._get_value_from_data(data, key="max_exec_time", data_index=data_index) + if max_exec_time != no_modify: #修改操作时,不修改数据则跳过操作。 + self.driver.find_element(By.XPATH, tsgProxyScripts_input_maximumExecutionTime_posXpath).clear() + #输入数据 + self.driver.find_element(By.XPATH, tsgProxyScripts_input_maximumExecutionTime_posXpath).send_keys(max_exec_time) + + def _get_value_from_data(self, data, key="", data_index=0): + """ + 从data数据中,根据key提取值 + :param data: + :param key: + :param data_index: 0 -1 + :return: + """ + try: + data_value: str = data[key].split("->")[data_index].strip().lower() #用例数据 + except Exception as e: + print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}", flush=True) + raise + return data_value
\ No newline at end of file |
