2

I have a question on debugging Protractor script in Intellij Idea 14. I did set up Dubuger configuration per this doc: protractor/docs/debugging.md and tried to debug my code by putting break-point against console.log to check value of lblInvalidLoginMsg object:

it('should do something', function() {
  txtEmail.sendKeys("aaa@asd.com");
  txtPassword.sendKeys("aaaaa");
  btnSignIn.click();
  lblInvalidLoginMsg.getAttribute('value').then(function(){
    console.log("hello");
  })

  expect(lblInvalidLoginMsg.getAttribute('value')).toEqual('Blah Blah');
});

The problem is that debugger is showing no values when breakpoint is encountered. Debugger watch just shows me list of available methods i can apply against the object like getText(), getID() etc but no values that are expected.

Console output gives something like:

‌‌lblInvalidLoginMsg.getId()
‌ElementFinder
‌‌lblInvalidLoginMsg.isElementPresent();
‌webdriver.promise.Promise

Same goes with "Evaluate" feature. Is there something I am missing?

Updated: Added screenshot with my script in Debug mode + debug config + results from Protractor console. enter image description here

Vlad
  • 121
  • 1
  • 2
  • 7

1 Answers1

2

Protractor heavily relies on a concept of promises. To see the actual values of the element's text or attributes, you need to resolve them using then(). Example:

element(by.id('#myId')).then(function(elm) {
    elm.getText().then(function (text) {
        console.log(text);  // put a breakpoint here
    });  
});

or:

lblInvalidLoginMsg.getAttribute('value').then(function(value) {
    console.log(value);  // value here would contain an actual attribute value
});

Also, when the protractor is paused for debugging, you can use browser developer tools and call protractor's injected client-side script commands, see:

See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Hi Alex,Thank you for your suggestions. I was able to get Protractor elementExplorer.js working but Debugging in IntelliJ Idea is still a mystery to me. I did set up breakpoint inside the then() statement per your suggestion but as before getting nothing but list of available element methods. I updated my original post with screenshot of my script in debug mode + debugger configuration + results from Protractor elementExplorer console. – Vlad Dec 30 '14 at 17:59
  • @Vlad this is actually correct. You are getting an element instance with available methods. All of them would return a promise. For example, if you want to get the value of `getText()`, you need to write `elm.getText().then(function (text) { console.log(text); });`.. – alecxe Jan 06 '15 at 15:22