gpt4 book ai didi

javascript - browser.navigate().back();导致 "document unloaded while waiting for result"错误

转载 作者:行者123 更新时间:2023-11-28 06:49:19 27 4
gpt4 key购买 nike

你好,我已经阅读了平台上的所有问题/答案,但没有一个能帮助我解决我的问题,问题是我有以下测试脚本:

it('Verify user sees the home page correctly when hitting back button', function () {
browser.get('/flight/los-angeles/');
expect(testUtils.getTextFromField(topSearchBarPage.airportDestLocator)).toContain("LAX");
element.all(by.css(".day-droppable.ui-droppable")).get(30).click();
element(by.css(".btn-primary")).click();
browser.navigate().back();
expect(browser.getTitle()).toMatch('page title');
expect(browser.getCurrentUrl()).toContain("/flight/los-angeles/");
});

然后我收到此错误:

UnknownError: javascript error: document unloaded while waiting for result

我可以看到(因为我已经设置了 sleep ),在执行 navigate.back() 后,测试立即尝试重新加载页面,并且当它尝试执行期望时,它抛出错误。

这是应用程序在导航后的样子。

reload

我已在 GitHub 中发布了该问题,以下是最重要的信息:

I had removed that step (the navigate back) and the expect function works, I had placed a browser.sleep(5000) right after the navigate.back() and that's how I found that it's trying to execute the next "expecs" on an "empty page".

然后,sjelin 添加了这个

I'm pretty sure the issue is actually just that element(by.css(".btn-primary")).click(); hasn't finished before browser.navigate().back(); happens. Try adding a browser.waitForAngular()

最后我评论了这一点。

@sjelin I've tried what you told and it does not work, in fact, the clicking action does happens and finishes when it should since I'm seeing the action being done while the test runs... so, I think that the problem here is the navigate().back() is opening or refreshing without URL, and the next actions are the ones throwing the errors.

最佳答案

如果您明确等待 click() 完成会怎样:

element(by.css(".btn-primary")).click().then(function () {
browser.navigate().back();

expect(browser.getTitle()).toMatch('page title');
expect(browser.getCurrentUrl()).toContain("/flight/los-angeles/");
});

关于javascript - browser.navigate().back();导致 "document unloaded while waiting for result"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111081/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com