browser.getCurrentUrl() 只在一次测试中给我 "UnhandledPromiseRejectionWarning"
browser.getCurrentUrl() is giving me "UnhandledPromiseRejectionWarning" in only one Test
我将测试更改为 async/await,此后 browser.getCurrentUrl() 工作正常,除了此测试:
(Filling out a Form)
...
await element(by.id('auftrag-disponieren')).click();
await browser.wait(EC.visibilityOf($('list')), 1000).catch((e) => {
console.log(e);
});
since('How it should be, but is #{actual}').
expect(await browser.getCurrentUrl()).toContain("https://someRandomDomain.com");
})
});
抛出以下警告但仍通过测试:
>(node:13760) UnhandledPromiseRejectionWarning: Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
at runWaitForAngularScript.then (C:\Users\mat\AppData\Roaming\npm\node_modules\protractor\built\browser.js:463:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:13760) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13760) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13760) UnhandledPromiseRejectionWarning: Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
at runWaitForAngularScript.then (C:\Users\mat\AppData\Roaming\npm\node_modules\protractor\built\browser.js:463:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:13760) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I̶f̶ ̶I̶ ̶g̶e̶t̶ ̶t̶h̶e̶ ̶c̶u̶r̶r̶e̶n̶t̶ ̶u̶r̶l̶ ̶b̶e̶f̶o̶r̶e̶ ̶t̶h̶e̶ ̶c̶l̶i̶c̶k̶ ̶i̶t̶ ̶a̶l̶s̶o̶ ̶f̶a̶i̶l̶s̶,̶ ̶s̶o̶ ̶i̶t̶'̶s̶ ̶n̶o̶t̶ ̶b̶e̶c̶a̶u̶s̶e̶ ̶o̶f̶ ̶t̶h̶e̶ ̶r̶e̶d̶i̶r̶e̶c̶t̶.̶ ̶P̶l̶a̶c̶i̶n̶g̶ ̶a̶ ̶t̶r̶y̶-̶c̶a̶t̶c̶h̶ ̶b̶l̶o̶c̶k̶ ̶a̶r̶o̶u̶n̶d̶ ̶i̶t̶ ̶w̶o̶n̶'̶t̶ ̶h̶e̶l̶p̶ ̶e̶i̶t̶h̶e̶r̶.̶ ̶
我在不同的测试中多次使用 browser.getCurrentUrl()
,但这是我唯一收到此警告的测试。
编辑:
禁用 since()
功能并尝试 await expect(..).toContain(..)
没有帮助。我得到了和以前一样的结果。
我也许应该提到我有以下功能
afterAll(async () => {
await browser.get("https://someRandomDomain.com/dashboard")
})
编辑2:
我认为警告来自 afterAll(async () => {await browser.get("https://someRandomDomain.com/dashboard")})
函数。自评论此行以来,我没有收到这些警告。但是我仍然在不同的测试中使用这个函数,他们不会抛出这些警告。
试试下面的
since('How it should be, but is #{actual}').
await browser.waiForAngularEnabled(false);//true if your application is angular
await expect(await browser.getCurrentUrl()).toContain("https://someRandomDomain.com");
})
在 expect
:
之前尝试 await
await expect(...).toContain(...);
我通过将 afterAll 更改为:
来修复它
afterAll(async () => {
await browser.driver.get("https://someRandomDomain.com/dashboard");
await browser.driver.sleep(1000);
});
我将测试更改为 async/await,此后 browser.getCurrentUrl() 工作正常,除了此测试:
(Filling out a Form)
...
await element(by.id('auftrag-disponieren')).click();
await browser.wait(EC.visibilityOf($('list')), 1000).catch((e) => {
console.log(e);
});
since('How it should be, but is #{actual}').
expect(await browser.getCurrentUrl()).toContain("https://someRandomDomain.com");
})
});
抛出以下警告但仍通过测试:
>(node:13760) UnhandledPromiseRejectionWarning: Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
at runWaitForAngularScript.then (C:\Users\mat\AppData\Roaming\npm\node_modules\protractor\built\browser.js:463:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:13760) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13760) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13760) UnhandledPromiseRejectionWarning: Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
at runWaitForAngularScript.then (C:\Users\mat\AppData\Roaming\npm\node_modules\protractor\built\browser.js:463:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:13760) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I̶f̶ ̶I̶ ̶g̶e̶t̶ ̶t̶h̶e̶ ̶c̶u̶r̶r̶e̶n̶t̶ ̶u̶r̶l̶ ̶b̶e̶f̶o̶r̶e̶ ̶t̶h̶e̶ ̶c̶l̶i̶c̶k̶ ̶i̶t̶ ̶a̶l̶s̶o̶ ̶f̶a̶i̶l̶s̶,̶ ̶s̶o̶ ̶i̶t̶'̶s̶ ̶n̶o̶t̶ ̶b̶e̶c̶a̶u̶s̶e̶ ̶o̶f̶ ̶t̶h̶e̶ ̶r̶e̶d̶i̶r̶e̶c̶t̶.̶ ̶P̶l̶a̶c̶i̶n̶g̶ ̶a̶ ̶t̶r̶y̶-̶c̶a̶t̶c̶h̶ ̶b̶l̶o̶c̶k̶ ̶a̶r̶o̶u̶n̶d̶ ̶i̶t̶ ̶w̶o̶n̶'̶t̶ ̶h̶e̶l̶p̶ ̶e̶i̶t̶h̶e̶r̶.̶ ̶
我在不同的测试中多次使用 browser.getCurrentUrl()
,但这是我唯一收到此警告的测试。
编辑:
禁用 since()
功能并尝试 await expect(..).toContain(..)
没有帮助。我得到了和以前一样的结果。
我也许应该提到我有以下功能
afterAll(async () => {
await browser.get("https://someRandomDomain.com/dashboard")
})
编辑2:
我认为警告来自 afterAll(async () => {await browser.get("https://someRandomDomain.com/dashboard")})
函数。自评论此行以来,我没有收到这些警告。但是我仍然在不同的测试中使用这个函数,他们不会抛出这些警告。
试试下面的
since('How it should be, but is #{actual}').
await browser.waiForAngularEnabled(false);//true if your application is angular
await expect(await browser.getCurrentUrl()).toContain("https://someRandomDomain.com");
})
在 expect
:
await
await expect(...).toContain(...);
我通过将 afterAll 更改为:
来修复它afterAll(async () => {
await browser.driver.get("https://someRandomDomain.com/dashboard");
await browser.driver.sleep(1000);
});