如何实现 Android 自带浏览器模拟百度搜索?
本人今天刚接触Appium,遇到个问题想请大侠们指点迷津。目的:用Android自带的浏览器模拟百度搜索。
问题:如何指定Android浏览器?
public class Test{
private WebDriver driver;
@Before
public void setUp() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","selendroid");
//------------------------------------下面的不知如何写--------------------------------------------------------------//
//capabilities.setCapability("app", "/system/app/Browser.apk");
//capabilities.setCapability("app", app.getAbsolutePath());
//capabilities.setCapability("app-package", "com.android.browser");
//capabilities.setCapability("app-activity", ".FMSActivity");
//----------------------------------------------------------------------------------------------------------------------------//
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.baidu.com");
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("wd")));
WebElement keyword = driver.findElement(By.name("wd"));
keyword.sendKeys("appium");
driver.findElement(By.id("su1")).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;
}
}
}
直接设置搜索网址 有什么直接疑问或困难 用默认的 找到原生浏览器的包名,启动原生浏览器,然后百度搜索
页:
[1]