我们如何使用 Cypress.io Js 自动化框架测试警报和里面显示的文本? Cypress文档中的相关示例我无法理解,请指教。
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!')
})
})
})
关于javascript - 我们如何使用 Cypress.io Js 自动化框架测试警报及其显示的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51795306/