protractor icon indicating copy to clipboard operation
protractor copied to clipboard

browser.debugger() fails to pause test

Open jdgblinq opened this issue 11 years ago • 13 comments

I'm running 1.4 and 1.5 of protractor with webdriver standalone and chromedriver on Mac OSX. Setting browser.debugger() in a test and running protractor with the debug argument results in the debug prompt, but pressing c causes my test to fail on the line after the browser.debugger() statement.

Using debugger instead pauses the test where expected. I see browser.debugger() mentioned as far back as protractor 0.20 on the web, so I'm fairly certain it should work. How do I debug this situation?

jdgblinq avatar Jan 06 '15 18:01 jdgblinq

Can you share the code for your test which is failing? I believe this is all working as intended, but I'd like to make sure.

What browser.debugger does is insert a debug statement in the control flow. This is so that you can do this:

element(by.id('clickme')).click();
browser.debugger();
expect(element(by.id('output')).getText()).toEqual('hi');

And the test will pause after the element has been clicked but before the text is grabbed. Note that this is after the whole test has been executed and the asynchronous tasks have been queued up.

Now, this is expected to fail:

element(by.id('clickme')).click();
browser.debugger();
throw new Error('foo');

The code above should throw an error before the debug breakpoint is ever reached.

juliemr avatar Jan 06 '15 18:01 juliemr

This is my current code:

element(by.css('.navbar-organization a')).getText().then(function(text){console.log(text);})
browser.debugger();
expect(element(by.css('.navbar-organization')).element(by.css('.dropdown-menu li')).length).to.equal(2);

It fails with:

debug> c
debug> 
  1) navbar organizations dropdown displays a list of organizations when clicked

  0 passing (3s)
  1 failing

  1) navbar organizations dropdown displays a list of organizations when clicked:
     AssertionError: expected undefined to equal 2

jdgblinq avatar Jan 06 '15 19:01 jdgblinq

Well, I think your error is that element.length is not a valid property, since element returns a promise. You probably want element(...).count().

juliemr avatar Jan 06 '15 19:01 juliemr

Just to confirm - this looks like it should be failing for the same reason without the browser.debugger. Is it somehow passing then?

juliemr avatar Jan 06 '15 19:01 juliemr

I commented out the line after the debugger statement and it worked.

The behavior is just not as expected. I don't expect a failure after the debugger statement to prevent me from entering the debugger. I do understand that this is implemented using async code, so maybe it just needs to be documented somewhere for people coming from a synchronous language where this sort of thing isn't possible. I'm personally coming from Ruby on Rails and binding.pry.

jdgblinq avatar Jan 06 '15 19:01 jdgblinq

I'm confused. It's not preventing you from entering the debugger - you enter the debugger just fine. You continue, and it fails, as it looks like it should.

juliemr avatar Jan 06 '15 19:01 juliemr

I simply mean it's not pausing where I expected.

jdgblinq avatar Jan 06 '15 19:01 jdgblinq

I'm sorry, I still don't understand the problem. It pauses after the command above, which logs the text, correct? And it pauses before the line after?

What behavior are you expecting?

juliemr avatar Jan 06 '15 19:01 juliemr

No problem. Using this code:

element(by.css('.navbar-organization a')).getText().then(function(text){console.log(text);})
browser.debugger();
expect(element(by.css('.navbar-organization')).element(by.css('.dropdown-menu li')).length).to.equal(2);

It does not pause on the browser.debugger(); line. Coming from Ruby on Rails, the equivalent of this would be binding.pry. binding.pry would pause here. It does not care if you have an exception happening after it.

This code does pause as expected:

element(by.css('.navbar-organization a')).getText().then(function(text){console.log(text);})
browser.debugger();
/*expect(element(by.css('.navbar-organization')).element(by.css('.dropdown-menu li')).length).to.equal(2);*/

It's an async vs sync thing, I think.

jdgblinq avatar Jan 06 '15 19:01 jdgblinq

OK, I think what you are saying is just that browser.debugger() != debugger.

This is commented in http://angular.github.io/protractor/#/debugging, but I'll also update the function description to try to make it super clear that browser.debugger() isn't just an alias for debugger.

juliemr avatar Jan 06 '15 19:01 juliemr

It was clear to me before I opened this issue that browser.debugger != debugger. I didn't understand what those differences were, however. Does the documentation mention the case described above?

The documentation says We use browser.debugger(); instead of node's debugger; statement so that the test pauses after the get command has been executed. Using debugger; pauses the test after the get command is scheduled but has not yet been sent to the browser., but I don't know what the get command is in this context or what the implications might be.

Anyway, I'm clear on why browser.debugger() was not pausing now. Thanks for the help.

jdgblinq avatar Jan 06 '15 19:01 jdgblinq

Made some doc changes that hopefully clarify the issue.

juliemr avatar Jan 06 '15 20:01 juliemr

use browser.pause()

Alexgerman avatar Jan 28 '15 11:01 Alexgerman