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