------------------------------------------------------------测试小黑--------------------------------------------------------------- 当你停止尝试的时候,就是失败的时候

python+unittest登录接口测试

上一篇 / 下一篇  2020-05-29 17:02:09 / 个人分类:坚持学习

id urlaccount password check
1/login  admin123456管理员
2/loginadmin123458密码错误
3/loginadmin23123456账号不存在

m4hnP3hP7h/Q0
以上excel数据
# -*- coding:utf-8 -*-
import unittest
import requests
import xlrd

CH#F/Zh,Y0
51Testing软件测试网u;eis5|"C`Q
class login_test(unittest.TestCase):

U0sgQ^!L?8t0
    def setUp(self):
        self.host = "http://ipipipipipip"
        self.header = {'Content-Type': 'application/json'}

Vj+` I rU^0
    def tearDown(self):
        print ("------测试结束-------")

}6?7uW"G/e l!^NR0
    def get_data(self):
        filename = "Cases.xlsx"
        sheetname = "login"
        bk = xlrd.open_workbook(filename)
        self.sh = bk.sheet_by_name(sheetname)
        self.nrows = self.sh.nrows
        self.row_list = []
        for i in range(1, self.nrows):
            row_data = self.sh.row_values(i)
            self.row_list.append(row_data)

)b(l|!|`;{+XKr0
    def login(self, num):
        self.setUp()
        self.get_data()
        self.row_list = []
        self.row_data = self.sh.row_values(num)
        self.row_list.append(self.row_data)
        self.row_list = []
        self.url = self.row_data[1]
        self.username = self.row_data[2]
        self.password = self.row_data[3]
        self.check = self.row_data[4]
        self.POSTURL = self.host + self.url
        self.data = {
            "account": self.username,
            "password": self.password
        }
        self.Response = requests.post(url=self.POSTURL, json=self.data, headers=self.header)

c+\6\X)h^B0
    def test_login_01(self):
        '''登录成功'''
        self.login(1)
        text = self.Response.text
        self.assertIn(self.check, text)
51Testing软件测试网 L)y|A`.l
    def test_login_02(self):
        '''登录失败'''
        self.login(2)
        text = self.Response.text
        self.assertIn(self.check, text)

S'Q.u4|j1`(Y|]|0
    def test_login_03(self):
        '''登录失败'''
        self.login(3)
        text = self.Response.text
        self.assertIn(self.check, text)
51Testing软件测试网@IE;t;T y9xq`6te`

$f.v L*b%T"R2j*m,Zy2i0

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar