browser.getCurrentUrl()仅在一次测试中给我“ UnhandledPromiseRejectionWarning”

时间:2019-04-04 08:16:23

标签: javascript selenium protractor e2e-testing

我将测试更改为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)

如果我得到当前的URL之前点击它也失败,所以̶不̶i̶t̶'̶s̶因为̶r̶e̶d̶i̶r̶e̶c̶t̶.̶放置try-catch块围绕它不会致使帮助̶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")})函数。自从注释掉这一行以来,我没有收到这些警告。但是我仍然在不同的测试中使用此功能,它们不会抛出这些警告。

3 个答案:

答案 0 :(得分:0)

尝试以下一个

    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");

  })

答案 1 :(得分:0)

await之前尝试expect

await expect(...).toContain(...);

答案 2 :(得分:0)

我通过将afterAll更改为:

afterAll(async () => {
        await browser.driver.get("https://someRandomDomain.com/dashboard");
        await browser.driver.sleep(1000);
    });