线程及其它代码

import random
import threading
import requests

#性能测试三要素:接口测试,多线程,真实场景
#真实场景:1、数据真实 2、用户操作链路真实 业务操作逻辑、思考时间
import time


class login():

    def __init__(self):
        pass

    def firstpage(self):
        url='http://localhost:8080/WoniuSales-20171128-V1.3-bin/'
        res=requests.request('get',url=url)
        if '请先登录' in res.text:
            print('已经进入首页')
        else:
            print('进入首页失败')

    def homepage(self):
        url='http://localhost:8080/WoniuSales-20171128-V1.3-bin/sell'
        res=requests.request('get',url=url)
        if '注销' in res.text:
            print('已经进入主页')
        else:
            print('进入主页失败')

    def login(self,data):
        url='http://localhost:8080/WoniuSales-20171128-V1.3-bin/user/login'
        #data={'username': username,'password': password,'verifycode': '0000'}
        res=requests.request('post',url=url,data=data)
        if 'pass' in res.text:
            print('登录成功')
        else:
            print('登录失败')

    def start(self):
        self.firstpage()
        time.sleep(3)
        self.login()
        time.sleep(1)
        self.homepage()

    def thre(self):

        for i in range(10):
            tt=login()
            user=[
                {'username': 'admin','password': 'admin123','verifycode': '0000'},
                {'username': 'zhangsan','password': 'zs123','verifycode': '0000'},
                {'username': 'lisi','password': 'ls123','verifycode': '0000'},
                {'username': 'wangwu','password': 'ww123','verifycode': '0000'},
                {'username': 'boss','password': 'boss123','verifycode': '0000'}
                  ]
            indexc=random.randint(0,len(user)-1)
            thre=threading.Thread(target=tt.login,args=(user[indexc],))     #线程
            thre.start()


if __name__ == '__main__':
    login().thre()
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。