测试数据的准备分为三类
通过Excel读取数据
https://www.jianshu.com/p/2c85ed6f5d02
通过数据库读取数据
https://www.jianshu.com/p/b53dbe72866f
通过代码程序随机生成测试数据
代码如下
author = 'damao'
from faker import Faker
import random
class RegistData(object):
def to_init_faker(self):
t = Faker(locale='zh_CN') # zh_CN 表示指定为中国
return t
def set_nickname_data(self):
"""随机生成昵称"""
f = self.to_init_faker()
# nkname = f.lexify()
nkname = f.name()
# print(nkname)
return nkname
def set_phone_data(self):
"""随机生成手机号"""
f = self.to_init_faker()
phone_nub = f.phone_number()
# print(phone_nub)
return phone_nub
def set_password_data(self):
# list = [chr(i) for i in range(65, 91)] + [chr(i) for i in range(97, 123)] + [bytes(i) for i in range(10)] # 大写字母+小写字母+数字
# SC = ('`','~','!','@','#','$','%','^','&','*','(',')','+','=','|','{','}',
# ':',';','\\','[',']','.','<','>','/','?','~','!','¥','……','(',')','—','|','{}','【】','‘',';','”','“',':','。',',','、','?')
# for s in SC:
# list.append(s)
# num = random.sample(list,10)
# str=''
# paswd = str.join(num) #将取出的十个随机数进行重新合并
# if not paswd[0].isdigit():
# print(paswd)
data_string = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?"
d = []
for i in range(8):
d.append(random.choice(data_string))
paswd = ''.join(d)
return paswd
# print(paswd)
if __name__ =="__main__":
a = RegistData()
a.set_nickname_data()
a.set_password_data()
a.set_phone_data()
实行结果如下:
C:\Python36\python3.exe C:/MYTEST/py_project/Appium_JDPE_Test/Data/regist_user_data.py
凌伟
216x{4+a
15515263168
Process finished with exit code 0
如何引用
只需要在对应的测试用例中导入,继承类即可使用
from Appium_JDPE_Test.Data import regist_user_data.RegistData
my_nickname = self.set_nickname_data() # 昵称
my_phone = self.set_phone_data() # 用户名
my_password = self.set_password_data() # 密码
网友评论