1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import sys
import os
from hytest.common import SELENIUM_LOG_SCREEN
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *
# 构建 CSV 文件的绝对路径
csv_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', 'testdata', '08设备管理', '新增设备.csv'))
class AreafuntionAdd:
tag = ['新增设备']
ddt_cases = read_csv_data(csv_path)
def teststeps(self):
wd = GSTORE['wd']
#从self.para中解构出数据
name = self.name
area_group, area_type, area_name, area_ip, remark, info = self.para
STEP(1, '点击新增按钮')
areafuntion_add = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable(
(By.XPATH, "//div[@class='company-edmit-right']//span[contains(text(),'新增')]"))
)
areafuntion_add.click()
sleep(1)
STEP(2, f'查找并选择区域分组:{area_group}')
if area_group:
area_group_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//div[@class='dialog_input']//input[@placeholder='请选择分组']"))
)
area_group_input.send_keys(area_group)
#默认选择第一个分组
areagroup_select = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(
By.XPATH, "//li[@class='el-cascader__suggestion-item']"))
)
sleep(1)
areagroup_select.click()
else:
print("group_name 为空,不执行选择区域分组的操作")
STEP(3, f'选择区域类型:{area_type}')
if area_type:
area_type_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//div[@class='dialog_input']//input[@placeholder='请选择区域类型']"))
)
area_type_input.send_keys(area_type)
#默认选择第一个区域类型
areatype_select = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//div[@x-placement='bottom-start']//ul[@class='el-scrollbar__view el-select-dropdown__list']"))
)
sleep(1)
areatype_select.click()
else:
print("area_type 为空,不执行选择区域类型的操作")
STEP(4, f'输入区域名称:{area_name}')
area_name_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//div[contains(@class,'dialog_input')]//input[contains(@placeholder,'请输入区域名称')]"))
)
area_name_input.clear()
area_name_input.send_keys(area_name)
STEP(5, f'填写IP地址:{area_ip}')
area_ip_input = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//input[@placeholder='IP地址']"))
)
area_ip_input.clear()
area_ip_input.send_keys(area_ip)
STEP(6, f'填写备注:{remark}')
funtion_remark = WebDriverWait(wd, 10).until(
EC.presence_of_element_located(
(By.XPATH, "//input[@placeholder='备注']"))
)
funtion_remark.clear()
funtion_remark.send_keys(remark)
STEP(7, '点击确认')
commit = WebDriverWait(wd, 10).until(
EC.element_to_be_clickable(
(By.XPATH, "//div[@aria-label='新增']//span[contains(text(),'确 定')]"))
)
commit.click()
STEP(8, '验证是否新增成功')
get_menu = WebDriverWait(wd, 10).until(
EC.visibility_of_element_located(
(By.CSS_SELECTOR, '.el-message__content'))
)
get_menu1 = get_menu.text
CHECK_POINT('检查是否出现成功提示弹窗', get_menu1 == info)
# 截图并保存
SELENIUM_LOG_SCREEN(wd, "50%")
sleep(1)
wd.refresh()