2

AngularJS と分度器では非常に新しいですが、これまでのところ正しい方向に進んでいると思います。

私のサイトには、項目をクリックして X 秒間押し続けると項目のリストがあり、モーダル ウィンドウが開きます。

分度器/ジャスミンでその動作をシミュレートするにはどうすればよいですか?

「click()」イベントがあることは知っていますが、「クリック アンド ホールド」イベントが必要です

それをシミュレートする方法を知っている人がいると確信しています。

よろしくお願いします!

4

1 に答える 1

4

アイデアは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();

whereelementは のターゲット要素です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
    });
});
于 2014-12-05T02:17:50.517 に答える