Is there an efficient way to assert that all the elements of a PageObject are visible?

时间:2015-12-03 10:37:15

标签: pageobjects nightwatch.js

It's great how you can describe key elements of a page using the elements object in nightwatch's PageObject.

A very basic test of "is the page rendered correctly?" seems to consist of a string of asserts that every element is visible:

 'Does it look right' : function (browser) {
      browser.page.welcome()
         .navigate()
         .assert.title('My App')
         .assert.visible('@header')
         .assert.visible('@usernameField')
         .assert.visible('@passwordField')
         .assert.visible('@forgotPasswordLink')
         .assert.visible('@signupButton') 

Is there a more efficient way to do this?

1 个答案:

答案 0 :(得分:0)

您可以使用自定义逻辑运行脚本,然后针对该

进行测试
    var script = function () {
      //some logic or query selector test
      return foo;
    };

   module.exports = {
  'Test PCC': function (browser) {

    var test;

    browser
      url('foo')
      .waitForElementVisible('body', 1000)
      .execute(script, [], function (response) {
        console.log(response);
        test = response.value;
      })

      //assert. test is something
      .end();
  }
};