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