cypress.io - 在所有页面上运行测试,遍历寻呼机

问题描述 投票:0回答:1

我想在多个页面上运行相同的测试。它是一个分为多个页面的长形式。页数会有所不同。有时它是7,有时是30.看截图:https://drive.google.com/file/d/1O_xhayyIaRJTqABDR27E4XubrmBTR2IW/view填充所有页面后,网址会发生变化。

如何使用cypress.io遍历所有页面?在jQuery / javascript中它会是这样的。

$(document).ready(function($) {
             if(window.location.href.indexOf("xyz") > -1) {
             fillInForm();
             clickOnNext();
}
});

在cypress.io中,我试过但它只运行一次。

cy.location().its('href').then((val) => {
    if (val.indexOf('xyz')  !== -1) {
        // cypress test, fill in form...
        cy.contains('Next').eq(0).click()  
    }
  })

有任何想法吗?谢谢。

javascript automated-tests mocha cypress
1个回答
0
投票

我正在使用cypress 3.1.1,这是我在我的应用程序中测试分页的方式,该分页提供了不同页数的搜索结果。

it('Pages proper', function() {

    // Perform search
    cy.get('[data-testid=search-icon]').click();
    cy.get('[data-testid=explorer-search-input]').type('the');
    cy.get('[data-testid=explorer-search-input]').type('{enter}');
    cy.contains('Displaying 1 - 10 of 21 results');
    cy.contains('Page 1 of 3');

    // Test Next Page
    cy.get('[data-testid=explorer-page-btns-next]').click();
    cy.contains('Displaying 11 - 20 of 21 results');
    cy.contains('Page 2 of 3');
    cy.get('[data-testid=explorer-page-btns-next]').click();
    cy.contains('Displaying 21 - 21 of 21 results');
    cy.contains('Page 3 of 3');

    // Test Previous Page
    cy.get('[data-testid=explorer-page-btns-previous]').click();
    cy.contains('Displaying 11 - 20 of 21 results');
    cy.contains('Page 2 of 3');

    // Preform new search to vary results/pages returned
    cy.get('[data-testid=search-icon]').click();
    cy.get('[data-testid=explorer-search-input]').type('Rabbit Hole');
    cy.get('[data-testid=explorer-search-input]').type('{enter}');        

    ...

})

您还可以为结果中的任何已知项添加cy.contains('xyz');,以验证除分页功能外还显示的数据。

© www.soinside.com 2019 - 2024. All rights reserved.