angularjs - 使用 navigateTo 后等待 AngularJS 初始化

标签 angularjs testing automated-tests web-testing testcafe

我注意到我必须使用navigateTo 进行使用已经过身份验证的用户的测试。如果我用 .page 定义它们,它只会让我返回登录屏幕,因为它似乎看不到 Angular 色/状态。

我认为这是有意的,但文档不是很清楚,但这是我做出的假设,可能会影响我的实际问题。

我还相信任何 beforeEach 逻辑都在 navigateTo 方法之前运行,这会破坏我们需要“waitForAngularJS”的逻辑。

我有一个 waitForAngularJS 方法,我从官方 waitForAngular 改编而来。它在没有身份验证的情况下使用时工作正常(当我可以使用 .page... 时)但是当我使用身份验证时它不会在“导航到”页面上运行。

fixture `demo1`
    .beforeEach(async () => {
        await waitForAngularJS();
    });

test('modal title', async t => {
    await t
        .useRole(regularUser)
        .navigateTo('http://127.0.0.1/some/page')
        // .. the "wait for angular" needs to run here, but can't
        .expect(Selector('.modal-title').innerText).eql('My Modal');
});

在那个地方放一个 .wait(1000) 解决了我的问题。当我使用 .debug() 时,我可以看出 waitForAngular 逻辑尚未在新页面上运行。

编辑:根据the forums ,逻辑顺序是对的:

opens the fixture page; executes the beforeEach function; executes the useRole command: goes to the role initialization page (the first argument of the useRole command), executes the initialization function and goes to the previously opened page as a registered user; resumes the test.

最佳答案

e2e 测试应该与用于呈现页面的框架无关。在我看来,您不应该使用像 waitForAngularJS 这样的方法。 只需像这样重写 expect 语句:

await t
  .expect(Selector('.modal-title').innerText).eql('My Modal', {timeout: 10000});

您还可以设置 assertion timeout直接在 TestCafe 命令行上。

关于angularjs - 使用 navigateTo 后等待 AngularJS 初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54875091/

相关文章:

javascript - AngularJS:无法访问 Controller 中的对象属性

javascript - 简化使用 $q.defer() promise 链接的 Angular 函数

angularjs - 如何在 Protractor 测试中获取页面上的所有内容/文本?

java - Chrome 不会找到 json 文件的长本地文件路径,而 Windows 资源管理器会找到它

javascript - 如何在使用 testcafe 运行测试之前单击按钮

javascript - 具有嵌套的 ng-repeat 和过滤器的 Angularjs 无限摘要循环

class - Angular.js 中的动态类

bash - bat : Make variable persistent across all tests

node.js - 通过多次调用计算异步函数的执行时间

testing - 使用另一个测试作为测试构造函数