1

CasperJS でマウスのドリフトをシミュレートしたい。それを達成するには、setInterval を使用したいと考えています。間隔は、 require() を使用して取得するだけで、別のファイルで定義されます。実行できますが、Casper はインターバルが終了するのを待ちません。間隔は約 200 ミリ秒で、Casper はコードの実行を続けます。Drift() が終了すると、「終了」コールバックが呼び出されます。

Finish() が実行されるまで待つように CasperJS に指示するにはどうすればよいですか?

casper.waitFor(function () {
  var result = drift({
    ...
    finished: function (x,y) {
      //casper.test.comment('up ' + x + ' ' + y);
      that.mouse.up(x, y);
    }
  }, window);

  return result;
}, function () { /** test here... **/ });

function drift (options, window) {
  interval = setInterval(function () {
    if (counter <= limit) {
      x += stepX;
      y += stepY;
      //call the way callback    
      options.way(x, y);
      counter += 1;
    } else {  
      options.finished(x, y);
      ...
      window.clearInterval(interval);
      returnVal = true;
    }
  }, 50);
  return returnVal;
}

完全なコードはこちら: https://github.com/schickling/Overscroll/blob/testing/test/drift.js そしてこちら: https://github.com/schickling/Overscroll/blob/testing/test/modules/ドリフト-move.js

4

0 に答える 0