5

I'm writing a simple protractor test that's intended to check if a certain input tag contains text after a button is clicked. I've tried a few things and I'm currently trying to use protractor.ExpectedConditions to check if it contains any text. Here's my code:

it("should click submit", function() {
    var EC = protractor.ExpectedConditions;
    var status = element(by.id('status'));
    $("#btnSubmitQuery").click();
    var condition = EC.textToBePresentInElement(status, 'C');
    browser.wait(condition, 8000, "Text is still not present");
    status.getText().then(function (text) {
        console.log(text);
    });
});

A REST call is made to a server once btnSubmitQuery is clicked but the problem is that I can never get any value for status. What happens when I run this code is that the browser just waits for 8 seconds then closes, even though I can see text in the element. Nothing gets logged to the console. Any ideas?

EDIT: The html element I'm checking looks like this:

<td><input id="status" type="text" class="form-control" placeholder="PaxStatus ..." value="{{paxInformation.status}}"ng-readonly="true"></td>
Sean Morris
  • 135
  • 2
  • 10

3 Answers3

7

Just to improve @maurycy's answer. There is a built-in Expected Condition for this particular case:

var EC = protractor.ExpectedConditions;
browser.wait(EC.textToBePresentInElementValue(status, 'C'), 5000)
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
6

Shouldn't it be more like that:

condition = function () {
  return status.getAttribute('value').then(function (value) {
    return value.length > 0
  })
};
browser.wait(condition, 8000, "Text is still not present").then(function () {
  status.getAttribute('value').then(function (text) {
    console.log(text);
  })
});
maurycy
  • 8,455
  • 1
  • 27
  • 44
  • It does seem to be working a little better with this approach - the browser isn't waiting for the full 8 seconds anymore but there is still no value being logged for text. I've edited my question to include the html element if it helps. – Sean Morris Jul 31 '15 at 11:19
  • That means that the condition was fullfiled, i think what's wrong now is that you try to getText of input, I've edited my answer, try with `getAttribute` – maurycy Jul 31 '15 at 11:23
  • That's done it - works a treat now. Thanks a million! – Sean Morris Jul 31 '15 at 11:28
  • Looks good, the key here being el.getAttribute('value) If I remember right, getText() does not get the text from an input field. It gets text from things like titles, and general text on the page. getAttribute('value) gets text from elements that YOU put the value into as a user of the webpage. – user2020347 Jul 31 '15 at 14:33
0

I am using this one

var EC = protractor.ExpectedConditions;
var txt = browser.wait(EC.textToBePresentInElementValue(status, 'C'), 5000)

return browser.wait(txt, 5000).catch(() => { 
throw new Error('Text is still not presentt');});
Lelik_
  • 7
  • 3