testcafe-react-selectors icon indicating copy to clipboard operation
testcafe-react-selectors copied to clipboard

Can't find desendant components of the same type

Open arubtsov opened this issue 7 years ago • 8 comments

I have two instances of a component one of which is desendant of another (with a div wrapper between them). ReactSelector('Foo').count returns 1.

arubtsov avatar May 30 '17 11:05 arubtsov

Yep, this does not work... I have component named Id and structure like:

<div>
  <Id name="one">
    <div>
      <Id name="two">
          foo
      </Id>
    </div>
  </Id>
</div>

I can try then:

    const one = await ReactSelector('Id').withProps({
        name: 'one'
    });
    const two = await one.findReact('Id').withProps({
        name: 'two'
    });

    await t.expect(one.count).ok('One was found');
    await t.expect(two.count).ok('Two was found'); // <-- This fails as two.count = 0

leomelin avatar May 08 '18 06:05 leomelin

Hi @leomelin, Yes, the current implementation doesn't allow to use such selectors. I'm going to investigate and try to figure out a fix soon.

kirovboris avatar May 08 '18 11:05 kirovboris

No idea how this issue still exists when such functionality is so common. For something like

Row
    Container
        Container key='1'
        Container key='2'
    Container
        ...
    Container
        ...

image How am I supposed to be able to select the containers with keys so that I can verify the key values are correct?

I'm able to select the first container fine with section = ReactSelector('Row Container').nth(0); but then selecting the two containers inside that is seemingly impossible.

  • section.findReact('Container'); does not work, it only returns the original container itself
  • section.findReact('Container Container').nth(x); also does not work

What's even stranger is that at seemingly random times, section.findReact('Container Container').nth(x); does actually work, but not in any reproducible way.

The hack that I'm currently using is section.find('.container').nth(0).findReact('Container').getReact(({ key }) => key))

joywave avatar Jan 30 '20 21:01 joywave

Hi @joywave,

Thank you for your feedback and for the workaround. Once we get any results, we will post them here. You are also welcome to submit your PR.

alexey-lin avatar Jan 31 '20 13:01 alexey-lin

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

github-actions[bot] avatar Dec 10 '22 01:12 github-actions[bot]

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

github-actions[bot] avatar Dec 20 '22 01:12 github-actions[bot]

Hello I encountered the same error. When searching for nested items with the same name. The reactive selector can only select the parent. For example

<ComponentA  key="componentAParent">
    <ComponentA key="componentAChild" />
    <ComponentB key="componentBChild" />
</ComponentA>

Example 2:

<ComponentA  key="componentAParent">
    <SomeComponent>
         <ComponentA key="componentAChild" />
         <ComponentB key="componentBChild" />
    <SomeComponent>
</ComponentA>

ReactSelector("ComponentA").withKey("componentAParent") - can find parent but ReactSelector("ComponentA").withKey("componentAChild") - can't find the nested element

Could you please help us with this issue?

ilya2010ujl avatar Mar 03 '23 08:03 ilya2010ujl

Hi @ilya2010ujl,

I see that the problem is still actual. I'll reopen the issue.

Aleksey28 avatar Mar 07 '23 08:03 Aleksey28

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

github-actions[bot] avatar Mar 08 '24 01:03 github-actions[bot]

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

github-actions[bot] avatar Mar 18 '24 01:03 github-actions[bot]