我注意到我必须使用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/