I want to use local variable pass to another function or compare with any variable. Example:
browser
.waitForElementVisible("//div[@class='col-xs-7 alignR uppercase']//strong", 5000, function () {
browser
.pause(500)
.getText("//div[@class='col-xs-7 alignR uppercase']//strong", function(result){
console.log('++++++++++++++',result.value);
let numb1 = result.value;
numb = numb1.match(/\d/g);
numb = numb1.join("");
console.log("value=", numb1);
return numb1;
})
})
.element('xpath', "(//div[@class='row']//div[@class='col-xs-7 alignR'])[1]", function (present) {
console.log(present);
if (present.status == 0) {
//arrange
browser
.pause(500)
.getText("(//div[@class='row']//div[@class='col-xs-7 alignR'])[1]", function (result) {
console.log("string", result.value);
let numb = result.value;
numb = numb.match(/\d/g);
numb = numb.join("");
console.log("value=", numb);
return numb;
})
}
})
I want to compare numb/numb1 or get the total both of them.
Well, if you want to keep your test structure as is (pretty suspicious!), then why don't you declare some test-file global variables?
That being said... a finer approach would be to break-down your big steps & extract the logic into single-purpose functions, so you would either use:
Taking into account your current setup, let's consider adding the following custom command for extracting your
num1:❒ getNumb1.js (should reside in
test/custom_commands/):Similarly, add a second custom-command file (getNumb.js), which will return the value of
numb. Then, use the two in your test file and do the data manipulation, or data checking (assertions) as you please:Thus, in the current setup, it would be best if you would add commands such as
getNumb&getNumb1inside the commands section of your page-object.