端到端测试:- 量角器错误:未知错误:调用函数结果缺少'value'



这是页面对象中的代码。

getPageTitle () {
return browser.getTitle (); 
}

在我的脚本中,我写下了这段代码。

it('Title should be Project', () => {
page.navigateTo();
page.getPageTitle()
.then((title: string) => {
expect(title).toEqual('Project');
});
});

之后,我收到此错误。我不知道为什么我会有这个,而我的标题写得很好。

1) project App Title should be Project
- Failed: unknown error: call function result missing 'value'
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.13.0-41-generic x86_64)
Executed 1 of 1 spec (1 FAILED) in 0.699 sec.
[11:55:50] I/launcher - 0 instance(s) of WebDriver still running
[11:55:50] I/launcher - chrome #01 failed 1 test(s)
[11:55:50] I/launcher - overall: 1 failed spec(s)
[11:55:50] E/launcher - Process exited with error code 1
(node:26179) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@0.0.0 e2e: `protractor "./protractor.conf.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.0.0 e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/student-08/.npm/_logs/2018-05-23T09_55_51_005Z-debug.log
Some end-to-end tests failed, see above.

我也尝试过这个:

it('Title should be Project', () => {
page.navigateTo();
expect(page.getPageTitle()).toEqual('Project');
})

但仍然有同样的问题。 知道我做错了什么吗?

我的猜测是标题加载有延迟。因此,与其检查标题,不如尝试在page.navigateTo()后等待它:

browser.wait(ExpectedConditions.titleIs('Project'));

最新更新