德阳市住房和城乡建设局网站首页,百度助手免费下载,室内设计师培训班哪家好,html网站开发实例视频})
beforeEach(() {
// 在每一条案例之前执行
})
afterEach(() {
// 在每一条案例执行完成之后执行
})
it(‘测试表单验证案例’, () {})
// 只执行该案例
it.only(‘测试表单验证案例’, () {})
// 忽略该案例
it.skip(‘测试表单验证案例’, …})
beforeEach(() {
// 在每一条案例之前执行
})
afterEach(() {
// 在每一条案例执行完成之后执行
})
it(‘测试表单验证案例’, () {})
// 只执行该案例
it.only(‘测试表单验证案例’, () {})
// 忽略该案例
it.skip(‘测试表单验证案例’, () {})
})
2. 钩子函数里环境变量 可以访问cy对象
const $cyElement cy.get(‘.demo-ruleForm .el-form-item:first-child input’)
类似jquery可以链式调用
样式选择器连接如是
cy.get(‘.demo-ruleForm .el-form-item:first-child input’)
.should(‘have.value’, ‘’)
.focus()
.blur()
js基本变量语法
js基本语法api都支持但稍有不同
const arr [];
arr.forEach 可以访问
[].forEach 不可以访问
expect asset断言
assert.isOk(‘everything’, ‘everything is ok’)
expect(‘Jane’).to.not.equal(‘Jane’)
Cypress对象
Cypress提供了cy的一切api另外多了.$()方法用于返回jquery对象
便于操作dom
3. should里环境变量 可以访问Cypress对象
js基本变量语法
const $cyElement cy.get(‘.demo-ruleForm .el-form-item:first-child input’) c y E l e m e n t . s h o u l d ( cyElement.should( cyElement.should(el {
// 闭包环境里可以访问Cypress是个可以操作dom集合
// Cypress.dom 返回dom的api
// Cypress.$(dom) 返回jquery对象
const isDom Cypress.dom.isDom($el)
const j q E l C y p r e s s . jqEl Cypress. jqElCypress.($el[0])
expect(isDom).to.be.true
}) Cypress.$()返回jQuery对象可以访问jquery 的api Cypress.dom 返回dom的api Cpress.cy返回cy实例可以类似钩子函数里断言
4. 案例 代码如下
// https://docs.cypress.io/api/introduction/api.html
describe(‘自动化测试表单验证案例’, () {
before(() {
// 在全部案例执行之前执行一次
// 浏览器模式访问时可按照自己的需要设置窗口大小如 cy.viewport(1920,1100)
// 访问首页
cy.visit(‘http://localhost:2000/#/input-demo’)
})
after(() {
// 在全部案例执行完成之后执行一次
})
beforeEach(() {
// 在每一条案例之前执行
})
afterEach(() {
// 在每一条案例执行完成之后执行
})
// 案例一、测试表单验证案例
it(‘测试表单验证案例’, () {
cy.get(‘.demo-ruleForm .el-form-item:first-child input’)
.should(‘have.value’, ‘’)
.focus()
.blur()
cy.get(‘.demo-ruleForm .el-form-item__error’)
.should(‘contain’, ‘请输入活动名称’)
cy.get(‘.demo-ruleForm .el-form-item:first-child input’).type(‘测试数据’)
.blur()
cy.get(‘.demo-ruleForm .el-form-item__error’)
.should(‘not.be.visible’)
cy.get(‘.demo-ruleForm .el-form-item:first-child input’).type(‘测试数据测试数据’)
.blur()
cy.get(‘.demo-ruleForm .el-form-item__error’)
.should(‘contain’, ‘长度在 3 到 5 个字符’)
})
// 案例二、测试一些闭包环境变量及api
it(‘测试表单验证案例’, () {
// This is fine, jQuery returns the element synchronously.
// const $jqElement $(‘.demo-ruleForm .el-form-item:first-child input’)
// This will not work! Cypress does not return the element synchronously.
const $cyElement cy.get(‘.demo-ruleForm .el-form-item:first-child input’)
// cy操作类型jquery传入selector选择器但不可以直接操作dom
// 类似jquery可以链式调用
// js基本变量语法
// 但稍有不同
const arr [];
// arr.forEach 可以访问
// [].forEach 不可以访问 c y E l e m e n t . s h o u l d ( cyElement.should( cyElement.should(el {
// 闭包环境里可以访问Cypress是个可以操作dom集合
// Cypress.dom 返回dom的api
// Cypress.$(dom) 返回jquery对象
const isDom Cypress.dom.isDom($el)
const j q E l C y p r e s s . jqEl Cypress. jqElCypress.($el[0])
expect(isDom).to.be.true
})
})
})
四、获取dom元素 1.get 用法一、选择器定位
cy.get(selector)
用法二、以别名定位
cy.get(alias)
匹配多个元素时返回多个对象
2.find cy.get(selector).find(selector1)
定位方法用来在 DOM 树中搜索已被定位到的元素的后代例如get选中的后代元素
// 错误写法
cy.find(selector)
会报错需要一个父类选中元素 3.contains 两种用法如下
.contains(content)
.contains(selector, content)
支持cy.contains及cy.get().contains
重点只会返回第一个匹配到的元素
4.first 类似jquery的first方法
5.eq 类似jquery的eq方法eq(index) index从0开始获取第几个元素子元素
五、获取/设置dom元素属性 1. cy.$$(selectorcontext) ☆☆☆ cy.$$(‘input’) // 返回input元素的jquery对象
cy.$$(‘input’).value() // 可用用jquery的api
cy.$$(‘input’).text() // 例子等等
cy对象挂载在window下故环境变量this指向window时可用访问一般顶级作用域指向这个window可用通过箭头函数将内部作用域指向window访问cy
2. Cypress.$(selector) ☆☆☆ Cypress.$(‘input’) // 返回input元素的jquery对象
Cypress.$(‘input’).value() // 可用用jquery的api
Cypress.$(‘input’).text() // 例子等等
Cypress对象挂载在window下故环境变量this指向window时可用访问一般顶级作用域指向这个window可用通过箭头函数将内部作用域指向window访问Cypresss
3.should回调函数 ☆☆☆ 形参$e为jquery对象 Cpress.$ 返回jquery对象
利用jquery的api可以获取元素的dom属性
cy.get(‘.dom-demo’)
.should($e {
// $e jquery对象
// Cpress.$ 返回jquery对象
const text $e.find(‘.item’).first().text();
const text1 Cypress. ( ( (e[0]).find(‘.item’).first().text();
console.log(text text1) // true
})
4.cy对象的type方法 对input输入框的输入
cy.get(‘input’).type(‘text’)
cy.get(‘input’).type(‘2222’)
六、鼠标事件 1.单击事件click // 点击事件
cy.get(‘#btn’).click()
2.悬浮事件hover 版本不支持该事件有代替方案如下
cy.get(‘#btn’)
.trigger(‘mouserover’)
.wait(3000)
.rightclick()
.wait(3000)
.should(‘have.css’, ‘color’, ‘rgb(255, 255, 255)’)
3.双加事件dblclick // 双击事件
cy.get(‘#btn’).dblclick()
4.右击事件rightclick // 右击事件
cy.get(‘#btn’).rightclick()
5.聚焦事件focus // 聚焦事件
cy.get(‘input’).focus()
6.失焦事件blur // 失焦事件
cy.get(‘input’).blur()
总结案例 // 案例三、测试鼠标一些事件
it(‘测试鼠标一些事件’, () {
// 点击事件
cy.get(‘#btn’)
.click()
// 双击事件
cy.get(‘#btn’)
.dblclick()
// 右击事件
cy.get(‘#btn’)
.rightclick()
// 悬浮事件
// cy.get(‘#btn’).hover()
// 该事件本版本不支持
// 代替方案如下
cy.get(‘#btn’)
.trigger(‘mouserover’)
.wait(3000)
.rightclick()
.wait(3000)
.should(‘have.css’, ‘color’, ‘rgb(255, 255, 255)’)
// 聚焦事件
cy.get(‘#int’)
.focus()
// 失焦事件
cy.get(‘#int’)
.blur()
})
七、断言should、expect 每条案例都需要加断言及验证点否则是一条不完整的案例
一、should断言 1. dom断言
Length
// retry until we find 3 matching li.selected
cy.get(‘li.selected’).should(‘have.length’, 3)
Class
// retry until this input does not have class disabled
cy.get(‘form’).find(‘input’).should(‘not.have.class’, ‘disabled’)
Value
// retry until this textarea has the correct value
cy.get(‘textarea’).should(‘have.value’, ‘foo bar baz’)
Text Content
// retry until this span does not contain ‘click me’
cy.get(‘a’).parent(‘span.help’).should(‘not.contain’, ‘click me’)
Visibility
// retry until this button is visible
cy.get(‘button’).should(‘be.visible’)
Existence
// retry until loading spinner no longer exists
cy.get(‘#loading’).should(‘not.exist’)
State
// retry until our radio is checked
cy.get(‘:radio’).should(‘be.checked’)
CSS
// retry until .completed has matching css
cy.get(‘.completed’).should(‘have.css’, ‘text-decoration’, ‘line-through’)
// retry until .accordion css have display: none
cy.get(‘#accordion’).should(‘not.have.css’, ‘display’, ‘none’)
2. 回调函数
cy.get(‘div’)
.should(($div) {
expect($div).to.have.length(1)
const className $div[0].className
// className will be a string like “main-abc123 heading-xyz987”
expect(className).to.match(/heading-/)
})
二、expect断言 1. 断言入参不是dom对象时
| Chainer | Example |
| — | — |
| not | expect(name).to.not.equal(‘Jane’) |
| deep | expect(obj).to.deep.equal({ name: ‘Jane’ }) |
| nested | expect({a: {b: [‘x’, ‘y’]}}).to.have.nested.property(‘a.b[1]’) expect({a: {b: [‘x’, ‘y’]}}).to.nested.include({‘a.b[1]’: ‘y’}) |
| ordered | expect([1, 2]).to.have.ordered.members([1, 2]).but.not.have.ordered.members([2, 1]) |
| any | expect(arr).to.have.any.keys(‘age’) |
| all | expect(arr).to.have.all.keys(‘name’, ‘age’) |
| a(type) Aliases: an | expect(‘test’).to.be.a(‘string’) |
| include(value) Aliases: contain, includes, contains | expect([1,2,3]).to.include(2) |
| ok | expect(undefined).to.not.be.ok |
| true | expect(true).to.be.true |
| false | expect(false).to.be.false |
| null | expect(null).to.be.null |
| undefined | expect(undefined).to.be.undefined |
| exist | expect(myVar).to.exist |
| empty | expect([]).to.be.empty |
| arguments Aliases: Arguments | expect(arguments).to.be.arguments |
| equal(value) Aliases: equals, eq | expect(42).to.equal(42) |
| deep.equal(value) | expect({ name: ‘Jane’ }).to.deep.equal({ name: ‘Jane’ }) |
| eql(value) Aliases: eqls | expect({ name: ‘Jane’ }).to.eql({ name: ‘Jane’ }) |
| greaterThan(value) Aliases: gt, above | expect(10).to.be.greaterThan(5) |
| least(value)Aliases: gte | expect(10).to.be.at.least(10) |
| lessThan(value) Aliases: lt, below | expect(5).to.be.lessThan(10) |
| most(value) Aliases: lte | expect(‘test’).to.have.length.of.at.most(4) |
| within(start, finish) | expect(7).to.be.within(5,10) | 自我介绍一下小编13年上海交大毕业曾经在小公司待过也去过华为、OPPO等大厂18年进入阿里一直到现在。
深知大多数前端工程师想要提升技能往往是自己摸索成长或者是报班学习但对于培训机构动则几千的学费着实压力不小。自己不成体系的自学效果低效又漫长而且极易碰到天花板技术停滞不前
因此收集整理了一份《2024年Web前端开发全套学习资料》初衷也很简单就是希望能够帮助到想自学提升又不知道该从何学起的朋友同时减轻大家的负担。 既有适合小白学习的零基础资料也有适合3年以上经验的小伙伴深入学习提升的进阶课程基本涵盖了95%以上前端开发知识点真正体系化 由于文件比较大这里只是将部分目录截图出来每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频并且会持续更新
如果你觉得这些内容对你有帮助可以扫码获取备注前端 最后
分享一套阿里大牛整理的前端资料给大家点击前端校招面试题精编解析大全即可获取
❤️ 谢谢支持喜欢的话别忘了 关注、点赞哦。
ue)Aliases: gte | expect(10).to.be.at.least(10) |
| lessThan(value) Aliases: lt, below | expect(5).to.be.lessThan(10) |
| most(value) Aliases: lte | expect(‘test’).to.have.length.of.at.most(4) |
| within(start, finish) | expect(7).to.be.within(5,10) | 自我介绍一下小编13年上海交大毕业曾经在小公司待过也去过华为、OPPO等大厂18年进入阿里一直到现在。
深知大多数前端工程师想要提升技能往往是自己摸索成长或者是报班学习但对于培训机构动则几千的学费着实压力不小。自己不成体系的自学效果低效又漫长而且极易碰到天花板技术停滞不前
因此收集整理了一份《2024年Web前端开发全套学习资料》初衷也很简单就是希望能够帮助到想自学提升又不知道该从何学起的朋友同时减轻大家的负担。
[外链图片转存中…(img-r7SHQx7c-1712650618655)]
[外链图片转存中…(img-17Ts6DJg-1712650618655)]
既有适合小白学习的零基础资料也有适合3年以上经验的小伙伴深入学习提升的进阶课程基本涵盖了95%以上前端开发知识点真正体系化
[外链图片转存中…(img-Y9WzD3Tm-1712650618655)]
由于文件比较大这里只是将部分目录截图出来每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频并且会持续更新
如果你觉得这些内容对你有帮助可以扫码获取备注前端 最后
分享一套阿里大牛整理的前端资料给大家点击前端校招面试题精编解析大全即可获取
❤️ 谢谢支持喜欢的话别忘了 关注、点赞哦。