2017-12-12 21 views
0

私は実際のデバイスでAppium 1.7とAndroid 8を使用しています。しかし、私はスワイプで立ち往生しています。さまざまな組み合わせで試してみました。スワイプ機能のための簡単なコードを提供してください。appiumのためにアンドロイドで垂直スワイプを実行する方法

が試み:

private void scrollDown() { 
    //if pressX was zero it didn't work for me 
    int pressX = driver.manage().window().getSize().width/2; 
    // 4/5 of the screen as the bottom finger-press point 
    int bottomY = driver.manage().window().getSize().height * 4/5; 
    // just non zero point, as it didn't scroll to zero normally 
    int topY = driver.manage().window().getSize().height/8; 
    //scroll with TouchAction by itself 
    scroll(pressX, bottomY, pressX, topY); 
} 

/* 
* don't forget that it's "natural scroll" where 
* fromY is the point where you press the and toY where you release it 
*/ 
private void scroll(int fromX, int fromY, int toX, int toY) { 
    TouchAction touchAction = new TouchAction(driver); 
    touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform(); 
} 

しかし運..!

答えて

0

============================================== ========================

使用されるJavaクライアントバージョン5.0.4および垂直方向のスワイプのコードの下に使用。

Dimension size = this.driver.manage() 
    .window() 
    .getSize(); 
int startX = size.getWidth()/2; 
int startY = size.getHeight()/2; 
int endX = 0; 
int endY = (int) (startY * -1 * 0.75); 
TouchAction action = new TouchAction (this.driver); 
action.press (startX, startY) 
    .moveTo (endX, endY) 
    .release() 
    .perform(); 

=========================================== =

Wasiq Bhamlaさんに感謝します。

0
private void scroll(int fromX, int fromY, int toX, int toY) { 
    TouchAction touchAction = new TouchAction(driver); 
    touchAction.tap(fromX, fromY).waitAction(1000).moveTo(toX, 
    toY).release().perform(); 
} 

あなたは押さなければなりません。 これは あなたは、スクロール/以下のコードでアクションをスワイプ実行できる点aから点b

+0

ここで直接座標値を渡す必要がありますか? int fromX、int fromY、int toX、int toY –

0

に任意の方向にスワイプするためにこれを使用することができます動作します:

Dimension size = this.driver.manage() 
    .window() 
    .getSize(); 
int startX = size.getWidth()/2; 
int startY = size.getHeight()/2; 
int endX = 0; 
int endY = (int) (startY * -1 * 0.75); 
TouchAction action = new TouchAction (this.driver); 
action.press (startX, startY) 
    .moveTo (endX, endY) 
    .release() 
    .perform(); 

あなたは左を実行するコードを微調整することができます、下と右のスワイプ。これがあなたのために働くかどうか私に教えてください。

+0

これは負の値を返します。 "int endY =(int)(startY * -1 * 0.75);"したがって、使用できない例外スローをコーディネートします。 –

+0

5.0またはそれ以上のJavaクライアントを使用している場合、私のフレームワークでこれを使用していて、これと同じコードが正常に機能するため、これは正常に動作します。基本的に-ve endYは、画面の中央から画面の上端に移動するようにAppiumを指定します。 –

+0

ImはJava 1.8を使用しており、-veの値を示しています。 –

0

これは私に解決できます:

TouchActionアクション=新しいTouchAction(ドライバ)。 action.longPress(bottomElement).moveTo(topElement).release()。perform();

関連する問題