Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda