Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug in nightwatch

I am trying to debug in nightwatch. When I put in a console.log it prints before the test runs - while its doing some sort of construction/compiling of the test. I tried also visual studio code debugger and same thing - the breakpoint hits before the tests are actually run. thanks for help - mark

like image 996
mark gibson Avatar asked Apr 12 '16 16:04

mark gibson


People also ask

What is the command to run the script Nightwatch?

You can add Nightwatch to your project simply by running npm install nightwatch --save-dev .

What is Nightwatch automation?

Nightwatch. js is an open-source automated testing framework that is powered by Node. js and provides complete E2E (end to end) solutions to automation testing with Selenium Javascript be it for web apps, browser apps, and websites.

What is Nightwatch JSON?

json is a configuration file which tells the Nightwatch tool where to find the stand-alone Selenium binary, browser drivers, location of the test, environment profile, and more. The package.json contains the metadata and node package dependencies for the project. The ci/functional-test.

What is Nightwatch in Selenium?

Nightwatch. js is an integrated, easy to use End-to-End testing solution for web applications and websites, written in Node. js. It uses the W3C WebDriver API to drive browsers and perform commands and assertions on DOM elements.


1 Answers

"nightwatch" is built on node.js. Node.js executes statements asynchronously. If you write console.log();, it will be executed asynchronously.

The statements you write using browser (or client) object (e.g. browser.url(); , browser.click(); etc.) will be queued up at Selenium Server. They are also executed asynchronously by node.js but are queued up at selenium server.

To perform console.log() in sync with other statements in nightwatch, use .perform(). You will get output in sync with other statements.

Example

var elementValue;
browser
.getValue('.some-element', function(result) {
  elementValue = result.value;
})
// other stuff going on ...
//
// self-completing callback
.perform(function() {
  console.log('elementValue', elementValue);
  // without any defined parameters, perform
  // completes immediately (synchronously)
})
.end();

For debugging purpose, you can stop the execution to find out element values or check the browser related data. Use this command: browser.pause(); (or client.pause();). Do not pass any timer here. It will stop the execution.

like image 135
Niraj Tathe Avatar answered Sep 23 '22 05:09

Niraj Tathe