t3mpwn
t3mpwn

Reputation: 91

How to use commands on sections in Nightwatch.js?

So basically I've started working with PageObjects and I'm having some issues.

  1. 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?

  1. [would say this question is a bonus because it's not related with question in title] I'm having problems when making an assertions on section in section. How to do this? I've tried a lot of ways, one of them is below:

browser.page.topMenu().expect.section('@loginBox').to.be.visible - this works - because it's only one section

browser.page.topMenu().expect.section('@loginBox').section('@unauthenticated').to.be.visible - doesn't work - I want to check if section unauthenticated which is inside loginBox section is visible. How to do this?

Thanks in advance for all answers, I've tried to figure this out myself without any success.

Upvotes: 3

Views: 2119

Answers (2)

dotch3
dotch3

Reputation: 11

The way to check if a section is visible should be:

loginBox.expect.section('@ unauthenticated').to.be.visible.before(1);

ref# NW github repository github pulllRequest

The high level commands only work with sections:. it is: asserts: visible, enabled, present.

Upvotes: 0

Beni Keyserman
Beni Keyserman

Reputation: 89

OK first let's break it down so it will be more readable:

var topMenu = browser.page.topMenu(); // Declare the page object.
var loginBox = topMenu.section.loginBox; // Declare the first section.
var unauthenticated = loginBox.section.unauthenticated // Declare the second section.

and so on...

Once you want to perform a command you can do:

loginBox.waitForElementVisible('@unauthenticated');

Note that the section selector should be declared:

sections: {
   unauthenticated: {
      selector: '.unauthenticated_title',
      elements: {
        sectionElements: '.selector_selector'
      }
   },
   anotherSection: {
      ...
   }
}

The second question is similar.

loginBox.expect.element('@ unauthenticated').to.be.visible;

Upvotes: 1

Related Questions