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

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

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 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