Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor - Checking if input field has text

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>
like image 294
Sean Morris Avatar asked Jul 31 '15 10:07

Sean Morris


2 Answers

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)
like image 171
alecxe Avatar answered Sep 30 '22 06:09

alecxe


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);
  })
});
like image 28
maurycy Avatar answered Sep 30 '22 07:09

maurycy