0

我想在多个页面上运行相同的测试。它是一个长表格,分为多个页面。页数不同。有时是 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()  
    }
  })

有任何想法吗?谢谢你。

4

1 回答 1

1

我正在使用 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');除了分页功能之外,您还可以在结果中添加任何已知项目以验证正在显示的数据。

于 2018-11-20T04:20:07.807 回答