Testing jQuery Drag & Drop and Droppable with Sele

2019-02-10 15:54发布

问题:

I have a page that makes use of jQuery Drag & Drop, and I would like to build a relatively robust test suite for this process using Selenium.

Looking into Selenium, I've found that it has a Drag & Drop command on a jQuery plugin like: FullCalendar, but when I use the Selenium IDE to try to record 'dragging and dropping I don't get any recorded events.

So should I try to target the events using jQuery selectors?

Because the following don't work (targeting the '12p Lunch' on the example page)

<tr>
    <td>dragAndDrop</td>
    <td>/html/body/div[2]/div/div/div[2]/div/div/div/div/div[8]/div</td>
    <td>+100,+100</td>
</tr>

or even clicking on the element

<tr>
    <td>click</td>
    <td>/html/body/div[2]/div/div/div[2]/div/div/div/div/div[8]/div</td>
    <td>+100,+100</td>
</tr>

In both cases the XPath isn't found. So how can I target this changing element? If I had a unique id in the selector could I target that? Either way the drag&drop doesn't seem to be working:

<tr>
    <td>dragAndDrop</td>
    <td>id=targetelement</td>
    <td>+100,+100</td>
</tr>

Also can I target elements in the 'Location' with jQuery?

<tr>
    <td>dragAndDrop</td>
    <td>selenium.getuserwindow.browserbot.jQuery('#targetelement')</td>
    <td>+100,0</td>
</tr>

回答1:

This works for me...

<!--test sorting-->
<!--move block 2 to col 1-->
<tr>
    <td>mouseDownAt</td>
    <td>//div[@id="block-set-col-1"]/ul/li</td>
    <td>80,20</td>
</tr>
<tr>
    <td>mouseMoveAt</td>
    <td>//div[@id="block-set-col-0"]/ul</td>
    <td>50,10</td>
</tr>
<tr>
    <td>mouseOver</td>
    <td>//div[@id="block-set-col-0"]/ul</td>
    <td>50,10</td>
</tr>
<tr>
    <td>pause</td>
    <td>2000</td>
    <td></td>
</tr>
<tr>
    <td>mouseUpAt</td>
    <td>//div[@id="block-set-col-0"]/ul</td>
    <td>50,10</td>
</tr>