Search code examples
testingfilterautomated-testse2e-testingtestcafe

Using Testcafe Selectors: withText then sibling


I'm trying to create a selector using the withText filter and wanting to select the sibling element.

given: const Create_asset = S('span').withText('Create Asset')

Create_asset() returns a ReExecutablePromise with the nextSibling() method. await Create_asset() returns a DOM-like(?) object, but without the nextSibling() method, so it seems I can't do await Create_asset().withText('text').nextSibling()

How can I select a sibling subsequently when using the withText() filter?

Thanks for any debugging tips too!


Solution

  • The code below returns a DOM Node Snapshot.

    const mySelector = Selector('span').withText('text');
    const snapshot   = await mySelector();
    

    In your test scenario you can do something like this:

    await t
    
        .expect(mySelector.withText('some text').nextSibling().getAttribute('id')).eql('id1');
    

    Note: TestCafe allows you to debug server-side test code and test behavior on the client