today0 2020-06-08
一.启动Cypress
进入cypress安装目录,输入yarn run cypress open 启动cypress

二.启动测试项目
进入到项目文件夹启动测试项目

三.编写测试脚本
在生成的integration文件夹下编写测试用例testLogin.js
//testLogin.js
///<reference types="cypress"/>
describe(‘登录‘, function(){
//此用户名密码服务器默认
const username = ‘jane.lane‘
const password = ‘password123‘
context(‘HTML 表单登录测试‘,function(){
it(‘登陆成功,跳转到dashboard页‘,function(){
cy.visit(‘http://localhost:7077/login‘)
cy.get(‘input[name=username]‘).type(username)
cy.get(‘input[name=password]‘).type(password)
cy.get(‘form‘).submit()
//断言,验证登陆成功则跳转dashbard页面
//断言,验证用户名存在
cy.url().should(‘include‘, ‘/dashboard‘)
cy.get(‘h1‘).should(‘contain‘,‘jane.lane‘)
}
)
}
)
}
) 
四.在Cypress中运行测试脚本
在启动的Cypress中点击添加的测试脚本,运行。

五.查看断言结果及相关页面
