【问题标题】:Using variable in Intern functional test在实习生功能测试中使用变量
【发布时间】:2015-12-21 18:27:07
【问题描述】:

我需要使用一个变量,其值是根据 css 样式像素确定的。 测试找到左像素的值,然后选择一个特定的单元格。但是当我运行这个测试时,值总是 0 而不是它实际应该是的值。

 'Test' : function() { 
            var left = 0;
            var remote = this.remote;
            return remote
            .setFindTimeout(5000)

            .findByXpath("//div[@class = 'grid']//div[@class = 'gridCell' and position() = 1]/div[3]")
              .getAttribute("style") 
              .then( function(width) {
                  left = parseInt(width.substring(width.indexOf("left")+6,width.indexOf("width")-4));
              }).end() 
            .f_selectCell("", 0, left)               
        },

【问题讨论】:

    标签: intern leadfoot


    【解决方案1】:

    虽然命令链中的调用将按顺序执行,但链表达式本身会被解析并在执行开始之前解析参数。所以在

    的情况下
    return remote
        .findByXpath('...')
        .getAttribute('style')
        .then(function (width) {
            left = parseInt(width);
        })
        .f_selectCell('', 0, left);
    

    f_selectCellleft 参数在链开始执行之前进行评估。当 leftthen 回调中重新分配时,f_selectCell 不会知道它,因为它已经将 left 评估为 0。

    相反,您需要在then 回调中调用f_selectCell 方法,或者将属性可以分配给它的object 传递给它。

    return remote
        // ...
        .then(function (width) {
            left = parseInt(width);
        })
        .then(function () {
            // I'm not entirely sure where f_selectCell is coming from...
            return f_selectCell('', 0, left);
        });
    

    // Put all args to selectCell in this
    var selectData = {};
    
    return remote
        // ...
        .then(function (width) {
            selectData.left = parseInt(width);
        })
        // selectCell now takes an object with all args
        // The object is never reassigned during execution. 
        .f_selectCell(selectData);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      • 2016-02-11
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      相关资源
      最近更新 更多