我创建了小提琴供参考:http://jsbin.com/xowawisewo/edit?js,output
<div class="parent">
<div class="list-group">
<div>Stage - 1</div>
<div class="child">
<div class="card">A</div>
<div class="card">B</div>
<div class="card">C</div>
</div>
</div>
<div class="list-group">
<div>Stage - 2</div>
<div class="child">
<div class="card">D</div>
<div class="card">E</div>
<div class="card">F</div>
</div>
</div>
<div class="list-group">
<div>Stage - 3</div>
<div class="child">
<div class="card">G</div>
<div class="card">H</div>
<div class="card">I</div>
</div>
</div>
</div>
在这里,我具有STAGE-> CARDS之类的结构,并且由于我使用了 RubaXa Sortable 库(https://github.com/RubaXa/Sortable),它们都可以拖放。
现在,我在这里编写一个自动测试用例,以测试舞台的拖放。为了测试我是否正在以编程方式拖放舞台。 为此,我正在编写类似以下的代码:-
function triggerPositionalMouseEvent(x, y, type){
var ev = document.createEvent("MouseEvent");
var el = document.elementFromPoint(x,y);
ev.initMouseEvent(
type,
true /* bubble */,
true /* cancelable */,
window, null,
x, y, x, y, /* coordinates */
false, false, false, false, /* modifier keys */
0 /*left button*/, null
);
el.dispatchEvent(ev);
return el;
}
triggerPositionalMouseEvent(document.getElementsByClassName('card')[0].offsetLeft + 10, document.getElementsByClassName('card')[0].offsetTop + 10, 'mousedown');
triggerPositionalMouseEvent(document.getElementsByClassName('list-group')[2].offsetLeft + document.getElementsByClassName('list-group')[2].clientWidth / 3 , document.getElementsByClassName('list-group')[2].offsetTop + 20, 'mousemove');
setTimeout(function() {
triggerPositionalMouseEvent(document.getElementsByClassName('list-group')[2].offsetLeft + 30, document.getElementsByClassName('list-group')[2].offsetTop + 30, 'mouseup');
}, 50);
如您所见,我先触发mousedown然后mousemove,并且延迟50ms后我触发mouseup,这里 50ms延迟对我来说很困难不想写50ms的延迟并且没有那个测试用例就无法正常工作。有人可以帮我吗?