Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Update variable everytime i run the app JS

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; 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!