Expected transporter condition for an element containing any text

Is there a way to check if an element contains any text? I already found textToBePresentInElement, but this function checks the specified value and does not return the correct error if it fails.

I populate the element through the API, and it downloaded the bit later, so I want the browser to wait until some information appears in the element, and then check the value is correct.

As an alternative, it would also be very useful to get a specific error message when EC fails:

browser.wait(EC.textToBePresentInElement(element(by.binding('myvar')), "expected"), 5000);
+2
source share
2 answers

browser.wait() - :

browser.wait(EC.textToBePresentInElement(element(by.binding('myvar')), "expected"), 5000, "Text is not something I've expected");

. :


, - , :

var EC = protractor.ExpectedConditions;

var anyTextToBePresentInElement = function(elementFinder) {
  var hasText = function() {
    return elementFinder.getText().then(function(actualText) {
      return actualText;
    });
  };
  return EC.and(EC.presenceOf(elementFinder), hasText);
};

:

browser.wait(anyTextToBePresentInElement(element(by.binding('myvar')), 5000);
+8

, : return actualText; boolean. , :

var anyTextToBePresentInElement = function(elementFinder) {
  var EC = protractor.ExpectedConditions;
  var hasText = function() {
    return elementFinder.getText().then(function(actualText) {
      return !!actualText;
    });
  };
  return EC.and(EC.presenceOf(elementFinder), hasText);
};

:

var el = element(by.binding('myvar'));
browser.wait(anyTextToBePresentInElement(el, 5000, 'Element still has no text');
+1

Source: https://habr.com/ru/post/1683317/


All Articles