-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.py
226 lines (217 loc) · 11.3 KB
/
test_main.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import os
import sys
from datetime import date
import pytest
from framework.browser_engine import BrowserEngine
from framework.base_page import BasePage, UploadFile
from framework.send_email import send_email
import json
import allure
with open(os.getcwd() + "/config/url_info.json", encoding='utf-8') as f:
load_dict = json.load(f)
@allure.feature('验证演示环境各链接是否活跃')
class TestClass(object):
@classmethod
def setup_method(cls):
cls.browser = BrowserEngine()
cls.driver = BasePage(cls.browser.driver)
@classmethod
def teardown_method(cls):
cls.driver.quit_browser()
def test_upload(self):
url = '''https://element-plus.gitee.io/#/zh-CN/component/upload'''
btn = "x=>/html/body/div[1]/div/div[2]/div/div[1]/div/div/div[2]/div[1]/section/div[1]/div[1]/div/div/div[1]/button"
file_path = r'C:\Users\tianchenxu\Desktop'
file_name = '111.txt'
assert_element = "x=>/html/body/div[1]/div/div[2]/div/div[1]/div/div/div[2]/div[1]/section/div[1]/div[1]/div/div/ul/li[3]/a"
assert_str = "111.txt"
self.browser.open_browser(url)
self.driver.wait_element(20, 1, btn)
self.driver.click(btn)
# 强制等待 不然窗体未完全加载粘贴会失败
self.driver.sleep(3)
upload = UploadFile()
upload.upload_file(file_path, file_name)
# 强制等待 等待文件上传完毕
self.driver.sleep(3)
actual_str = self.driver.get_element_text(assert_element)
with allure.step("断言结果"):
allure.attach('期望结果:{}; 实际结果:{}'.format(assert_str, actual_str), "断言结论")
assert assert_str in actual_str, "failed!!! 预期结果:{}; 与实际结果不符:{}".format(assert_str, actual_str)
# def str_split(self, s):
# t = s.split('=>')[0]
# v = s.split('=>')[1]
# return t, v
#
# def verify(self, index, username, pwd, btn, ass_el):
# username_type, username_value = self.str_split(username)
# pwd_type, pwd_value = self.str_split(pwd)
# btn_type, btn_value = self.str_split(btn)
# username_text = load_dict[index]['account']
# pwd_text = load_dict[index]['pwd']
# assert_element = ass_el
# assert_element_type, assert_element_value = self.str_split(assert_element)
# assert_str = load_dict[index]['assert_str']
# '''
# 注意:
# 不直接使用变量driver作为wait_element()中driver参数,因为browser.driver为原始webDriver类型,变量driver类型为BasePage,
# 调用后续方法是会有限从内部方法中选取,内部存在find_element()时会与selenium库中方法冲突!!!
# '''
# self.browser.open_browser(load_dict[index]['url'])
# wait_element(self.browser.driver, 20, 1, username_type, username_value)
# self.driver.clear(username)
# self.driver.enter(username, username_text)
# wait_element(self.browser.driver, 20, 1, pwd_type, pwd_value)
# self.driver.clear(pwd)
# self.driver.enter(pwd, pwd_text)
# wait_element(self.browser.driver, 20, 1, btn_type, btn_value)
# self.driver.click(btn)
# wait_element(self.browser.driver, 30, 1, assert_element_type, assert_element_value)
# actual_str = self.driver.get_element_text(assert_element)
# with allure.step("断言结果"):
# allure.attach('期望结果:{}; 实际结果:{}'.format(assert_str, actual_str), "断言结论")
# assert assert_str in actual_str, "failed!!! 预期结果:{}; 与实际结果不符:{}".format(assert_str, actual_str)
#
# @allure.story(load_dict[0]['name'])
# def test_subject_demo(self):
# username = 'n=>username'
# pwd = 'n=>userpass'
# btn = 'c=>login-form-btn'
# assert_element = 'c=>logo'
# self.verify(0, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[1]['name'])
# def test_Northwest_University_demo(self):
# username = 'n=>username'
# pwd = 'n=>userpass'
# btn = 'c=>login-form-btn'
# assert_element = 'x=>/html/body/div[1]/div[2]/div[2]/div[1]/div[1]/div/span'
# self.verify(1, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[2]['name'])
# def test_Nankai_University_demo(self):
# username = 'n=>username'
# pwd = 'n=>userpass'
# btn = 'c=>login-form-btn'
# assert_element = 'x=>/html/body/div[1]/div[1]/div/div[1]/div/div/ul/li[1]/a/span/span[2]'
# self.verify(2, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[3]['name'])
# def test_China_Public_Security_University_demo(self):
# username = 'x=>/html/body/div/div/div/div[2]/div/form/div[1]/div/div[1]/input'
# pwd = 'x=>/html/body/div/div/div/div[2]/div/form/div[2]/div/div[1]/input'
# btn = 'x=>/html/body/div/div/div/div[2]/div/div/div/button'
# assert_element = 'x=>/html/body/div/div[1]/div/div[1]/div/div/ul/li[1]/a/span/span[2]'
# self.verify(3, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[4]['name'])
# def test_claim_demo(self):
# username = 'n=>form[user_name]'
# pwd = 'n=>form[user_pwd]'
# btn = 'c=>login-btn'
# assert_element = 'x=>/html/body/div[2]/div/ul/li[1]/a'
# self.verify(4, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[5]['name'])
# def test_Academic_libraries_demo(self):
# username = 'x=>/html/body/div/div[2]/div/div/div/div[2]/form/div[1]/input'
# username_type, username_value = self.str_split(username)
# username_text = load_dict[5]['account']
# pwd = 'x=>/html/body/div[1]/div[2]/div/div/div/div[2]/form/div[2]/input'
# pwd_type, pwd_value = self.str_split(pwd)
# pwd_text = load_dict[5]['pwd']
# btn = 'x=>/html/body/div/div[2]/div/div/div/div[2]/form/button'
# btn_type, btn_value = self.str_split(btn)
# self.browser.open_browser(load_dict[5]['url'])
# login_a = 'c=>sign-in'
# login_a_type, login_a_value = self.str_split(login_a)
# wait_element(self.browser.driver, 30, 1, login_a_type, login_a_value)
# self.driver.click(login_a)
# pwd_login_a = 's=>a[href="#password"]'
# pwd_login_a_type, pwd_login_a_value = self.str_split(pwd_login_a)
# wait_element(self.browser.driver, 30, 1, pwd_login_a_type, pwd_login_a_value)
# self.driver.es("arguments[0].click();", pwd_login_a)
# wait_element(self.browser.driver, 20, 1, username_type, username_value)
# self.driver.es("$('#username1').val('" + username_text + "');")
# wait_element(self.browser.driver, 20, 1, pwd_type, pwd_value)
# self.driver.es("$('#passwd1').val('" + pwd_text + "');")
# wait_element(self.browser.driver, 20, 1, btn_type, btn_value)
# self.driver.es("arguments[0].click();", btn)
# self.browser.open_browser(load_dict[5]['url'])
# assert_element = 'x=>/html/body/div[1]/div[1]/div[1]/div/span/span/a'
# assert_element_type, assert_element_value = self.str_split(assert_element)
# assert_str = load_dict[5]['assert_str']
# wait_element(self.browser.driver, 30, 1, assert_element_type, assert_element_value)
# actual_str = self.driver.get_element_text(assert_element)
# with allure.step("断言结果"):
# allure.attach('期望结果:{}; 实际结果:{}'.format(assert_str, actual_str), "断言结论")
# assert assert_str in actual_str, "failed!!! 预期结果:{}; 与实际结果不符:{}".format(assert_str, actual_str)
#
# @allure.story(load_dict[6]['name'])
# def test_Academic_map_demo(self):
# assert_element = 'c=>logo'
# assert_element_type, assert_element_value = self.str_split(assert_element)
# assert_str = load_dict[6]['assert_str']
# self.browser.open_browser(load_dict[6]['url'])
# wait_element(self.browser.driver, 30, 1, assert_element_type, assert_element_value)
# actual_str = self.driver.get_element_text(assert_element)
# with allure.step("断言结果"):
# allure.attach('期望结果:{}; 实际结果:{}'.format(assert_str, actual_str), "断言结论")
# assert assert_str in actual_str, "failed!!! 预期结果:{}; 与实际结果不符:{}".format(assert_str, actual_str)
#
# @allure.story(load_dict[7]['name'])
# def test_Research_assistant_demo(self):
# username = 'x=>/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[1]/input'
# pwd = 'x=>/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[2]/input'
# btn = 'x=>/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/button'
# assert_element = 'x=>/html/body/div[1]/div[1]/div/a'
# self.verify(7, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[8]['name'])
# def test_Traditional_Chinese_Medicine_University_Of_Guangzhou_demo(self):
# username = 'x=>/html/body/div[1]/div/div[1]/div[2]/div/form/div[1]/div/div[1]/input'
# pwd = 'x=>/html/body/div[1]/div/div[1]/div[2]/div/form/div[2]/div/div[1]/input'
# btn = 'x=>/html/body/div/div/div[1]/div[2]/div/div/div/button'
# assert_element = 'x=>/html/body/div[1]/div[1]/div[2]/div[2]/ul/li[1]/div/span/a'
# self.verify(8, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[9]['name'])
# def test_Beijing_Institute_of_Technology_demo(self):
# username = 'x=>/html/body/div/div/div[1]/div[2]/div/form/div[1]/div/div[1]/input'
# pwd = 'x=>/html/body/div/div/div[1]/div[2]/div/form/div[2]/div/div[1]/input'
# btn = 'x=>/html/body/div/div/div[1]/div[2]/div/div/div/button/span/span'
# assert_element = 'x=>/html/body/div[1]/div[2]/div[1]/div/ul/li[1]/a'
# self.verify(9, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[10]['name'])
# def test_Beijing_University_of_Posts_and_Telecommunications_demo(self):
# username = 'n=>username'
# pwd = 'n=>userpass'
# btn = 'c=>login-form-btn'
# assert_element = 'c=>header-left'
# self.verify(10, username, pwd, btn, assert_element)
#
# @allure.story(load_dict[11]['name'])
# def test_Sichuan_Vocational_College_of_Mechanical_and_Electrical_Technology_demo(self):
# username = 'n=>username'
# pwd = 'n=>userpass'
# btn = 'c=>login-form-btn'
# assert_element = 'c=>head_litterTitle'
# self.verify(11, username, pwd, btn, assert_element)
if __name__ == '__main__':
rq = str(date.today())
html_file = os.path.dirname(os.path.realpath(__file__)) + '/html/' + rq + "演示环境测试报告.html"
'''
"-v" 显示详细信息
"-q" 显示简要信息与-v相反
"-l" 显示失败用例详细信息(堆栈中局部变量及值)
"-m 【标记名称】" 只执行对应标记测试用例配合装饰器@pytest.mark.【标记名称】进行使用
"-x" 遇到用例失败直接结束执行,debug必备
"-s" 打印print函数输出
'''
pytest.main(["-q", "test_main.py", "--html=" + html_file, "--self-contained-html", "--alluredir=./result"])
try:
send_email(html_file)
print("发送成功")
except Exception as e:
print("发送失败", e)