Testcafe: 1.1.0: "ClientFunction cannot return DOM elements" when using client function to get a property of window

Created on 3 Apr 2019  ·  4Comments  ·  Source: DevExpress/testcafe

What is your Test Scenario?

I want to check the existence of a window object

What is the Current behavior?

Error: ClientFunction cannot return DOM elements. Use Selector functions for this purpose

What is the Expected behavior?

The object should be returned, since it is a valid object.

Note that replacing getNavDispatch with getWindowLocation in the test does not result in the error. They are both valid properties of window

If I add await t.debug() at the top of the test then open a console:

image

What is your web application and your TestCafe test code?

nike.com/orders


Your complete test code (or attach your test files):

const getNavDispatch = ClientFunction(() => window.NikeDotcomNav);
const getWindowLocation = ClientFunction(() => window.location);

fixture`Login`
  .httpAuth({
    username: process.env.BASIC_AUTH_USER,
    password: process.env.BASIC_AUTH_PASS,
  })
  .page(`${page.settings.baseUrl}/orders/`)
  .beforeEach(async () => {
    await waitForReact();
  });


test('user can log in', async t => {
  // Login via guest lookup page.
  const disp = await getNavDispatch();
  console.log('NikeDotcomNav', disp);
...


Your complete test report:

 ✖ user can log in

   1) ClientFunction cannot return DOM elements. Use Selector functions for this purpose.

      Browser: Chrome 73.0.3683 / Mac OS X 10.13.6

Your Environment details:

  • testcafe version: 1.1.0
  • node.js version: 8.15.1
  • command-line arguments: NODE_ENV=development testcafe -s screenshots --skip-js-errors chrome ./tests/*.test.js -F Login
  • browser name and version:
  • platform and version: OSX
Auto-locked

Most helpful comment

Excellent, thanks

All 4 comments

If anyone is curious the fix for this was to JSON.stringify the object I wanted to get back. Ran into a few problems with that (circular structure). The root of the problem is related to object marshalling across processes -- I didn't need the full object, I just needed to check for its existence.

Still, the error message I got has nothing to do with that. It could be improved.

I've found that the NikeDotcomNav contains at least one DOM element. Check the window.NikeDotcomNav.vanilla.objects[1].el property.

image

However, I understand that the error message is very unclear and DOM elements can be missed easily when you try to retrieve an object with a very complex structure. I think we should display the name of the property that causes the error and names of its parent properties as well. I've created a feature suggestion about it: https://github.com/DevExpress/testcafe/issues/3640.

Excellent, thanks

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings