【问题标题】:Problem on cypress test with drag and drop on fullcalendar在全日历上拖放柏树测试的问题
【发布时间】:2020-04-12 17:07:22
【问题描述】:

我想测试使用 Cypress 拖放一个完整的日历事件(更改任务的日期),测试通过但该事件没有被删除:

这是测试实现:

Then('I move a task to another date', () => {
    cy.get('.fc-event')
        .trigger('mousedown', { which: 1, pageX: 188, pageY: 196 })
        .trigger('mousemove', { which: 1, pageX: 188, pageY: 261 })
        .trigger('mouseup')
})

我用这个插件https://www.npmjs.com/package/@4tw/cypress-drag-drop 对其进行了测试,但结果相同,事件没有移动:

Then('I move a task to another date', () => {
     cy.get('.fc-event').drag(':nth-child(3) > .fc-bg > table > tbody > tr > .fc-thu', { force: true })
})

编辑

我成功地用这个实现做到了:

Then('I move a task to another date', () => {
    cy.get('.fc-day-grid-event')
        .trigger('mousedown', { which: 1, button: 0 })
        .trigger('mousemove', {
            pageX: 775,
            pageY: 1250,
        })
        .trigger('mouseup', { force: true })
})

错误是没有使用button: 0,也没有给出好的坐标值。

【问题讨论】:

    标签: testing fullcalendar cypress


    【解决方案1】:

    我的应用遇到了类似的问题,非常感谢,因为您的解决方案让我很开心。 我在 mouseup 上出现了最后一个错误,因为 cypress 无法定位我的元素,但我找到了解决方法。这是我的命令:

    Cypress.Commands.add('moveTo', {prevSubject: true}, (subject, options) => {
        const offsetTop = subject[0].getBoundingClientRect().y
        const offsetLeft = subject[0].getBoundingClientRect().x
        cy.get(subject)
            .trigger('mousedown', {which: 1, button: 0})
            .trigger('mousemove', {
                pageX: offsetLeft + options.x,
                pageY: offsetTop + options.y
            })
        cy.get('body').trigger('mouseup', {
        pageX: offsetLeft + options.x,
        pageY: offsetTop + options.y
      })
    })
    

    【讨论】:

      猜你喜欢
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多