【问题标题】:Calling custom command in nightwatch.js在 nightwatch.js 中调用自定义命令
【发布时间】:2022-03-03 23:00:46
【问题描述】:

我想做的是在 nightwatch.js 中的另一个自定义命令中调用一个自定义命令(目的是使测试不那么脆弱)。

例如,在我的第一个自定义命令 (message1.js) 中,我可以有以下代码;

exports.command = function(browser) {
  this
    browser
      console.log('display this first')
  return this;

随后在我的第二个自定义命令 (message2.js) 中,我想先调用 message1.js 命令,然后执行其余代码。

例如;

exports.command = function(browser) {
 this
   browser
     //call the message1.js command
       console.log('display the second message')
 return this;

我试过用方法调用它;

exports.command = function(browser) {
  this
    browser
      .message1();
        console.log('display the second message')
  return this;

但这不起作用。

所以我的问题是;

是否可以在另一个自定义命令中调用一个自定义命令 如果没有,还有其他方法吗?

【问题讨论】:

    标签: command nightwatch.js


    【解决方案1】:

    是的,您可以将自定义命令链接在一起或与其他守夜方法一起使用:

    自定义方法openUrl.js:

    exports.command = function(url) {
        const browser = this;    
        browser.url(url);
        return this;
    

    }

    自定义方法openStackOverflow.js,调用openUrl.js

    exports.command = function(url) {
        const browser = this;
        browser.openUrl(url).waitForElementVisible('#submit-button');
        return this;
        }
    

    在测试中使用它们:

    'Open Stack Overflow': browser => {
        browser.openStackOverflow(`https://stackoverflow.com`);
     },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 2017-12-02
      • 2011-06-25
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      相关资源
      最近更新 更多