frisby.js-接口测试基础知识

一、安装环境

1.先更新yum语言
 curl -sL https://rpm.nodesource.com/setup | bash -  
2.安装nodejs
 yum install -y nodejs
3.安装npm
yum install -y npm
4.jasmine
npm install -g jasmine-node
5.frisby
npm install --save-dev frisby

 

二、运行脚本 test_spec.js

jasmine-node  test_spec.js

 

三、生成XML报告

jasmine-node test_spec.js --junitreport

四、常用的Expectations

 

1.expectStatus( code )   响应返回的HTTP状态码等于code

2.expectHeader( key, content )  期望的头信息  精确的

例如:

frisby.create( 'Ensure response has a proper JSON Content-Type header')
  .get( 'http://httpbin.org/get')
  .expectHeader( 'Content-Type', 'application/json')
.toss();
3.expectHeaderContains( key, content ) 期望的头信息   不精确的

例如:

frisby.create( 'Ensure response has a proper JSON Content-Type header')
  .get( 'http://httpbin.org/get')
  .expectHeader( 'Content-Type', 'json')
.toss();
4.expectHeaderToMatch( key, patterm )  期望的头信息,使用正则表达式匹配的
例如:
frisby.create( 'Ensure response has image/something in the Content-Type header')
  .get( 'http://httpbin.org/get')
  .expectHeaderToMatch( 'Content-Type', '^image/.+')
.toss();

5.expectJSON( [path], json )  期望的JSON 

例如:

frisby.create( 'Ensure test has foo and bar')
  .get( 'http://httpbin.org/get?foo=bar&bar=baz')
  .expectJSON({
    args: {
      foo: 'bar',
      bar: 'baz'
    }
  })
.toss()

6.expectJSONTypes( [path], json )  期望json的类型

例如:

frisby.create( 'Ensure response has proper JSON types in specified keys')
  .post( 'http://httpbin.org/post', {
    arr: [ 1, 2, 3, 4],
    foo: "bar",
    bar: "baz",
    answer: 42
  })
  .expectJSONTypes( 'args', {
    arr: Array,
    foo: String,
    bar: String,
    answer: Number
  })
.toss()
7.expectBodyContains( content )  body内容
8.expectJSONLength( [path], length )  JSON长度
9.expectMaxResponseTime( milliseconds )  最大响应时间
 
五、path
1.All Objects in an Array
所有的对象都在一个数组内,可用 * 作为path
2.One Object in an Array
一个对象在一个数组内,可以用 ? 作为path
 
六、Helpers

1.after()

frisby.create( 'First test')
  .get( 'http://httpbin.org/get?foo=bar')
  .after( function(err, res, body) {
 
    frisby.create( 'Second test, run after first is completed')
      .get( 'http://httpbin.org/get?bar=baz')
    .toss()
 
  })
.toss()
2.afterJSON()  返回的JSON在别的里面使用
frisby.create( 'First test')
  .get( 'http://httpbin.org/get?foo=bar')
  .afterJSON( function(json) {
 
  // Now you can use 'json' in additional requests
    frisby.create( 'Second test, run after first is completed')
      .get( 'http://httpbin.org/get?bar=' + json.args.foo)
    .toss()
 
  })
.toss()
3.inspectRequest()  发送的请求
 
详细学习地址:http://frisbyjs.com/docs/api/


 

转载于:https://www.cnblogs.com/minna/p/6336917.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值