Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

browser.debugger() fails to pause test #1688

Closed
jdgblinq opened this issue Jan 6, 2015 · 13 comments
Closed

browser.debugger() fails to pause test #1688

jdgblinq opened this issue Jan 6, 2015 · 13 comments

Comments

@jdgblinq
Copy link

jdgblinq commented Jan 6, 2015

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?

@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

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.

@jdgblinq
Copy link
Author

jdgblinq commented Jan 6, 2015

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

@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

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
Copy link
Member

juliemr commented Jan 6, 2015

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

@jdgblinq
Copy link
Author

jdgblinq commented Jan 6, 2015

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.

@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

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.

@jdgblinq
Copy link
Author

jdgblinq commented Jan 6, 2015

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

@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

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?

@jdgblinq
Copy link
Author

jdgblinq commented Jan 6, 2015

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.

@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

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.

@jdgblinq
Copy link
Author

jdgblinq commented Jan 6, 2015

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.

@juliemr juliemr closed this as completed in 4e34424 Jan 6, 2015
@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

Made some doc changes that hopefully clarify the issue.

@Alexgerman
Copy link

use browser.pause()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants