Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip test Nightwatch.js?

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.

like image 274
Arsenowitch Avatar asked Jan 20 '16 16:01

Arsenowitch


People also ask

How do you run a single test on Nightwatch?

You can also execute a single test with the --test flag, e.g. Show activity on this post. just add it to your test case: module.

What is the script command for Nightwatch?

Use the command: npm install --save-dev nightwatch chromedriver. 1.

How do you run multiple test cases on Nightwatch?

To execute tests in multiple browsers, you need to add the desired capabilities of the browsers and Test_worker configurations in nightwatch. json file. For example if you want to execute tests in three browsers parallely - Chrome, Firefox and Opera, your nightwatch. json should something like this.


2 Answers

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.

like image 199
paul Avatar answered Oct 12 '22 12:10

paul


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.

like image 26
eBuster Avatar answered Oct 12 '22 14:10

eBuster