Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I use WebStorm to write my javascript tests. I have include Selenium WebDriver (+ chromedriver) to run my tests in browser. As a test-runner framework I use Mocha.

The problem is: when I try to debug my test and set a breakpoint into code, while debugging WebDriver does not starts. And as a result I could not see any variables realtime.

Code example:

// Add external libraries
var test = require('selenium-webdriver/testing'), webdriver = require('selenium-webdriver'), By = require('selenium-webdriver').By;
var mocha = require('./node_modules/mocha/mocha.js'), chai = require('chai'), chaiuse = require('chai-as-promised'), expect = require('chai').expect;
var assert = require('assert');
// global variable for webdriver browser
var browser;
// Main part with test suites
test.describe('Suite 1', function() {
    this.timeout(5000);
    test.beforeEach( function(){ // Executes before each test
        browser = new webdriver.Builder().usingServer().withCapabilities({ 'browserName' : 'chrome', 'timeout' : '5000' }).build();
    });
    test.afterEach( function(){ // Executes after each test
        browser.close();
    });
    test.it('Get Fields', function(done) {
        browser.get('http://google.com');
        var btnFirst = browser.wait(webdriver.until.elementLocated(webdriver.By.name('btnK'), 30000));
        var btnSecond = browser.findElement(webdriver.By.name('btnI')).getAttribute("name");
        btnSecond.then(function(text) {
            console.log("Name of Second button: " + text + "\n");
            assert.equal(text,'btnI','Button with name \'btnI\' not presented');
        });
        done();
    });
});

And so for now all process is like black-box tests development.

I have tried DevTools - a chrome console to work. But it just run all test without pause on breakpoints.Command:

devtool node_modules/mocha/bin/_mocha -qc -- ./Tests.js --break

On C# + Selenium WebDriver I have no problems with step by step debugging, but now I need to do that on JavaScript + Selenium WebDriver.

Please, give an advice?

share|improve this question

You can debug Mocha tests just like any Node.js script with the help of node-inspector :

  • Install and run node-inspector:

    npm install -g node-inspector node-inspector

  • Run your tests with break option: mocha [options] --debug-brk

  • Open the debugger in Chrome at url http://127.0.0.1:8080/?port=5858

You can set your breakpoints and enjoy debugging with Chrome Dev Tools!

Source: How to debug Mocha tests with Chrome

share|improve this answer
    
I still could not get elements from 'webdriver'. I have faced with the same behavior as other ways of debugging - webdriver graphically executes all commands after code was debugged. Even though I put breackpoints and successfully stepped my code. – Alex.K May 30 '16 at 15:39
    
@Alex.K You could add a debugger statement before the line you want the debugger to break, and see if it stops – Supersharp Jun 30 '16 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.