summer506hai / auto_test

自动化测试:UI自动化测试(Android 、pc(Windows+h5)混合);技术调研;技术难点解决方案
0 stars 0 forks source link

web/h5 UI自动化-JavaScript脚本-存档 #5

Open summer506hai opened 1 year ago

summer506hai commented 1 year ago

滑动

从(x , y)移动到 (x + move_x , y)

var el = document.elementFromPoint({x}, {y});
var ev = new MouseEvent('mousedown', {{
                        'view': window,
                        'bubbles': true,
                        'cancelable': true,
                        'screenX': {x},
                        'screenY': {y},
                        'clientX': {x},
                        'clientY': {y} 
                        }});
el.dispatchEvent(ev);
var ev1 = new MouseEvent('mousemove', {{
                        'view': window,
                        'bubbles': true,
                        'cancelable': true,
                        'screenX': {x} + {move_x},
                        'screenY': {y},
                        'clientX': {x}+ {move_x},
                        'clientY': {y}
                           }});
el.dispatchEvent(ev1);
var ev2 = new MouseEvent('mouseup', {{
                        'view': window,
                        'bubbles': true,
                        'cancelable': true,
                        'screenX': {x} + {move_x},
                        'screenY': {y},
                        'clientX': {x}+ {move_x},
                        'clientY': {y}
                        }});
el.dispatchEvent(ev2);
summer506hai commented 1 year ago

用MouseEvent来模拟鼠标右键 contextmenu事件

var ev = new MouseEvent('contextmenu', {{
                        'view': window,
                        'bubbles': true,
                        'cancelable': true,
                        'screenX': '{x}',
                        'screenY': '{y}'  }});
var el = document.elementFromPoint('{x}','{y}');
el.dispatchEvent(ev);