appium-desktop 脚本录制常用AW使用介绍(下)

发表于:2021-7-16 09:45

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:测试步行人    来源:CSDN

#
AW
  AWSleep
  1、功能描述
  线程等待时间。
  2、字段描述
  3、举例
  {
  "className": "AWSleep",
  "seconds": "1"
  }
  AWHttpClient
  1、功能描述
  发送HTTP请求到服务端,并按照一定规则校验服务端返回的响应消息。
  2、字段描述
  重试策略说明:
  1.若响应返回为null则直接进行重试。
  2.如果未设置retryStateCodeList或retryStateCodeList为空集合,则判断reponseExpected.getStateCode()是否与实际的状态码是否一致,不一致则进行请求重试。
  3.如果retryStateCodeList不为空集合,则判断retryStateCodeList集合是否包含实际状态码,若包含则进行重试。
  2.1 HttpClientRequest
  2.2  HttpClientResponse
  3、举例
  {
  "remark": "调用address接口",
  "className": "AWHttpClient",
  "config": {
  "primaryKeys": [
  "orderNo"
  ],
  "keyNameAndPrimarykeys": {
  "items": [
  "itemUrl"
  ]
  }
  },
  "request": {
  "type": 1,
  "url": "${global.data.ecommerce.addr}/xxxx/api/v1/xxxx/{ecommerce_id}/xxxx/xxxx",
  "path": {
  "ecommerce_id": "${global.taobao.ecommerceid}"
  },
  "headers": {
  "content-type": "application/json",
  "userId": "${global.auth.userid}",
  "Authorization": "${global.auth.token}"
  }
  },
  "reponseExpected": {
  "stateCode": "200",
  "responseBody": [
  {
  "dealDate": "2017-04-17T13:16:36.000+08",
  "orderNo": "3234925410420512",
  "amount": 78.35,
  "address": "中华人民共和国",
  "consignee": "张三",
  "phoneNumber": "1816",
  "items": [
  {
  "itemUrl": "//trade.taobao.com/trade/detail/tradeSnap.htm?tradeID=3234925410430512",
  "itemName": "十二生肖传说精装图画书海豚绘本花园适合3岁以上亲子阅读正版童书",
  "price": 17.4,
  "quantity": 1
  }
  ]
  }
  ]
  }
  AWTemplateActuator
  1、AW变为模版
  正常编写完AW,在测试用例中作为一个步骤,格式如下:
  举例:
  {
  "className": "AWAppiumRecordAction",
  "remark": "",
  "mobile":"15210001001",
  "password":"qazxsw"
  }
  1.1、增加下面两个参数
  "awIsTemplate":true,
  "templateName":"youname"
  1.2、参数化
  把变量参数化,比如上面的例子中,需要把mobile和password的值参数化。
  上面测试步骤变成的模版如下:
  {
  "className": "AWAppiumRecordAction",
  "remark": "",
  "awIsTemplate":true,
  "mobile":"${mobile}",
  "password":"${password}"
  "templateName":"loginTemplate"
  }
  原有AW只要是继承了ActionWord类都支持该功能。
  2、模版引用
  使用框架中的 AWTemplateActuator引用模版。该AW唯一参数citationTemplates是一个对象的list。对象属性包括:
  · templateName–引用的模版名称
  · templateParamValue–模版中参数值
  · assertTemplateName–校验结果的模版名称
  举例:
  比如引用上面的模版的使用方法如下:
  {
  "className": "AWTemplateActuator",
  "citationTemplates": [
  {
  "templateName": "loginTemplate",
  "templateParamValue": {
  "mobile": "15267",
  "password": "2222"
  },
  "assertTemplateName": "loginSuccess"----这是把校验结果作为一个模版
  }
  ]
  }
  当然如果你参数值是固定的,可以不用参数,模版引用中只需要不传递templateParamValue参数即可。
  2.1、扩展
  对于输入我们一般会做很多非法性校验,使用模版执行器只需要配置参数值即可,比如上面的例子:
  {
  "className": "AWTemplateActuator",
  "citationTemplates": [
  {
  "templateName": "loginTemplate",
  "templateParamValue": {
  "mobile": "15267",--手机号位数不够"password": "2222"
  },
  "assertTemplateName": "loginSuccess"----这是把校验结果作为一个模版
  },
  {
  "templateName": "loginTemplate",
  "templateParamValue": {
  "mobile": "152671111111111",---手机号过长"password": "x@#@"
  },
  "assertTemplateName": "loginSuccess"----这是把校验结果作为一个模版
  }
  ]
  }
  3、模版路径
  3.1、模版和非模版混合使用
   一个用例文件中可以包含AW模版和非AW模版两种类型,但是对于模版记得使用AWTemplateActuator执行模版
  3.2、模版路径方法
  为了模版的重复使用,可以把模版放到一个文件夹里面,用例文件只负责使用AWTemplateActuator调用模版
  3.2.1、新建模版文件夹
  新建文件夹,把所有模版都放到该文件夹里面
  3.2.2、增加配置
  application.propertites中增加template.path:./xx/xx/xxx/xxx。
  其它不变。

  本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号