提交 32b561f1 authored 作者: 彭甘宇's avatar 彭甘宇

解决初始化异常问题,增加"新增用户"脚本;

上级 cdf4655f
from lib.login import *
def suite_setup():
wd = GSTORE['wd']
open_browser()
user_login("admin@pgy", "ub@123456", "csba")
enter_system()
enter_manage()
enter_user_manage()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
# wd.quit()
from lib.login import *
class UserAdd001:
name = 'user_add_001'
def teststeps(self):
wd = GSTORE['wd']
STEP(1, '点击新增按钮')
user_add = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='company-edmit-right']//span[contains(text(),'新增')]"))
)
user_add.click()
sleep(2)
STEP(2, '填写登录名')
account_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.XPATH, "//input[@placeholder='登录名以字母开头,长度在5-18之间,只能包含字母、数字和下划线、@']"))
)
account_input.clear()
account_input.send_keys("admin@test")
STEP(3, '填写用户名称')
account_name_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请输入用户名称']"))
)
account_name_input.clear()
account_name_input.send_keys("测试用户")
STEP(4, '填写新密码')
passwd_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//input[@placeholder='必须包含字母(不区分大小写)、数字和特殊字符,至少8个字符']"))
)
passwd_input.clear()
passwd_input.send_keys("ub@123456")
STEP(5, '填写确认密码')
sepasswd_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//input[@placeholder='请确认密码']"))
)
sepasswd_input.clear()
sepasswd_input.send_keys("ub@123456")
STEP(6, '点击确认')
commit = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='新增']//span[contains(text(),'确 定')]"))
)
commit.click()
STEP(7, '验证是否新增成功')
get_menu = WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '.el-message__content'))
)
get_menu1 = get_menu.text
CHECK_POINT('检查是否出现成功提示弹窗', get_menu1 == "操作成功!")
sleep(2)
class UserAdd002:
name = 'user_add_002'
def teststeps(self):
wd = GSTORE['wd']
STEP(1, '点击新增按钮')
user_add = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='company-edmit-right']//span[contains(text(),'新增')]"))
)
user_add.click()
sleep(2)
STEP(2, '填写登录名')
account_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.XPATH, "//input[@placeholder='登录名以字母开头,长度在5-18之间,只能包含字母、数字和下划线、@']"))
)
account_input.clear()
account_input.send_keys("admin@test")
STEP(3, '填写用户名称')
account_name_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请输入用户名称']"))
)
account_name_input.clear()
account_name_input.send_keys("测试用户")
STEP(4, '填写新密码')
passwd_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//input[@placeholder='必须包含字母(不区分大小写)、数字和特殊字符,至少8个字符']"))
)
passwd_input.clear()
passwd_input.send_keys("ub@123456")
STEP(5, '填写确认密码')
sepasswd_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//input[@placeholder='请确认密码']"))
)
sepasswd_input.clear()
sepasswd_input.send_keys("ub@123456")
STEP(6, '点击确认')
commit = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='新增']//span[contains(text(),'确 定')]"))
)
commit.click()
STEP(7, '验证是否正常提示')
get_menu = WebDriverWait(wd, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '.el-message__content'))
)
get_menu1 = get_menu.text
CHECK_POINT('检查是否出现错误提示弹窗', get_menu1 == "登录名已存在,请重新输入")
sleep(2)
# from lib.login import *
# def suite_setup():
# INFO('初始化浏览器')
# open_browser()
#
#
from lib.login import *
def suite_setup():
wd = GSTORE['wd']
open_browser()
# def suite_teardown():
# INFO('进行清除操作')
# wd = GSTORE['wd']
......
from selenium import webdriver
from hytest import *
import pandas as pd
import logging
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.edge.options import Options
from time import sleep
from selenium.common.exceptions import TimeoutException, ElementNotInteractableException
from time import sleep
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def open_browser():
INFO('打开浏览器')
# wd = webdriver.Chrome()
edge_options = Options()
edge_options.add_argument('--ignore-certificate-errors')
edge_options.add_argument('--disable-blink-features=AutomationControlled')
edge_options.add_argument('--allow-insecure-localhost')
wd = webdriver.Edge(options=edge_options)
GSTORE['wd'] = wd
# wd.get('https://rms.ubainsyun.com/#/login')
wd.get('https://192.168.1.118:8443/#/login')
wd.maximize_window()
wd.implicitly_wait(10)
......@@ -84,5 +89,61 @@ def main():
except Exception as e:
print(f"An error occurred: {e}")
def enter_system():
wd = GSTORE['wd']
INFO('点击系统设置按钮')
enter_sys = WebDriverWait(wd, 3).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'系统设置')]"))
)
enter_sys.click()
sleep(2)
def enter_system():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击系统设置按钮')
try:
enter_sys = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'系统设置')]"))
)
enter_sys.click()
logging.info('系统设置按钮已点击')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking system settings button: {error}")
def enter_manage():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击管理按钮')
try:
enter_mag = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='el-submenu__title']//span[contains(text(),'管理')]"))
)
enter_mag.click()
logging.info('管理按钮已点击')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
def enter_user_manage():
wd = GSTORE['wd']
if wd is None:
raise ValueError("WebDriver is not initialized")
logging.info('点击用户管理按钮')
try:
enter_user_mag = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'用户管理')]"))
)
enter_user_mag.click()
logging.info('用户管理按钮已点击')
except (TimeoutException, ElementNotInteractableException) as error:
logging.error(f"Error clicking manage button: {error}")
if __name__ == "__main__":
main()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论