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

python+unittest登录接口测试

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

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

+J"_'{*]C#nj(`0
以上excel数据
# -*- coding:utf-8 -*-
import unittest
import requests
import xlrd
51Testing软件测试网&x1d~EvR
51Testing软件测试网szPR I0ic
class login_test(unittest.TestCase):
51Testing软件测试网2b+~Mt_}/J
    def setUp(self):
        self.host = "http://ipipipipipip"
        self.header = {'Content-Type': 'application/json'}
51Testing软件测试网:G!Crc*p _:x
    def tearDown(self):
        print ("------测试结束-------")

'P6KXn2d'd1]0
    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)

@ |[1sx;D we!y0
    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)
51Testing软件测试网l G^,V qa
    def test_login_01(self):
        '''登录成功'''
        self.login(1)
        text = self.Response.text
        self.assertIn(self.check, text)
51Testing软件测试网fjc s!jDs
    def test_login_02(self):
        '''登录失败'''
        self.login(2)
        text = self.Response.text
        self.assertIn(self.check, text)

yF*T8Ir*y}?M0
    def test_login_03(self):
        '''登录失败'''
        self.login(3)
        text = self.Response.text
        self.assertIn(self.check, text)
51Testing软件测试网'SjW(W(eq d
51Testing软件测试网-[0b8V1Ve_3ws$_

TAG:

 

评分:0

我来说两句

Open Toolbar