selenium-webdriverrobotframeworkdragselenium2library

RobotFramework: Drag And Drop Selenium2 Keyword seems not to work


I'm testing web app (using RobotFramework with Selenium2Library) in which some drag and drop actions is needed at couple of points. I tried Drag And Drop keyword, but it's not working properly.

Since I can't pass the production app, I recreated problem using this page below: https://html5demos.com/drag/

My code is:

*** Settings ***
Library  Selenium2Library

*** Variables ***
${URL} =  https://html5demos.com/drag/

*** Test Cases ***

Prepare Browser
    Open_Browser  ${url}  browser=chrome
    Maximize Browser Window

Make Test
    #Drag And Drop  //*[@id="one"]  //*[@id="bin"]
    #Drag And Drop  //*[@id="two"]  //*[@id="bin"]
    Capture Page Screenshot
    Sleep  1

Close All
    Close Browser

Have tried it using both Python 2.7 and 3.6.

Output I get is test shown as PASS, but I can't see any real results of drag and drop action (both in my production app and sample page linked above). Screenshot of drag and drop test results

When I look into what happens in the browser during test I notice, that the object became draggable (quote "drag me" is added in brackets) but test stood for a log time. When mouse cursor is moved, test goes on int PASS mentioned above, but without real effect.

Tried on newest Chrome, Firefox, IE. Also tried with keywords Mouse Down, Mouse Over, Mouse Up, but with the same results.

Here is screenshot of log from execution report: Execution report screenshot

I would appreciate any help or workaround to have it done correctly.


Solution

  • I tried the above answer and they weren't applicable to my use case and neither was the inbuilt function of selenium. Instead i implemented my own drag and drop keyword that is reusable. This works even for scenarios where in the angular js/ react js elements for example don't have an attribute called draggable set.

    Drag And Drop
        [Arguments]     ${src}     ${intermediate}      ${tgt}
        Wait Until Keyword Succeeds      ${ATTEMPTS}     ${LARGER_TIMEOUT}      Mouse Down   ${src}
        Wait Until Keyword Succeeds      ${ATTEMPTS}     ${LARGER_TIMEOUT}      Mouse Over   ${intermediate}
        Wait Until Keyword Succeeds      ${ATTEMPTS}     ${LARGER_TIMEOUT}      Mouse Over   ${tgt}
        Wait Until Keyword Succeeds      ${ATTEMPTS}     ${LARGER_TIMEOUT}      Mouse Up     ${tgt}
    

    The use of Wait until keyword succeeds helps with guaranteeing to a good extent that the process wont fail. You can find its documentation here. What the drag and drop does is literally press the mouse down move location and release it. I have additionally used an intermediate location to handle cases where it may fail but its not necessary.

    To call the function simply use something like this -

    Drag And Drop   ${XPATH1}  ${XPATH2}  ${XPATH3}