0

For below protractor mocha test cases, greeting.getText() will always return
below result instead of the string. Could anyone give me clue on this?

   describe('angularjs home', function () {
        it('Should welcome a user', function (done) {
            browser.get('http://www.angularjs.org');
            element(by.model('yourName')).sendKeys('tanshuai');    
            var greeting = element(by.binding('yourName'));
            console.log(greeting.getText());
            expect(greeting.getText()).to.eventually.equal('Hello tanshuai!');
        });
    });

The console.log output================

  ElementFinder {
      browser_:
       ProtractorBrowser {
         controlFlow: [Function],
         schedule: [Function],
         setFileDetector: [Function],
         getExecutor: [Function],
      ................................
      getId: [Function],
      takeScreenshot: [Function] }
user9405863
  • 1,506
  • 1
  • 11
  • 16
emma.l
  • 3
  • 1
  • 4

1 Answers1

0

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

Looks like getText() returns a promise and you need to resolve it. Check out the link above

Chris
  • 1,956
  • 1
  • 10
  • 12
  • Hi Chirs, Thanks. greeting.getText().then(function (text) { console.log(text); }); works for me. It print the expected result. But how to let expect() resolve the promise? expect(greeting.getText()).equal('Hello tanshuai!'); still did not work – emma.l Apr 18 '18 at 04:11
  • glad to hear it! – Chris Apr 18 '18 at 16:18