正文
保存文件后,Cypress会自动加载执行脚本,并运行输出测试结果。上述代码没有断言,测试结果也是通过的。
2、 查询页面元素。通过脚本查询页面上某个元素,将脚本修改为如下:
describe('My First Test', () => {
it('finds the content "type"', () => {
cy.visit('https://example.cypress.io')
cy.contains('type')
})
})
此时运行时通过的,因为页面上包含type元素。如果找不到对应的元素,测试结果则会是失败。而且Cypress在失败后会自动等待并重试。
3、 点击一个元素。查找到某个元素后,执行点击动作,使用.click方法。
describe('My First Test', () => {
it('clicks the link "type"', () => {
cy.visit('https://example.cypress.io')
cy.contains('type').click()
})
})
4、 使用断言。
对单击的新页面上的内容进行断言,确保新的URL是预期的URL,使用.should方法。
describe('My First Test', () => {
it('clicking "type" navigates to a new url', ()