• 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/


     

  • 相关阅读:
    小程序路由
    机器学习笔记—支持向量机(1)
    用极大似然估计法推出朴素贝叶斯法中的先验概率估计公式
    机器学习笔记—生成学习
    机器学习笔记—再谈广义线性模型
    机器学习笔记—指数分布簇和广义线性模型
    机器学习笔记—Logistic 回归
    机器学习笔记—局部权重线性回归
    机器学习笔记—线性回归
    机器学习笔记1
  • 原文地址:https://www.cnblogs.com/minna/p/6336917.html
Copyright © 2020-2023  润新知