cypress - 如何处理柏树中的新标签。如果子域是动态的?
问题描述
子域网址: https://localhost:8008/datasearch?actionId=772675
我无法将赛普拉斯中的新选项卡作为 cy.visit(' https://localhost:8008/datasearch?actionId=772675 ') 处理,因为在输入数据并单击提交按钮后,操作 ID 会不断变化。因为子域会在新选项卡上打开选项卡。我需要检查断言在新选项卡中打开的输出。
问候
库沙尔
解决方案
我假设在您的情况下,如果您的提交按钮位于“a”标签内,那么您可以执行类似的操作。如果您单击提交按钮,那么它将作为新选项卡打开,因此理想情况下,您应该在单击之前从“a”标签或提交按钮获取链接并传递给 aconst
并使用cy.visit()
context('Open as new tab in cypress', () => {
it('Test to open a new tab/subdomain in cypress', () => {
cy.visit('https://localhost:8008/');
cy.get('.mt-2 > .btn-primary').then(($ele)=>{ // if the button is in an '<a>' tag, you could grab something like this
const newUrl = Cypress.$($ele).attr('href');
cy.visit(newUrl);
})
})
})
推荐阅读
- ruby-on-rails - Authlogic活动字段到activated_at字段
- nuget - 如何获取所有 NuGet 相关操作/权限?
- html - 如何在角度 8 中垂直滚动两个 div?
- android - 如何在 android WebView 或视频播放器中加载 Twitch 直播
- python - 具有相同键的字典中列表的总和
- java - Apache poi workbookfactory 从 xlsx 创建 HSSFWorkbook,但我希望 XSSFWorkbook
- mongodb - 补丁返回 null 而不是注释
- javascript - 如何防止用户在 React 的多个浏览器选项卡中单击 UI 元素?
- nginx - GKE 上的 Ingress-nginx-controller 在安装 Eclipse che 后返回状态 302 ERR_TOO_MANY_REDIRECTS
- c - 关于c中的转义序列