iOS iPad または Android タブレット用の Java コードを使用して、Selenium WebDriver でタッチ/タップ イベントを使用したいと考えていました。
これどうやってするの?
はい、Android デバイスで Web アプリケーション / Web サイトをテストするために使用できる AndroidDriver があります。
リンク:
iOS 用のAndroid WebDriver 、iPhone 用の WebDriver があります
リンク: iPhone WebDriver
また、これを確認してください:
モバイル ブラウザー用の WebDriverドライバーは、すぐに使用できる Web ビュー/ページの自動テスト用です。ネイティブ アプリ自動化フレームワークなどのタップ イベント。jQuery Mobile API を使用して、Web ページでタッチ/タップ イベントを実行するようにしてください。Selenium Webdriver のJavascriptExecutorを使用し、executor を使用して jquery を実行します。
これを確認してください:jQuery Mobile Tap
Android の場合、TouchEvents が利用可能です。
これは、Google 検索結果ページでサンフランシスコの天気のスライダーを動かすコード スニペットです。Google が決定した検索クエリと同じ結果が得られるとは保証できません :) とはいえ、この例で十分に理解できることを願っています。
この例では Junit 4 テスト ランナーを使用していますが、コードを微調整して Junit 3 やその他のテスト ランナーなどで実行することができます。
package org.example.androidtests;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class AndroidDemoTest {
@Test
public void test() throws InterruptedException {
AndroidDriver driver = new AndroidDriver();
Wait<WebDriver> wait = new WebDriverWait(driver, 20);
driver.get("http://www.google.co.uk");
WebElement q = driver.findElement(By.name("q"));
q.sendKeys("weather in san francisco");
q.submit();
WebElement slider = wait.until(visibilityOfElementLocated(By.className("wob_shi")));
Point location = slider.getLocation();
Dimension size = slider.getSize();
// Find the center of this element where we we start the 'touch'
int x = location.getX() + (size.getWidth() / 2);
int y = location.getY() + (size.getHeight() / 2);
new TouchActions(driver).down(x, y).move(150, 0).perform();
}
}
注: iOS と Android の両方のプラットフォームで動作するテストが必要な場合は、質問に対する別の回答で提案されているように、おそらく JQuery Mobile を使用する別のアプローチが必要になります。次の記事では、JQuery を使用して iOS のタッチ イベントをシミュレートする方法についても説明していますhttp://seleniumgrid.wordpress.com/2012/06/01/how-to-simulate-touch-actions-using-webdriver-in-iphone-or -iPad/