so I am working in a Testing Automation case where i should increment the index of my Xpath every time i run dhe test case. So far i have done this:
wd.addPromiseChainMethod("SelectAcc", () => {
var XPathIndex = I;
return driver.waitForElementByXpath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[" +
i +
"]"
);
if (XPathIndex > 5) {
I = 1;
} else {
I = XPathIndex + 1;
}
click();
});
and also globaly declared`
Var I =1;
But I am not sure how to update the global variable I, so for example if i have ran the test case 2 times, the third time I run it I will be:
Var I =3;
You can use two "globals" in that case. (I'd recommend to have them confined in an object along with your test though).
let xPathIndex = 1;
const max = 5;
wd.addPromiseChainMethod('SelectAcc', () => {
if( ++xPathIndex > max ) xPathIndex = 1;
return driver. waitForElementByXpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout["+ xPathIndex +"]")
} );
In case you need to store the inital value for new contexts (page reloads) you can use localStorage to persist and update the starting value, hence sg like:
let storedXPathIndex = localStorage.getItem("storedXPathIndex");
let xPathIndex = (storedXPathIndex) ? ++storedXPathIndex : 0;
localStorage.setItem("storedXPathIndex", xPathIndex);
const max = 5;
wd.addPromiseChainMethod('SelectAcc', () => {
if( ++xPathIndex > max ) xPathIndex = 1;
return driver. waitForElementByXpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout["+ xPathIndex +"]")
} );
Note: JavaScript is case-sensitive! You have a lot of typos in your code above.