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

163
Views
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 answers
Answer question

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