Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 512
G-key Avatar asked Nov 27 '18 18:11

G-key


People also ask

How do I select a element in TestCafe?

You can pass selectors to test actions to specify the action's target element. import { Selector } from 'testcafe'; fixture `My fixture` . page `http://devexpress.github.io/testcafe/example/`; const label = Selector('#tried-section'). child('label'); test('My Test', async t => { await t.

Can we use XPath in TestCafe?

Yes, We can use Custom XPath in testcafe, Create a custom function, import it into your test file.

How do you assert in TestCafe?

You can specify the assertion query timeout in test code with the options. timeout option. To set the timeout when you launch tests, pass the timeout value to the runner. run method if you use API or specify the assertion-timeout option if you run TestCafe from the command line.


1 Answers

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

like image 149
Vladimir A. Avatar answered Oct 16 '22 14:10

Vladimir A.