zoukankan      html  css  js  c++  java
  • 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测试过程。

  • 相关阅读:
    返回顶部
    C# 对文本文件的几种读写方法
    cocos2dx 锁定30帧设置
    AndroidManifest.xml 屏幕上下反转
    粒子系统主
    CCParticleSystem粒子系统
    精灵的优化
    cocos2dx 菜单按钮回调方法传参 tag传参
    cocos2dx跨平台使用自定义字体
    ios7 Cocos2dx 隐藏状态栏设置
  • 原文地址:https://www.cnblogs.com/jan4984/p/4500753.html
Copyright © 2011-2022 走看看