How to test drag & drop functionality in AngularJS e2e testing

倖福魔咒の 提交于 2019-11-29 19:05:04

问题


I am trying to test my application where I need to move a widget from one location to other, in other word I need to test drag & drop functionality in an end to end test.

How would I test this?


回答1:


I had this same issue. The solution for me was to follow the advice in the Selenium issue here: https://code.google.com/p/selenium/issues/detail?id=3604#c20

Starting with the example from @nilsK, here was my solution:

var yourOffset = {x:5,y:5};
ptor().actions()
    .mouseMove(yourElement,yourOffset)
    .mouseDown()
    .mouseMove(yourElement,{x:0,y:0}) // Initial move to trigger drag start
    .mouseMove(youTarget[,targetOffset]) // [] optional
    .mouseUp()
    .perform();

I think this also solves this issue




回答2:


you will need to chain your mouse actions:

var yourOffset = {x:5,y:5};
ptor().actions().
   mouseMove(yourElement,yourOffset).
   mouseDown().
   mouseMove(youTarget[,targetOffset]). // [] optional
   mouseUp().
   perform();



回答3:


You can use ptor.actions().dragAndDrop(el1, el2).perform();

I have an example here from the test suite in my own application:

/**
 * Reorders questions by dragging and dropping.
 */
this.moveQuestion = function (questionToMove, positionToMoveTo) {
    return page.getQuestionField(positionToMoveTo).then(function (dest) {
        page.getDragHandle(questionToMove).then(function (dragHandle) {
            ptor.actions().dragAndDrop(dragHandle, dest).perform();
            ptor.sleep(800);    // wait for animation
        });
    });
};


来源:https://stackoverflow.com/questions/22984267/how-to-test-drag-drop-functionality-in-angularjs-e2e-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!