1

I have to assert the text by the below:

expect(accessPolicyPage.accessPolicyName).toEqual(element.all(by.binding("pol.name")).get(0).getText());

It is giving me some long error as below.

Expected 'Access Policy Name 01' to equal ({ ptor_: ({ controlFlow: Function, schedule: Function, setFileDetector: Function, getSession: Function, getCapabilities: Function, quit: Function, actions: Function, touchActions: Function, executeScript: Function, executeAsyncScript: Function, call: Function, wait: Function, sleep: Function, getWindowHandle: Function, getAllWindowHandles: Function, getPageSource: Function, close: Function, getCurrentUrl: Function, getTitle: Function, findElementInternal_: Function, findElementsInternal_: Function, takeScreenshot: Function, manage: Function, switc

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Deepak Sabastein
  • 197
  • 3
  • 16

3 Answers3

1

What you see printed on the console is a "scary" promise object representation. If you need a real value, resolve the promise explicitly with then():

element.all(by.binding("pol.name")).get(0).getText().then(function (text) {
    expect(accessPolicyPage.accessPolicyName).toEqual(text);
});

Or, since accessPolicyPage.accessPolicyName is an actual text defined beforehand, you can just swap the things in the matcher and let expect() resolve the promise implicitly:

expect(element.all(by.binding("pol.name")).get(0).getText()).toEqual(accessPolicyPage.accessPolicyName);

This option is simpler and generally recommended.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

In fact Protractor supports expectations for promises. But it only handles case, when first argument in expectation is promise. So following should work:

expect(somePromise).toEqual(someString);
expect(somePromise).toEqual(anotherPromise);

But this one won't:

expect(notPromise).toEqual(somePromise);
Segg3r
  • 466
  • 3
  • 6
0

getText() return a promise and not text,which needs to be handled.

Protractor: element.getText() returns an object and not String

Community
  • 1
  • 1
picstand
  • 141
  • 2
  • 13