![](/img/trans.png)
[英]How can we test the alert and the text it is displaying using Cypress.io Js automation framework?
[英]How to handle a windows prompt in a test automation using Cypress?
我是使用赛普拉斯进行网络自动化的新手。 我仍在通过互联网寻找答案,但我找不到适合我的解决方案。
这就是我在测试中尝试做的事情:
target
属性。)第一场斗争- 我无法在 Windows 提示符中输入值。 在下面的代码中,我试图查看是否会单击 Windows 提示符上的“登录”按钮,但事实并非如此。
cy.window().then(win => {
cy.get('@documentPassword').then((finalPassword) => {
const stub =cy.stub(win, 'prompt')
stub.returns('test')
cy.get('button#signin').click()
})
})
我收到断言错误: Timed out retrying after 25000ms: Expected to find element: button#signin, but never found it.
在没有运气之后,我转向另一个建议。
第二个斗争- 我尝试将用户名和密码放入链接中,如下所示: https://username:password@mytestingwebsite.com
。 请注意,当我将链接手动粘贴到浏览器中时,它可以工作。 为了测试这一点,这是我所做的:
cy.visit('https://mailtrap.io')
// ...other steps
cy.forceVisit('https://username:password@mytestingwebsite.com')
我在commands.js
文件中添加了一个自定义命令forceVisit
:
Cypress.Commands.add('forceVisit', url => {
cy.window().then(win => {
return win.open(url, '_self');
});
});
结果是第二个 url 没有加载。
希望大家多多指教。 提前致谢。
这对我有用:
cy.visit('https://mytestingwebsite.com', {
auth: {
username: 'username',
password: 'password'
}
})
这在我第一次尝试时对我不起作用,因为我仍然在 url 中传递了凭据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.