最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to skip test Nightwatch.js? - Stack Overflow

programmeradmin2浏览0评论

I use nightwatch.js, mocha.js and selenium web driver for acceptance testing for now. And I need to skip some tests, how I can do it?

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()
}
}

So, how to skip one or more tests? Thank you for answers.

I use nightwatch.js, mocha.js and selenium web driver for acceptance testing for now. And I need to skip some tests, how I can do it?

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()
}
}

So, how to skip one or more tests? Thank you for answers.

Share Improve this question asked Jan 20, 2016 at 16:24 ArsenowitchArsenowitch 4015 silver badges22 bronze badges 3
  • Do you want to skip a test using mand line parameters, or by adding some code to the test case? – Jens Wegar Commented Feb 2, 2016 at 9:31
  • @Jens Wegar, thank you, but I found the solution by adding mocha.js wrapper to my tests! – Arsenowitch Commented Feb 2, 2016 at 9:38
  • Cool! Would be good if you can add your solution as an answer to this question and accept it, so it gets removed from the list of unanswered questions ;) – Jens Wegar Commented Feb 2, 2016 at 11:32
Add a ment  | 

2 Answers 2

Reset to default 12

Without using Mocha or Grunt. I am able to skip using:

  1. Use '@disabled': true, like this

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

    it will will skip everything inside module.exports = {

    and print skip statement in console

  2. Skip specific tests:

    In your .js file if you have so many tests and you want to skip specific test, use ''+ as prefix before test function in your test, like this:

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

    first two tests will be skipped and third will get executed. No skip statement will be printed.

You can just prefix function keyword with exclamation ! or some other valid character:

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

Tests marked by this way will not executed.

发布评论

评论列表(0)

  1. 暂无评论