【发布时间】:2014-03-25 12:52:58
【问题描述】:
我想在安卓手机上使用appium自动化浏览器,但不知道如何设置功能。
首先,我在我的 Android 设备上的开发者选项中启用了 USB 调试。
其次,adb 运行良好,我可以看到设备 id。
第三,我从Appium for windows启动Appium.exe,用JAVA写了一些代码,但是不知道如何在Android浏览器上设置能力。
public class Test {
private WebDriver driver;
@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
//------------I don't know how to set the capability------------//
capabilities.setCapability(CapabilityType.VERSION, "2.3.7");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
//--------------------------------------------------------------//
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testcase_001() throws Exception{
driver.get("http://www.google.com");
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("lst-ib")));
WebElement keyword = driver.findElement(By.name("lst-ib"));
keyword.sendKeys("appium");
driver.findElement(By.id("btnK")).click();
Thread.sleep(5000);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
private RemoteTouchScreen touch;
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
touch = new RemoteTouchScreen(getExecuteMethod());
}
public TouchScreen getTouch() {
return touch;
}
}
}
非常感谢。
【问题讨论】: