cypress问题笔记


遇到的一些问题

each方法支持遍历元素

each(($el, index, $list) => { ... }, $el文档说是jquery元素, 但是直接用jquery方法不行( 比如click)

解决方法: 用cy.wrap传入元素

cy.get('@item').each(($el, index, $list) => {       
    cy.wrap($el).click().find('li:first').click();
});

等价于

cy.get('@item').eq(0).click().find('li:first').click();    cy.get('@item').eq(1).click().find('li:first').click();    cy.get('@item').eq(2).click().find('li:first').click();



使用promise.all

不支持原生的promise.all,需要用Cypress.Promise.all
讨论:https://github.com/cypress-io/cypress/issues/915

new Cypress.Promise.all([ promise1, promise2 ]).then( ()=>{ ... } )



循环测试

直接for循环就行...



添加自定义指令

案例是官网的

Cypress.Commands.add('login', (email, pass) => {
    cy.visit('http://localhost:4200/login',{timeout:500} ); //延迟500毫秒访问
    cy.get('input[name=email2]').type(email);
    cy.get('input[name=password2]').type(pass);
    cy.get('button[type=submit]').click();
})
it('can do logged-in user stuff', () => {
    cy.login('hello@angularfirebase.com', 'password123')
    // test stuff here
});

=-= markdown编辑器会吞换行 用html标签才能强制换行 有毒


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM