【问题标题】:Cypress is not closing menu when I click on a button from menu当我单击菜单中的按钮时,赛普拉斯没有关闭菜单
【发布时间】:2020-11-01 15:51:12
【问题描述】:

这里我正在使用 cypress 测试一个 Vue 应用程序。我的应用程序屏幕上有一个菜单。通常,当我单击菜单上的按钮时,它会关闭菜单并执行功能。但是当我使用 cypress 执行此操作时,它会执行功能但无法关闭菜单。 这是我的示例代码。

it('Open menu, Click on sort button(A -> Z): Check ascending order of data', function () {
    cy.server();
    cy.route("GET", getTableListAPI).as('getTableList');
    cy.route("GET", getFirstPageTableData).as("getTableDetails");
    //Asc sort Api
    cy.route("GET", ascendingSortApi).as("getAscData");
    cy.visit(testTargetURL);
    //Wait to load data
    cy.wait('@getTableList');
    //Select the target tablefrom the left pane
    cy.get(selectors.navigationDrawer).find('a').contains(testTableWithData).click();
    //Wait to load data
    cy.wait('@getTableDetails');

    //Open menu
    cy.get('th').eq(1).find('button').click();
    //Click on first button.
    cy.get(selectors.filterMenu).within(($menu) => {
        cy.get('.v-item-group').find('button').eq(0).click();
    })
    //Wait to load data
    cy.wait('@getAscData');

    //Check visibility
    cy.get(selectors.filterMenu).should('not.be.visible');
    //Check ascending order data
    cy.get('table').within(($table) => {
        cy.get('tr').find('td').should('contain','');
        cy.get('tr').find('td').should('contain','-9223372036854776000');
    })
 })

注意:我也试过了

  1. 点击({ force: true });
  2. cy.wait(500) // 关注 (https://github.com/cypress-io/cypress/issues/3135#issuecomment-454420548) 这个问题。

但是,它仍然不适合我。请为我提出其他建议。 提前致谢。

【问题讨论】:

    标签: javascript unit-testing vuetify.js cypress


    【解决方案1】:

    在我看来,问题在于您正在使用 {force:true} 并且不会触发关闭菜单的功能。尝试选择菜单原生的按钮的一些父元素并单击它。

    【讨论】:

    • 你的观点是关于 cy.get() 函数吗?另外我想告诉你我已经尝试过cy.get(selectors.filterMenu).within(($menu) => { cy.get('.col').contains('A').click(); //Also with { force: true } }) 还有.. cy.get('.v-list').find('.col').find('button').eq(0).click(); cy.get('.v-list').find('.col').contains('A').click();
    • 您好抱歉不清楚。这是我第一次尝试在 StackOverflow 中给出答案,我m used to answering in facebook groups. I meant that you should check which component has the on click event and - the code of that event - when and how it is applied. If you think my anwser was inappropriate Ill 删除它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 2022-11-03
    • 2022-10-31
    • 1970-01-01
    • 2020-06-24
    相关资源
    最近更新 更多