• 如何实现 Android 自带浏览器模拟百度搜索?
  • 移动测试
    2.00元
本人今天刚接触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;
        }
    }

}
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信