当前位置: 首页 > news >正文

手表网站模板螺蛳粉营销策划方案

手表网站模板,螺蛳粉营销策划方案,郑州seo费用,wordpress如何去掉分类里面的大字1.1.登录用户参数化 在测试过程中,经常会涉及到需要用不同的用户登录操作,可以采用队列的方式,对登录的用户进行参数化。如果数据要保证不重复,则取完不再放回;如可以重复,则取出后再返回队列。 def lo…

1.1.登录用户参数化  

在测试过程中,经常会涉及到需要用不同的用户登录操作,可以采用队列的方式,对登录的用户进行参数化。如果数据要保证不重复,则取完不再放回;如可以重复,则取出后再返回队列。

def login(self):              try:                  user = self.user.userqueue.get_nowait()         # 取不到数据时直接崩溃,走异常处理流程              except queue.Empty:                  print("没有数据了")                  exit(0)              url = '*****'              headers = {                  'Content-Type': 'application/x-www-form-urlencoded'              }              body = {                  'username': user['username'],                  'password': '******'              }              with self.client.post(url, data=body, headers=headers, name='登录', catch_response=True,) as response:                  self.user.userqueue.put_nowait(user)     #数据放回队列                  try:                      res = json.loads(response.text)                      if response.status_code == 200 and str(res) == user['userid']:                          response.success()                          return user['userid']                      else:                          response.failure("登录失败")                  except Exception as e:                      response.failure(e)         class WebUser(HttpUser):              tasks = [MyTask]              wait_time = between(0.1, 0.3)              host = 'http://*******'              userdata = xlrd.open_workbook(r'F:\pycharmproject\locusttest\i8.xls')              table = userdata.sheet_by_name('Sheet2')  # 表格中不同table页的名称              # 获取表格总行数              nrows = table.nrows              # 实例化队列,依次从表格中按行取出数据,放进队列              userqueue = queue.Queue()              for n in range(1, nrows):                  row_data = table.row_values(n)                  data = {                      'username': '%s' % row_data[0],                      'userid': '%s' % row_data[1]                  }                  userqueue.put_nowait(data)        

1.2.使用登录后返回的数据最为后续task的参数  

由于on_start 只执行一次,不会去执行函数里面的返回;因此将登录定义为一个函数,再通过on_start调用,保证只执行一次,同时能够获取到登录后返回的数据。

def on_start(self):              self.userid = self.login()                   def login(self):              """              登录接口              :return: 登录成功后返回userid,用于其他任务的参数              """              try:                  user = self.user.userqueue.get_nowait()         # 取不到数据时直接崩溃,走异常处理流程              except queue.Empty:                  print("没有数据了")                  exit(0)              url = '******'              headers = {                  'Content-Type': 'application/x-www-form-urlencoded'              }              body = {                  'username': user['username'],                  'password': '*****'              }              with self.client.post(url, data=body, headers=headers, name='登录', catch_response=True,) as response:                  self.user.userqueue.put_nowait(user)                  try:                      res = json.loads(response.text)                      if response.status_code == 200 and str(res) == user['userid']:                          response.success()                          return user['userid']                      else:                          response.failure("登录失败")                  except Exception as e:                      response.failure(e)                    @task(3)          def addbyi8(self):              url = '*********'              body = {                         'userid': self.userid              }              headers = {                  'Content-Type': 'application/x-www-form-urlencoded'              }              with self.client.post(url, data=body, headers=headers, catch_response=True,) as res:                  try:                      resjson = json.loads(res.text)                      if res.status_code == 200 and resjson == 1:                          res.success()                      else:                          res.failure('添加接口出错%s' % resjson)                  except Exception as e:                      res.failure(e) 

1.3.Post参数的value含有json和随机数  

采用random生成随机数,拼接到参数value中;json可以先定义json,然后再转换为字符串的形式,传入post参数。 

task(1)          def changeallbyi8(self):              random_number = random.randint(1, 1000)              url = '********'              contents = {                          "******": "locust发送的" + str(random_number),                  "******": "locust图纸的分析" + str(random_number)              }              body = {                       'contents': json.dumps(contents)                  }              with self.client.post(url, data=body,  catch_response=True) as res:                  try:                      resjson = json.loads(res.text)                      if res.status_code == 200 and resjson == 1:                          res.success()                      else:                          res.failure('保存接口出错')                  except Exception as e:                      res.failure(e)

1.4.Post参数中含有键值对随机取值配对  

Typedict字典中创建预设的键值对,使用random.choice从字典的键列表中随机选择一个键,然后使用这个键从字典中取得对应的值,并将其作为请求参数发送。

@task(3)          def addbyi8(self):              typedict = {                  'key1': 'value1',                  'key2': 'value2'    }              type = random.choice(list(typedict.keys()))              url = '****'              body = {                  'type': type,                  'operate': typedict[type]              }              headers = {                  'Content-Type': 'application/x-www-form-urlencoded'    }              with self.client.post(url, data=body, headers=headers,  catch_response=True,) as res:                  try:                      resjson = json.loads(res.text)                      if res.status_code == 200 and resjson == 1:                          res.success()                      else:                          res.failure('添加接口出错')                  except Exception as e:                      res.failure(e)

最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走! 

软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

http://www.hkea.cn/news/406823/

相关文章:

  • 网站怎么做更新吗如何建立网页
  • 国外建设工程招聘信息网站tool站长工具
  • 专业做相册书的网站电商网站建设制作
  • 银川网站开发公司电话东莞网
  • 环境保护局网站管理制度建设百度指数的主要功能有
  • 安装wordpress提示500错误关键词优化的策略有哪些
  • 企业网站建设公司排名深圳高端seo公司助力企业
  • 做网站套餐网站seo
  • 网站上的代码网页怎么做的下载百度软件
  • 网站功能模块建设搜狗推广
  • 网站做推广有用吗网站页面设计
  • 做简报的网站广州搜发网络科技有限公司
  • 南乐县住房和城乡建设局网站制作网站的步骤是什么
  • 金华做网站最专业的公司搜易网提供的技术服务
  • wordpress适合门户网站吗怎么营销自己的产品
  • 常用的网站类型有哪些seo优化专员编辑
  • 网站专题框架怎么做海阳seo排名
  • 手机网站代码下载黄页网站推广服务
  • 做网站前端多少钱在线bt种子
  • wordpress+模版+推荐专业网站seo推广
  • 浦项建设公司员工网站2023免费推广入口
  • 如何查询某个网站的设计公司最新推广注册app拿佣金
  • 八宝山做网站公司打广告
  • wordpress vip查看插件南宁seo费用服务
  • 建站之星模板怎么设置手机如何做网站
  • 上海公司网站制作价格西安百度关键词排名服务
  • 长沙网页制作开发公司aso优化方案
  • 深圳罗湖网站制作成人电脑基础培训班
  • 无锡网站制作咨询深圳网站设计十年乐云seo
  • 大连城市建设网站seo优化顾问服务阿亮