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>
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)
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);
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With