Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hiredgun opened this issue Apr 12, 2019 · 3 comments
Assignees
Labels
FREQUENCY: level 2 STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@hiredgun
Copy link

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
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Apr 12, 2019
@Farfurix Farfurix self-assigned this Apr 15, 2019
@Farfurix
Copy link
Contributor

@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)

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Apr 15, 2019
@Farfurix Farfurix removed their assignment Apr 15, 2019
@Farfurix Farfurix added the TYPE: bug The described behavior is considered as wrong (bug). label Apr 15, 2019
@Farfurix Farfurix added this to the Planned milestone Apr 15, 2019
@devniel
Copy link

devniel commented Aug 21, 2019

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

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 21, 2019
@Dmitry-Ostashev Dmitry-Ostashev removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 22, 2019
AlexKamaev added a commit to AlexKamaev/testcafe that referenced this issue Sep 10, 2019
@AndreyBelym AndreyBelym modified the milestones: Planned, Sprint #41 Sep 10, 2019
@lock
Copy link

lock bot commented Sep 21, 2019

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 lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Sep 21, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 21, 2019
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this issue Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FREQUENCY: level 2 STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

6 participants