【问题标题】:Store a variable in Intern funcational test在实习生功能测试中存储变量
【发布时间】:2013-12-05 17:11:33
【问题描述】:

如何在 Intern 功能测试中存储一个元素的值以用于查找其他元素?

比如我有如下测试sn-p:

var mainItem = "Menu 1";
var subItem = "Sub Menu 1";
var mainItemId = "";
                return this.remote
                .elementByXPath("//*[contains(text(),'" + mainItem + "')]/ancestor::*[@dojoattachpoint='focusNode']")
                    .getAttribute("id")
                    .then(function(id){ mainItemId = id; })
                    .clickElement()
                    .end()
                .wait(500)
                .then(function(){ console.log(mainItemId); })
                .elementByXPath("//*[contains(text(),'" + subItem + "')][ancestor::*[@dijitpopupparent='" + mainItemId + "']]")
                    .clickElement()
                    .end()

基本上,当我运行测试时,mainItemId 值将正确记录,但第二个 elementByXPath 将找不到。如果我用相同的值初始化mainItemId,xpath 就可以工作。根据我所看到的,好像mainItemId 只会将值存储在.then() 上下文中。

谢谢。

【问题讨论】:

    标签: intern


    【解决方案1】:

    所有remote 方法都是非阻塞的,并且在调用测试函数时立即执行。 mainItemId 直到执行第 4 个命令后才设置。如果您需要执行以从先前命令检索的数据为条件的查询,则需要在回调中执行此操作:

    var mainItem = "Menu 1";
    var subItem = "Sub Menu 1";
    var mainItemId = "";
    var remote = this.remote;
    return remote
        .elementByXPath("//*[contains(text(),'" + mainItem + "')]/ancestor::*[@dojoattachpoint='focusNode']")
            .getAttribute("id")
            .then(function(id){ mainItemId = id; })
            .clickElement()
            .end()
        .wait(500)
        .then(function(){
            return remote.elementByXPath("//*[contains(text(),'" + subItem + "')][ancestor::*[@dijitpopupparent='" + mainItemId + "']]")
                .clickElement()
                .end()
        });
    

    【讨论】:

    • 效果很好!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-05-21
    • 2015-12-30
    • 2016-02-11
    • 2015-10-13
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多