如何跳过测试Nightwatch.js?

时间:2016-01-20 16:24:02

标签: javascript selenium nightwatch.js

我现在使用nightwatch.js,mocha.js和selenium web驱动程序进行验收测试。 我需要跳过一些测试,我该怎么做?

module.exports = {

"User logs in the WebPortal": function(browser) {
browser
  .url(urlAdress)
  .setValue('input#login', user.login)
  .setValue('input#password', user.password)
  .click('button.ui-button')
  .waitForElementPresent('a[href="/logout"]', middleTimer)
  .getText('a[href="/logout"] span', function(result) {
    (result.value).should.be.exactly("logout")
  })
  .end()
},
"User logs out": function(browser) {
browser
  .url(urlAdress)
  .setValue('input#login', user.login)
  .setValue('input#password', user.password)
  .click('button.ui-button')
  .waitForElementPresent('a[href="/logout"]', middleTimer)
  .click('a[href="/logout"]')
  .waitForElementPresent('button.ui-button', middleTimer)
  .getText('button.ui-button', function(result) {
    (result.value).should.be.exactly("Login")
  })
  .end()
}
}

那么,如何跳过一个或多个测试? 谢谢你的回答。

2 个答案:

答案 0 :(得分:7)

不使用MochaGrunt。我可以跳过使用:

  1. 像这样使用'@disabled': true,

    after module.exports = {
       '@disabled': true,
    

    它会跳过module.exports = {

    内的所有内容

    并在控制台中打印skip语句

  2. 跳过特定测试:

    在您的.js文件中,如果您有太多测试并且想要跳过特定测试, 在测试''+之前使用function作为前缀,如下所示:

    'Test 1': '' + function (client) {
     },
    'Test 2': '' + function (client) {
     },
    'Test 3': function (client) {
     }
    

    将跳过前两个测试,第三个测试将被执行。不会打印跳过声明。

答案 1 :(得分:2)

您可以使用感叹号!或其他一些有效字符为函数关键字添加前缀:

"User logs in the WebPortal": !function(browser) {
  browser
  .url(urlAdress)
  ...
  .end()
},

以这种方式标记的测试将不会执行。

相关问题