javascript - 我们如何使用 Cypress.io Js 自动化框架测试警报及其显示的文本?
问题描述
我们如何测试使用 Cypress.io Js 自动化框架显示的警报和文本?我无法找出赛普拉斯文档中的相关示例,请告知。
describe('Test an alert and the text displaying', function() {
it('Verify alert and its text content', function(){
cy.visit('http://www.seleniumeasy.com/test/javascript-alert-box-demo.html')
cy.get('button').contains('Click me!').click()
cy.on ('window:alert', 'I am an alert box!')
})
})
解决方案
按照 Richard Matsen 的建议,使用 cy.stub() 方法找出答案:
describe('Test an alert and the text displaying', function() {
it('Verify alert and its text content', function(){
cy.visit('http://www.seleniumeasy.com/test/javascript-alert-box-demo.html')
const stub = cy.stub()
cy.on ('window:alert', stub)
cy
.get('button').contains('Click me!').click()
.then(() => {
expect(stub.getCall(0)).to.be.calledWith('I am an alert box!')
})
})
})
推荐阅读
- json - Flutter:如何在flutter中获取当前月份数据和选定月份数据
- javascript - javascript:数学表达式和替代变量
- testing - com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法使用 SSL 加密建立与 SQL Server 的安全连接
- python - 如何在 python 中将 Str() 类型的列转换为数字?
- django - 403 Forbidden nginx/1.18.0 (Ubuntu) for Django 3.1,在媒体文件和管理 css 中面临问题
- html - 如何使用 vscode 中的实时服务器在移动设备上查看我的 html 文件?
- airflow - AssertionError: 只能加入 Airlflow 2.0.1 中的子进程
- sql - 类似的方法,比如 presto 中的 TRY_CAST
- javascript - 如何在 Sentry 上设置源地图
- c - C 编程:“sizeof”对不完整类型“Tipo {aka struct ElemSCl}”的无效应用