I am trying to only use the expect nightwatch.js API to check the html page title, but I cannot get the correct command.
My assumption would be to either check the inner text of the title element, or maybe its value, but it does not work as I expected.
If I run the following mocha test:
describe('Open Google', function () {
var expectedTitle = 'Google';
var uri = 'https://www.google.de';
it('should assert the page title', function (browser) {
browser.url(uri);
browser.expect.element('title').to.be.present.before(2000);
browser.assert.title(expectedTitle);
});
it('should verify title.text', function (browser) {
browser.url(uri);
browser.expect.element('title').to.be.present.before(2000);
browser.expect.element('title').text.to.equal(expectedTitle);
});
it('should verify title.value', function (browser) {
browser.url(uri);
browser.expect.element('title').to.be.present.before(2000);
browser.expect.element('title').value.to.equal(expectedTitle);
});
});
The assert statement works as expected, but with both ways to use expect, I don't get the page title.
Conclusion:
Open Google
√ should assert the page title (4787ms)
1) should verify title.text
2) should verify title.value
1 passing (12s)
2 failing
1) Open Google should verify title.text:
Expected element <title> text to equal: "Google" - Expected "equal 'Google'" but got: ""
at Context.<anonymous> (C:\temp\nightwatch-test\test\google.js:14:18)
2) Open Google should title.value:
Expected element <title> to have value equal: "Google" - Expected "equal 'Google'" but got: "null"
at Context.<anonymous> (C:\temp\nightwatch-test\test\google.js:20:18)
marcw source
share