android端到端测试工具,端到端测试神器 cypress 浅入浅出

我之前写过关于cypress的文章,https://segmentfault.com/a/11...,最近在工作中用到cypress比较多了,顿时觉得cypress确实是比较优秀的一个。

1. 软件安装.

2. 安装cypress

3. 初始化

假如项目目录是 /test

打开cypress客户端, 点击箭头位置,通过资源管理器选择/test目录

如果/test没有cypress目录,那么cypress就会在test目录下新建cypress目录,并初始化一些文件

1460000015653928?w=1600&h=1100

4. cypress目录分析

- cypress // cypress目录

---- fixtures 测试数据配置文件,可以使用fixture方法读取

---- integration 测试脚本文件

---- plugin 插件文件

---- support 支持文件

- cypress.json // cypress全局配置文件

5. 基本例子

一般流程

访问某个页面

查找DOM进行交互,例如输入,点击,选择之类

进行断言

describe('Hacker News登录测试', () => {

it('登录页面', () => {

cy.visit('https://news.ycombinator.com/login?goto=news')

cy.get('input[name="acct"]').eq(0).type('test')

cy.get('input[name="pw"]').eq(0).type('123456')

cy.get('input[value="login"]').click()

cy.get('body').should('contain', 'Bad login')

})

})

1460000015653929?w=894&h=535

6. DOM选取

jquery选择法

通过客户端GUI工具选取

7. DOM交互

.click() 单击

.dblclick() 双击

.type() 输入

.clear() 清空

.check() 选中

.uncheck() 取消选中

.select() 下拉框选择

.trigger() 反转

8. 断言

.contains() 查找匹配字符串

.should()

8.1. 长度断言

// retry until we find 3 matching

cy.get('li.selected').should('have.length', 3)

8.2. 类断言

// retry until this input does not have class disabled

cy.get('form').find('input').should('not.have.class', 'disabled')

8.3. 值断言

// retry until this textarea has the correct value

cy.get('textarea').should('have.value', 'foo bar baz')

8.4. 文本断言

// retry until this span does not contain 'click me'

cy.get('a').parent('span.help').should('not.contain', 'click me')

8.5. 可见性断言

// retry until this button is visible

cy.get('button').should('be.visible')

8.6. 存在性断言

// retry until loading spinner no longer exists

cy.get('#loading').should('not.exist')

8.7. 状态断言

// retry until our radio is checked

cy.get(':radio').should('be.checked')

9. 读取测试配置数据

Cypress.env() 可以读取全局配置

fixture(文件名).as(变量), 可以将文件中的配置数据读取为变量,作为后续的测试用例来使用,注意这一步是异步的,必须放在before或者beforeEach等钩子函数中使用

describe('软电话登录', function () {

before(() => {

cy.fixture(Cypress.env('envName') + '-login-data.json').as('loginData')

})

it('wellClient test', function () {

cy.log(this.loginData)

cy.visit(this.loginData.url)

cy.get('#config-env').select('CMB-TEST')

cy.get('#config').click()

cy.get('#well-code').type(this.loginData.jobNumber)

cy.get('#well-password').type(this.loginData.password)

cy.get('#well-namespace').type(this.loginData.domain)

cy.get('#well-deviceId').type(this.loginData.ext)

cy.get('#well-login').click()

cy.wait(3000)

cy.get('#well-login').should('not.be.visible')

})

})

10. 全局配置 cypress.json

11. 变量与别称

12. 钩子函数

before()

beforeEach()

afterEach()

after()

13. 最佳实践

其他

cy.window() 异步获取window对象,无法直接使用window对象

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值