简体   繁体   English

如何在AngularJS e2e测试中测试拖放功能

[英]How to test drag & drop functionality in AngularJS e2e testing

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? 我该如何测试?

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 对我来说,解决方案是遵循Selenium问题中的建议: https//code.google.com/p/selenium/issues/detail? id = 3604#c20

Starting with the example from @nilsK, here was my solution: 从@nilsK的示例开始,这是我的解决方案:

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 我认为这也解决了这个问题

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();

You can use ptor.actions().dragAndDrop(el1, el2).perform(); 你可以使用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
        });
    });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM