AngularJS 和 Protractor 非常新,但我认为到目前为止我的方向是正确的。
当您单击并按住该项目 X 秒时,我的网站有一个项目列表,它会打开一个模式窗口。
如何在 Protractor/Jasmine 中模拟这种行为?
我知道有“click()”事件,但我想要“点击并按住”事件
我相信有人知道如何模拟它。
提前非常感谢!
AngularJS 和 Protractor 非常新,但我认为到目前为止我的方向是正确的。
当您单击并按住该项目 X 秒时,我的网站有一个项目列表,它会打开一个模式窗口。
如何在 Protractor/Jasmine 中模拟这种行为?
我知道有“click()”事件,但我想要“点击并按住”事件
我相信有人知道如何模拟它。
提前非常感谢!
这个想法是首先使用mouseDown()
:
/**
* Presses a mouse button. The mouse button will not be released until
* {@link #mouseUp} is called, regardless of whether that call is made in this
* sequence or another. The behavior for out-of-order events (e.g. mouseDown,
* click) is undefined.
...
*/
然后,呼叫browser.sleep()
X 秒。
然后,调用mouseUp()
释放鼠标点击:
/**
* Releases a mouse button. Behavior is undefined for calling this function
* without a previous call to {@link #mouseDown}.
...
*/
代码:
browser.actions().mouseDown(element).perform();
browser.sleep(5000);
browser.actions().mouseUp(element).perform();
其中element
是 的目标元素click-and-hold
。
工作示例(基于此 jsfiddle):
require('jasmine-expect');
describe('Test Click And Hold', function () {
beforeEach(function () {
browser.ignoreSynchronization = true;
browser.get('http://jsfiddle.net/LysCF/13/embedded/result/');
browser.sleep(5000);
});
it('should show appropriate list elements after click and hold', function () {
var frame = browser.findElement(by.xpath('//div[@id="result"]/iframe'));
browser.switchTo().frame(frame);
var element = browser.findElement(by.css('div.hold_trigger'));
browser.actions().mouseDown(element).perform();
browser.sleep(5000);
browser.actions().mouseUp().perform();
// check expectations
});
});