• frisby用例动态链


    frisby是一个nodejs的rest api测试框架。一般来讲,因为nodejs是众所周知的异步编程模式,api以.after()方法一步步走:

    frisby.create('login')
      .get('http://httpbin.org/login',{usernmae:xxx,password:xxx})
      after(function(err, res, body) {
        frisby.create('logout')
          .get('http://httpbin.org/logout')
        .toss()
      });
    .toss()

    在一些较为复杂的测试流程中,需要根据上一部的返回动态决定下一步需要做什么。比如:

    frisby.create('login')
      .get('http://httpbin.org/login',{usernmae:xxx,password:xxx})
      afterJSON(function(rsp) {
        if(rsp.ok){
           frisby.create('logout')
             .get('http://httpbin.org/logout')
           .toss()
        }else{
           frisby.create('login again')
             .get('http://httpbin.org/login',{username:xxx,password:xxxx})
           .toss()
        }
      });
    .toss()

    上面的例子,如果第二个frisby toss的时候还有更多的after操作,代码会非常难组织。为此写了一个简单的pipeLine函数用于将多个frisby串起来。

    function toss(f, msg){
        return function(){
            //console.log('toss ' + msg);
            f.toss();
        }
    }
    
    //frisby.after() just add a function to array and invoke them when .toss()
    function pipeLine(works){
        for(var i = 0; i < works.length - 1; i++){
            works[i].after(toss(works[i+1], ''+(i+1)));
        }
        return works[0];
    }
    
    var testsPipline = function() {
        var f1 = frisby.create('test 1')
            .get('http://192.168.5.120:8080/static/3ef9f60c/images/title.png');
        var f2 = frisby.create('test 2')
            .get('http://192.168.5.120:8080/static/3ef9f60c/images/title.png');
        var f3 = frisby.create('test 3')
            .get('http://192.168.5.120:8080/static/3ef9f60c/images/title.png');
        toss(pipeLine([f1, f2, f3]), 0)();
        toss(pipeLine([f2,f3]), 0)();
    }

    可以很方便的重用预定义的frisby测试过程。

  • 相关阅读:
    将图片部署在tomcat/iportWork/uploadFiles中
    idea中的svn配置
    mavan和idea的搭建,很好的一篇文章
    C#如何遍历数组?
    java 泛型小小的测试题
    js关于变量作为if条件的真假问题
    HTML5实现两个视频循环播放!
    JQuery利用选择器定位动态id?
    hibernate QBC查询
    mybatis前台传来一个String,后后台执行sql变成了true
  • 原文地址:https://www.cnblogs.com/jan4984/p/4500753.html
Copyright © 2020-2023  润新知