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

155
Views
Testcafe expect passes if await used but not if methods chained

Take this Testcafe code:

test
    .page('https://testsite.com')
    ('button hidden after clicked', async t => {
        await t
            .expect(await Selector('button.cc-banner__button-accept').visible).ok({ timeout: 5000 })
            .setNativeDialogHandler(() => true)
            .click(await Selector('button.cc-banner__button-accept'))
            .expect(await Selector('button.cc-banner__button-accept').visible).notOk({ timeout:1000 });

The above fails when Testcafe runs.

However, the code below passes:

test
    .page('https://testsite.com')
    ('button hidden after clicked', async t => {
        await t
            .expect(await Selector('button.cc-banner__button-accept').visible).ok({ timeout: 5000 })
            .setNativeDialogHandler(() => true)
            .click(await Selector('button.cc-banner__button-accept'));
        await t
            .expect(await Selector('button.cc-banner__button-accept').visible).notOk({ timeout:1000 });

Why is this? Any ideas?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

JS evaluates the real element value for Selector at the time of chain compiling. (JS works in this way). It means that the first test you evaluate calculates await Selector('button.cc-banner__button-accept').visible for the whole chain only once and then this value is used for checking. Since you get the value only once, the test fails as expected. You should remove await inside, before Selector inside assertions, as you can see in CLI warnings.

enter image description here

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!