gpt4 book ai didi

angular - Protractor 测试重定向

转载 作者:行者123 更新时间:2023-11-28 20:26:40 24 4
gpt4 key购买 nike

我有一个要测试的 Angular 应用程序。它有登录部分,我需要以某种方式知道它是否正常工作(它发送登录数据、打开套接字连接、重定向到应用程序深度并且路由守卫没有阻止该重定向)。

我试过了

import { AppPage } from './app.po';
import { browser, by, element, until } from "protractor";
import urlContains = until.urlContains;

...

it('should log in', () => {
page.navigateTo();
page.fillInputs();
page.logIn();

browser.waitForAngular();
browser.wait(() => {
return urlContains('dashboard');
}, 2000);
});

即使我用不正确的数据填充字段并且应用程序不进行任何重定向,它也会成功。如何实现此重定向等待然后检查 url?

如果它很重要,我会使用 Angular 6。

是的,我看过一个类似的主题,但我不明白答案。

最佳答案

看来我可能有一个旧版本的 Protractor ,我在 until 命名空间中找不到 urlContains 方法。我与 ExpectedConditions 一起工作对我来说效果很好。

因此使用预期条件,您可以拥有如下代码:

expect(
browser.wait(
protractor.ExpectedConditions.urlContains("dashboard"), 5000
)
.catch(() => {return false})
).toBeTruthy(`Url match could not succced`);

我喜欢使用 catch,这样脚本就不会在出现错误时停止。此外,expect() 将标记一个测试用例(有助于阅读生成的报告)。

关于angular - Protractor 测试重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53431245/

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