我尝试仅使用expect API的nightwatch.js来验证html页面标题,但我无法正确使用该命令。
我的猜测是检查标题的内部文字'元素,或者它的价值,但它没有按照我的预期工作。
如果我运行以下mocha测试:
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);
});
});
断言语句按预期工作,但是使用expect的两种方式,我都没有收到页面标题。
输出是这样的:
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)