Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda