testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Test fails while selecting every element ('*'), filtering by text and svg tag is a child

Open hiredgun opened this issue 7 years ago • 3 comments

What is your Test Scenario?

I would like to select a node with foo text without providing a tag name

html body:

    <span>
         <svg></svg>
    </span>
    <span>foo</span>

What is the Current behavior?

When you want to filter only an element with a specific text and there is an svg tag for instance like in the example above you get Cannot read property 'trim' of undefined error

What is the Expected behavior?

Span wit foo text should be found

What is your web application and your TestCafe test code?

test(`test`, async t => {
   console.log(await Selector('*').withExactText('foo').count);
});
Your complete test report:
 Test selector
 ✖ test

   1) An error occurred in Selector code:

      TypeError: Cannot read property 'trim' of undefined

      Browser: Chrome 73.0.3683 / Mac OS X 10.14.4

         1 |import { Selector } from 'testcafe';
         2 |
         3 |fixture('Test selector').page('http://localhost:5000/index.html');
         4 |
         5 |test(`test`, async t => {
       > 6 |    console.log(await Selector('*').withExactText('foo').count);
         7 |});
         8 |

         at <anonymous> (/Users/Projects/Private/testcafe-selector-tester/test.js:6:23)
         at test (/Users/Projects/Private/testcafe-selector-tester/test.js:5:1)
         at markeredfn (/Users/Projects/Private/testcafe-selector-tester/node_modules/testcafe/src/api/wrap-test-function.js:17:28)
         at <anonymous> (/Users/Projects/Private/testcafe-selector-tester/node_modules/testcafe/src/api/wrap-test-function.js:7:5)
         at fn (/Users/Projects/Private/testcafe-selector-tester/node_modules/testcafe/src/test-run/index.js:241:19)
         at LiveModeTestRun._executeTestFn
      (/Users/Projects/Private/testcafe-selector-tester/node_modules/testcafe/src/test-run/index.js:237:38)
         at _executeTestFn (/Users/Projects/Private/testcafe-selector-tester/node_modules/testcafe/src/test-run/index.js:290:24)

Steps to Reproduce:

Just run the above test with provided html body

Your Environment details:

  • testcafe version: 1.1.2
  • node.js version: v11.10.1
  • command-line arguments: testcafe chrome test.js -L
  • browser name and version: Chrome 73.0.3683 / Mac OS X 10.14.4
  • platform and version: macOS Mojave 10.14.4

hiredgun avatar Apr 12 '19 16:04 hiredgun

@hiredgun

Hello.

I've reproduced this issue under Windows 10 / Chrome 73 / [email protected]. Our team will research it and check for a suitable solution.

For team: index.html

<html>
<head>
</head>
<body>
<div>
    <span>
        <svg></svg>
    </span>
    <span>foo</span>
</div>
</body>
</html>

test.js

import { Selector } from 'testcafe';

fixture `My Fixture`
    .page `./index.html`;

test('test', async (t) => {
    const selector = Selector('*').addCustomDOMProperties({
        outerHTML: el => el.outerHTML
    });
    const body     = Selector('body').addCustomDOMProperties({
        outerHTML: el => el.outerHTML
    });
    const span     = Selector('span').addCustomDOMProperties({
        outerHTML: el => el.outerHTML
    });
    const div      = Selector('div').addCustomDOMProperties({
        outerHTML: el => el.outerHTML
    });

    console.log('body.count:', await body.count);
    console.log('div.count:', await div.count);
    console.log('span.count:', await span.count);

    await t
        .expect(body.withExactText('foo').count).eql(0)
        .expect(div.withExactText('foo').count).eql(1)
        .expect(span.withExactText('foo').count).eql(1);

    console.log('selector.count:', await selector.count);

    for (let i = 0; i < 7; i++) {
        console.log(i + ':', await selector.nth(i).outerHTML);
    }

    await t
        .expect(selector.withExactText('foo').count).eql(1);

});

result log

 - Chrome 73.0.3683 / Windows 10.0.0

 My Fixture
body.count: 1
div.count: 1
span.count: 2
selector.count: 7
0: <html><head>
</head>
<body>
<div>
    <span>
        <svg></svg>
    </span>
    <span>foo</span>
</div>


</body></html>
1: <head>
</head>
2: <body>
<div>
    <span>
        <svg></svg>
    </span>
    <span>foo</span>
</div>


</body>
3: <div>
    <span>
        <svg></svg>
    </span>
    <span>foo</span>
</div>
4: <span>
        <svg></svg>
    </span>
5: <svg></svg>
6: <span>foo</span>
 × test

   1) An error occurred in Selector code:

      TypeError: Cannot read property 'trim' of undefined

      Browser: Chrome 73.0.3683 / Windows 10.0.0

         31 |    for (let i = 0; i < 7; i++) {
         32 |        console.log(i + ':', await selector.nth(i).outerHTML);
         33 |    }
         34 |
         35 |    await t
       > 36 |        .expect(selector.withExactText('foo').count).eql(1);
         37 |
         38 |});
         39 |

         at eql (D:\tst\i3684-tc\test.js:36:54)



 1/1 failed (2s)

Farfurix avatar Apr 15 '19 11:04 Farfurix

Hello,

I got the same problem, in this case I'm searching inside a <svg/> element, while with textContent the text is indeed there, when using withExactText it throws the TypeError: Cannot read property \'trim\' of undefined and withText doesn't find the same text.

Thanks

devniel avatar Aug 21 '19 04:08 devniel

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.

lock[bot] avatar Sep 21 '19 10:09 lock[bot]