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

159
Visualizações
Avoiding await in for loop in testafe

I have a written a test that loops through drop down options and sets value based on options. During the process, I have to also evaluate if the index is indeed set for which my code is -

    test(`Select all available options`, async (browser) => {
      const audioDevicelist = Selector(
        '#__next > div > main > div.Home_toolbar__JY_RL > div.Home_deviceControls__nQw4V > select:nth-child(2)'
      );
      const setSelectedIndex = ClientFunction(
        (index) => {
          audioDevicelist().selectedIndex = index;
        },
        { dependencies: { audioDevicelist } }
      );
      await browser.wait(3000);
      for (let i = 0; i < 4; i++) {
        await setSelectedIndex(i);
        await browser.expect(audioDevicelist.selectedIndex).eql(i);
         
        }
      }
      
    });

This works, but I wanted to avoid the await inside a loop. So I tried -

if (audioDevicelist.selectedIndex === i) {
        let ops += 1;
      } else {
        console.log('Sorry');
      }

But somehow the if statement is not validating while below statement satisfies and passes the test.

await browser.expect(audioDevicelist.selectedIndex).eql(i);

Any pointers? I just wanted to remove await inside the for loop.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't get any properties from the Selector result directly because the result of the Selector is a special asynchronous function and you should run it to get DOMNodeState. After that, you can get this property from the node state. But in any case, you should use await to get DOMNodeState.

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