【问题标题】:page object: visit <page_url> in nightwatch.js页面对象:访问 nightwatch.js 中的 <page_url>
【发布时间】:2016-07-12 06:09:57
【问题描述】:

GebWATIR 中,我们使用某些关键字来访问我们在页面类中指定的page_url。例如。 Geb 中的 to 关键字和 WATIR 中的 visit 关键字。

我们可以在nightwatch.js 中使用什么类似的东西。这是我尝试过的,但它给出了错误:

我试过了:

module.exports = {
    url: function () {
        return this.api.globals.launchUrl + "/goto/desiredPage.html";
    },
    commands: [pageCommands],
    elements: {}
};

在页面类中,我将其用作:

desiredPage
          .url()   
          .foo()
          .bar();
client.end();

但它给出了错误.url is not a function

【问题讨论】:

    标签: javascript nightwatch.js


    【解决方案1】:

    您可以在 nightwatch 文件夹中查看 nightwatch 示例,例如:

    [page-objects/home.js]
    var searchCommands = {
      submit: function() {
        this.waitForElementVisible('@submitButton', 3000)
          .click('@submitButton')
          .api.pause(1000);
        return this; // Return page object for chaining
      }
    };
    
    module.exports = {
      url: 'http://google.com',
      commands: [searchCommands],
      elements: {
        searchBar: { selector: 'input[name=q]' },
        submitButton: { selector: 'button[type=submit]' }
      }
    }; 
    

    然后在测试中:

    /* jshint expr: true */
    module.exports = {
      'Demo Google search test using page objects' : function (client) {
        var homePage = client.page.home();
        homePage.navigate();
        homePage.expect.element('@searchBar').to.be.enabled;
    
        homePage
          .setValue('@searchBar', 'Nightwatch.js')
          .submit();
    
        var resultsPage = client.page.searchResults();
        resultsPage.expect.element('@results').to.be.present.after(2000);
        resultsPage.expect.element('@results').to.contain.text('Nightwatch.js');
        resultsPage.expect.section('@menu').to.be.visible;
    
        var menuSection = resultsPage.section.menu;
        menuSection.expect.element('@web').to.be.visible;
        menuSection.expect.element('@video').to.be.visible;
        menuSection.expect.element('@images').to.be.visible;
        menuSection.expect.element('@shopping').to.be.visible;
    
        menuSection.productIsSelected('@web', function(result) {
          this.assert.ok(result, 'Web results are shown by default on search results page');
        });
    
        client.end();
      }
    };
    

    所以页面中的“url()”命令不存在,你需要在页面中定义url并使用“navigate()”代替。

    【讨论】:

      猜你喜欢
      • 2018-06-14
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多