首先需要使用python第三方模块
pip install pytest -i https://pypi.tuna.tsinghua.edu.cn/simple
安装之后cmd黑窗口输入pip list查看模块版本信息 打开pycharm软件配置环境 配置环境 我们newproject,然后创建文件夹,文件如图 在test_fw里面
from test_case.test_fw_login import *
from test_case.test_push_file import *
from test_case.test_edit_userinfo import *
class Test_Fw:
def setup_class(self):
self.s = test_fw_login()
print('前置操作')
def test_edit(self):
test_edit_userinfo(self.s)
def test_chongzhi(self):
test_push_file(self.s)
在test_fw_login
import requests
def test_fw_login():
url='http://106.52.182.140/fanwe/index.php?ctl=user&act=dologin&fhash=xGhwpLIiqHoEAAvNeWFnikycDaFmbPBKfBSxMoNkNXJPdoRBSO'
data={
'email' :'iop123',
'user_pwd' :'V2hrYmRzaXdhRG1ibFpaRnB5RXJKTGFoUmlvSFprWVlSdVZncEJDTm9yaW1QR0tNVnklMjV1NjVCOSUyNXU3RUY0aW9wMTIzJTI1dThGNkYlMjV1NEVGNg==',
'ajax': '1'
}
header={
'Host': '106.52.182.140',
'Origin': 'http://106.52.182.140',
'Referer': 'http://106.52.182.140/fanwe/index.php?ctl=user&act=login'
}
s=requests.session()
rq=s.post(url=url,data=data,headers=header)
rsp=rq.content.decode('unicode_escape')
print()
print(rsp)
return s
在test_edit_userinfo
import requests
from test_case.test_fw_login import test_fw_login
def test_edit_userinfo(s=None):
if s==None:
s=test_fw_login()
edit_url='http://106.52.182.140/fanwe/member.php?ctl=uc_account&act=save'
data_edit={
'avatar_file': '',
'graduation': '本科',
'university': 'wuhan',
'marriage': '已婚',
'province_id': '2',
'city_id': 52,
'address': 'lifengfanclub',
'phone': '17674128890-17674128890',
'commit': '保存更改'
}
edit_header={
'Referer': 'http://106.52.182.140/fanwe/member.php?ctl=uc_account'
}
rq=s.post(url=edit_url,data=data_edit,headers=edit_header)
print()
print('编辑个人资料接口的cookie{}'.format(s.cookies))
print(rq.text[315:345])
在test_push_file
import requests
from test_case.test_fw_login import test_fw_login
def test_push_file(s=None):
if s == None:
s = test_fw_login()
else:
pass
file_url = 'http://106.52.182.140/fanwe/file.php'
file_data = {
'a': 'do_upload',
'localUrl': r'C:\fakepath\lff1.png',
'm': 'File',
'upload_type': '0'
}
path = r'D:\softTest\Python\work\filework\work\lff1.png'
file = {
'imgFile': ('lff1.png', open(path, 'rb'), 'image/png')
}
file_header = {
'Referer': 'http://106.52.182.140/fanwe/member.php?ctl=uc_money&act=incharge'
}
rq = s.post(url=file_url, data=file_data, files=file, headers=file_header)
print()
print('上传文件接口的cookie{}'.format(s.cookies))
print(rq.text)
|