拖放柏树

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

我正在尝试使用拖放库,但它不起作用。 库:https://github.com/4teamwork/cypress-drag-drop

我需要执行测试来订购此站点中的任务: https://tarefas-fc129.web.app/home

我尝试使用 cy.wrap() 因为元素没有 ID

  it('reordenar itens' , () => {
    
    cy.get('input')
      .should('have.attr', 'placeholder', 'Ex. Tomar vacina')
      .type('Item A');
    cy.get('.button')
      .eq(0)
      .click();
    
    cy.contains('Item A')
      .should('be.visible');
    
    cy.get('input')
      .should('have.attr', 'placeholder', 'Ex. Tomar vacina')
      .type('Item B');
    cy.get('.button')
      .eq(0)
      .click();
    
    cy.contains('Item B').should('be.visible');

    cy.get('.button')
      .eq(1)
      .click();
    
    let posicaoItemA
    
    cy.contains('Item A')
      .parent('ion-item')
      .find('ion-buttons')
      .then( (ItemA) => {
        posicaoItemA = ItemA;
      });

    let posicaoItemB
    
    cy.contains('Item B')
      .parent('ion-item')
      .find('ion-buttons')
      .then( (ItemB) => {
        posicaoItemB = ItemB;
      });

    cy.wrap(posicaoItemA).drag(cy.wrap(posicaoItemB));
    
  })

我收到此错误,甚至使用 cy.wrap() 传递元素

erro image

重新排序任务,将顺序从“项目 A”更改为“项目 B”

cypress drag drop
1个回答
0
投票

啊,Cypress 和拖放,总是一个有趣的组合,对吧? 😄

首先,我看不到您提到的错误图像,但我仍然可以尝试帮助您。

cy.wrap()
方法通常用于包装原生 JavaScript 对象并将其生成为 Cypress 主题。但是,它可能不是最适合您的拖放场景。

您可以尝试以下几件事:

  1. 使用
    dragTo
    而不是拖动:
    您正在使用的库,
    cypress-drag-drop
    ,有一个
    dragTo
    方法。你可以这样使用它:
cy.get('your-source-selector').dragTo('your-target-selector');
  1. 确保正确导入库: 仔细检查是否已在测试文件顶部导入
    cypress-drag-drop
    库:
import 'cypress-drag-drop';
  1. 检查元素:有时问题出在您尝试拖放的元素上。确保它们在 DOM 中实际上是可拖动和可放置的。

  2. 调试: 使用

    .debug()
    暂停执行并检查状态。

cy.get('your-selector').debug();

如果您仍然遇到困难,请告诉我。我可以深入研究该库的 GitHub 存储库,看看是否有任何具体您需要做的事情。

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