javascript - 很多时候 cypress 无法访问 /auth 页面并且找不到 id 或 class
问题描述
我正在尝试/auth
使用以下代码访问路径并使用 cypress 登录:
Cypress.Commands.add('login', (email, password) => {
cy.get('.auth').find('.login').should(($login) => {
expect($login).to.contain('auth.welcome')
})
cy.get('[name="email"]').type(email);
cy.get('[name="password"]').type(password);
cy.get('button.login')
.click();
})
但赛普拉斯失败并显示以下错误消息:
AssertionError: Timed out retrying: Expected to find element: `.auth`, but never found it.
有时代码有效,有时失败。
我的登录页面 url 是 (http://localhost:3000/) 或 (http://localhost:3000/auth)
解决方案
此命令将等待元素:
cy.get('.auth').should('be.visible');
在与之交互之前添加此命令。
推荐阅读
- laravel-7 - 在 Finder.php 第 590 行:“”目录不退出。在生产中运行 php artisan optimize:clear 后
- javascript - 属性或方法“foo”未在实例上定义,但在渲染期间被引用
- android-studio - Android Studio Git 合并显示空白屏幕,冲突无法解决
- c# - C#在Datatable中添加动态列和行
- c# - 有没有办法根据收到的对象的类型来确定资产的范围?
- flutter - 如何解决新 Flutter 更新中的快照问题?
- android - React Native 应用程序在杀死时增加存储用户数据和缓存大小
- python - 将插入排序实现为快速排序时出错
- excel - 使用 VBA 粘贴 Excel 行
- python - 如何获取pdf的特定部分?