testing - 在fullcalendar上拖放cypress测试的问题

标签 testing fullcalendar cypress

我想测试使用 Cypress 拖放完整的日历事件(更改任务的日期),测试通过但未删除事件:
enter image description here
enter image description here
这是测试实现:

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并且也没有给出好的坐标值。

最佳答案

我的应用程序遇到了类似的问题,非常感谢,因为您的解决方案让我开心。
我在使用 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
  })
})

关于testing - 在fullcalendar上拖放cypress测试的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61175154/

相关文章:

visual-studio - 防止 Visual Studio Web 测试更改请求详细信息

python - 使用 py.test 的项目

php - Laravel - MySQL 数据库测试

testing - Kotlin 测试 DSL 中的限制

javascript - 将 z-index 添加到 FullCalendar 中的周行

javascript - 显示 06 :00 instead of 6am in FullCalendar

javascript - FullCalendar 按钮放置月份名称应位于左右箭头之间

柏树 下载 : "cypress run" appears to be the same as "cypress open"

cypress - 使用Cypress,如何获取非请求事件触发的api调用的响应体

node.js - 创建项目后 Gatsby 开发不工作