I'm getting the empty string back from a getText() call. I've got this in my index.html:
<title ng-bind="pageTitle"></title>
This is in my controller:
$scope.pageTitle = "banana";
This is in my protractor test:
var pageTitle = element(by.binding('pageTitle'));
expect(pageTitle.getText()).toBe('banana');
The page title is displayed correctly in the browser, even when selenium pops up a window for the test, but my test always fails saying "Expected '' to be 'banana'". Nobody wants their empty strings to be bananas, just their bananas.
I'm aware that getText() doesn't work with input elements, but this is a title element.
Thanks!
I've also tried this approach, to see if it was a laziness issue:
element(by.binding('pageTitle')).getText().then(function (title) {
expect(title).toBe('banana');
});
Title isn't a visible element to the user, so webdriver doesn't return it as having text. You probably want
browser.getTitle()
getinnerhtml and getattribute(text) will also work:
describe('test', function() {
it('title', function() {
browser.get('index.html');
var title = element(by.css('title'));
expect(title.getInnerHtml()).toEqual('My AngularJS App');
expect(title.getAttribute("text")).toEqual('My AngularJS App');
});
});
Oh I see, so webdriver's not delivering the content that way? That explains why it wouldn't work (although it seems odd, because the title is shown by most browsers). Thanks for the suggestions though, they've got me on my way.
Most helpful comment
Title isn't a visible element to the user, so webdriver doesn't return it as having text. You probably want
browser.getTitle()