Вопрос

How can you store a value from one element in an Intern functional test that can be used to find additional elements?

For example, I have the following test snippet:

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()

Basically, when I run the test, the mainItemId value will log correctly, but the second elementByXPath will not be found. If I initialize mainItemId with the same value, the xpath works. Based on what I'm seeing, its as if mainItemId will store the value only within the .then() context.

Thanks.

Это было полезно?

Решение

All of the remote methods are non-blocking, and execute immediately when the test function is invoked. mainItemId is not set until after the 4th command is executed. If you need to perform a query that is conditional upon data retrieved from an earlier command, you need to do that within a callback:

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()
    });
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top