0

I'm having a very frustrating problem with testing a React app using CodeceptJS and puppeteer - it only finds elements with a custom locator only when in paused mode.

My custom locator is data-test-id. I'm targeting elements using I.seeElement("$id-of-element-here") and I.seeNumberOfElements("$test-id", X).

This works perfectly when my tests are paused and I'm manually moving onto each step of the test, but does not work when the tests are executing from start to finish - targeted elements are simply not found.

Sometimes I can counter this with I.wait(X) or I.refreshPage() but I'm now running into a case where none of this helps.

I do see the data-test-id attributes in the HTML using both Chrome's and Chromium's dev tools. There are no typos either.

There's not much point in showing examples of targeted elements, as the problem seems to happen at random, I haven't been able to see any pattern of where/when this happens.

These are the settings of the custom locator plugin, in codecept.conf.js:

plugins{
  ...
  customLocator: {
    enabled: true,
    attribute: 'data-test-id',
  },
  ...
}    

Any help will be appreciated! :)

Boyan Kmetov
  • 11
  • 1
  • 2

2 Answers2

0

May waitForNavigation is a way to go?

https://codecept.io/helpers/Puppeteer/#configuration https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagewaitfornavigationoptions

  • hey, thanks for the tip! I haven't used `waitFroNavigation` yet but it looks like a good way to mitigate the problem. I'll give it a try next time I have this problem. In this particular case though, I found my answer - the problem was I was looking for an element within a `within` block. I know - noobs, right? :) – Boyan Kmetov Jan 14 '21 at 08:25
0

Solution:

I was running the assertions in question in a rather big within block (link), so I was ending up looking for something within an element that was no longer on the page.

It appears that during a pause(), you can find and operate on elements that are visible at the moment and the within blocks don't matter.

That's the only way I can explain why, in this situation, an element can be detected during a pause but not during the actual execution of the test from start to finish.

As soon as I moved the assertions out of the within block, everything was normal and behaved as expected.

Apologies for the confusion - learning every day... :)

Boyan Kmetov
  • 11
  • 1
  • 2