You can use browser.debugger() to stop the execution. You can insert it any place in your code and it will stop the execution after that line until you don't command to continue.
Note: To run the tests in debugger mode you have to issue command like this:
`protractor debug <configuration.file.js>`
Enter c
to start execution and continue after the breakpoint or enter next
command.The next command steps to the next line in control flow.
The debugger used in Protractor uses node debugger and it pause the execution in asynchronous way. For example, in below code the browser.debugger()
will get called when username.sendKeys('username')
has been executed.
Note: Since these are asynchronous tasks, you would have to increase the default timeout of your specs else default timeout exception would be thrown!
it('should pause when we use pause method', function () {
browser.get('/index.html');
var username = element(by.model('username'));
username.sendKeys('username');
browser.debugger();
var password = element(by.model('password'));
password.sendKeys('password');
});
One can enter the repl
mode by entering the command-
debug > repl
> element(by.model('abc')).sendKeys('xyz');
This will run the sendKeys command as the next task, then re-enter the debugger.
One can change the Port no.
they want to debug their scripts by just passing the port to the debugger method-
browser.debugger(4545); //will start the debugger in port 4545
The debugger()
method injects a client side from Protractor to browser and you can run few commands in browser console in order to fetch the elements. One of the example to use client side script is:
window.clientSideScripts.findInputs('username');