Nightwatch: Executing commands directly on sections?

Created on 12 Sep 2015  路  8Comments  路  Source: nightwatchjs/nightwatch

Hello, I was wondering if that's even possible.

I want to execute a command directly on some section. For example - I want to .waitForElementVisible directly on section (not on elements). Is it even possible? I've tried a lot of combinations, for example:

browser.page.topMenu().section.loginBox.section.unauthenticated.waitForElementVisible('@loginTooltip', 10000)

So it looks like this: topMenu() is my pageObject file, then there is loginBox section containing -> unauthenticated section containing -> loginTooltip section. I want to .waitForElementVisible on the last one section. How to do this? I know I can combine my sections without limitations, but how to work on them later on?

Best regards,
drptbl.

enhancement

Most helpful comment

Hello,
About that.
var loginToolTipSelector = browser.page.topMenu().section.loginBox.section.unauthenticated.section.loginToolTip.selector;
I believe that this is not an option since you'll get only the leaf selector, not the whole construct. if the loginToolTip.selector is the same in other branch of xpath you'll get false positive. In that case the section construct does not have a sense and you can have just parent element instead.

But back to the original issue: " calling directly on section"

If I have a section which I want to use also the same way as a element, I'll add a container element into it:
elements: { container: { selector: '.', locateStrategy: 'xpath' },
Now I can use:
list.section.segmentationsContainer.expect.element('@container).to.be.present'

All 8 comments

I use an expectation with a cb in my project. Something like:

browser.page.topMenu().section.loginBox.section.unauthenticated.expect.section('@loginTooltip').to.be.visible.before(10000);

That's a good solution for assertions. Thank you!

I'm wondering - what about commands instead of assertions? Like .click? Is there any way to execute those directly on sections?

Not currently but it's something we could look at adding.

A workaround would be something like:

var loginToolTipSelector = browser.page.topMenu().section.loginBox.section.unauthenticated.section.loginToolTip.selector;
browser.click(loginToolTipSelector);

You'll have to call useXpath/useCss directly if the locate strategy differs from the previous one.

This works excellent for now. Thank you :+1:!

Adding this feature would make less code to maintain, still it does the job and I'm happy with this :).

Hello,
About that.
var loginToolTipSelector = browser.page.topMenu().section.loginBox.section.unauthenticated.section.loginToolTip.selector;
I believe that this is not an option since you'll get only the leaf selector, not the whole construct. if the loginToolTip.selector is the same in other branch of xpath you'll get false positive. In that case the section construct does not have a sense and you can have just parent element instead.

But back to the original issue: " calling directly on section"

If I have a section which I want to use also the same way as a element, I'll add a container element into it:
elements: { container: { selector: '.', locateStrategy: 'xpath' },
Now I can use:
list.section.segmentationsContainer.expect.element('@container).to.be.present'

Waiting for this PR to be merged:
https://github.com/nightwatchjs/nightwatch/pull/1155
should do the job.

@sknopf Do we still have to use this workaround?

@sknopf Do we still have to use this workaround?

What would be the correct way for clicking a section element?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pieras2 picture Pieras2  路  3Comments

chaseconey picture chaseconey  路  4Comments

antogyn picture antogyn  路  4Comments

dakebl picture dakebl  路  4Comments

MateuszJeziorski picture MateuszJeziorski  路  3Comments