简单框架:
tool: pytest==3.6.0, pluggy0.6.0, allure-python-commons2.5.3 ,allure-pytest 2.5.3
formdata:
# author: Jingke
class Login():
def __init__(self):
self._loginOptions = None
self._password = None
self._loginEmail = None
self._deviceId = None
self._userName = None
self._profilePicUrl = None
@property
def loginOptions(self):
return self._loginOptions
@property
def password(self):
return self._password
@property
def deviceId(self):
return "ffffffff-c95b-47ce1"
@property
def userName(self):
return ""
@property
def profilePicUrl(self):
return ""
@property
def loginEmail(self):
return self._loginEmail
@loginEmail.setter
def loginEmail(self, val):
self._loginEmail = val
@password.setter
def password(self, val):
self._password = val
@loginOptions.setter
def loginOptions(self, val):
self._loginOptions = val
generat_login_data:
# author: Jingke
import json
from Test_login.login_tool.formdata import Login
data = Login()
data_req = {}
class Generat_login_data():
@classmethod
def generate_data(cls, email, password,loginOptions):
data_req["loginEmail"] = email
data_req["password"] = password
data_req["loginOptions"] = loginOptions
data_req["deviceId"] = data.deviceId
data_req["profilePicUrl"] = data.profilePicUrl
data_req["userName"] = data.userName
return json.dumps(data_req)
Test login
# author: Jingke
import requests
from Test_login.login_tool.header import header
from Test_login.login_tool.url import url
from Test_login.login_tool.generat_login_data import Generat_login_data
import time, datetime
from Test_login.login_tool.random_str import random_set
import allure
class login_request():
@classmethod
def request_login(cls, email, password, loginOptions):
a = Generat_login_data()
login_url = url["registerFromThirdPart"]
res = requests.post(login_url, data=a.generate_data(email, password, loginOptions), headers=header)
response_dict = res.json()
return response_dict
@allure.feature('Login')
@allure.story('LoginEmail')
@allure.severity('critical')
def test_one():
"test correct account"
one = login_request.request_login("wangjingke@papayamobile.cn", "111111", "papaya_login")
try:
one['resultCode'] == 1
except:
allure.attach(one['errorInfo'])
time.sleep(3)
@allure.feature('Login')
@allure.story('LoginEmail')
@allure.severity('critical')
def test_two():
"test wrong password"
two = login_request.request_login("wangjingke@papayamobile.cn", "123456", "papaya_login")
try:
two['resultCode'] == 200
except:
allure.attach(two['errorInfo'])
time.sleep(3)
@allure.feature('Login')
@allure.story('Login_create')
@allure.severity('critical')
def test_three():
"test create account with exist account"
three = login_request.request_login("wangjingke@papayamobile.cn", "123456", "papaya_create")
try:
three['resultCode'] == 200
except:
allure.attach(three['errorInfo'])
time.sleep(3)
@allure.feature('Login')
@allure.story('Login_create')
@allure.severity('critical')
def test_four():
"test create new account"
four = login_request.request_login("wangjingke@pqq.com", "123456", "papaya_create")
try:
four['resultCode'] == 1
except:
allure.attach(four['errorInfo'])
time.sleep(3)
@allure.feature('Login')
@allure.story('Login_create')
@allure.severity('critical')
def test_five():
"test create wrong format account"
date = datetime.datetime.now().day
sec = datetime.datetime.now().second
five = login_request.request_login("%d@%d.com" % (date, sec), "123456", "papaya_create")
try:
five['resultCode'] == 1
except:
allure.attach(five['errorInfo'])
time.sleep(3)
@allure.feature('Login')
@allure.story('Login_create')
@allure.severity('critical')
def test_six():
"test create wrong password format"
six = login_request.request_login("%s@qq.com" % (random_set()), "%s" % (random_set()), "papaya_create")
try:
assert six['resultCode'] == 1
except:
allure.attach(six['errorInfo'])
生成报告:
image.png
网友评论