启动 虚拟设备参考:Appium笔记
下载 ContactManager.apk
https://raw.githubusercontent.com/appium/sample-code/master/sample-code/apps/ContactManager/ContactManager.apk
安装ContactManager.apk
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb install D:\xxx\ContactManager.apk
Java代码:
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.List;
-
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.remote.CapabilityType;
- import org.openqa.selenium.remote.DesiredCapabilities;
-
- import io.appium.java_client.MobileElement;
- import io.appium.java_client.android.AndroidDriver;
-
- public class ContactManagerAppTest {
-
- public static void main(String[] args) throws MalformedURLException {
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
- capabilities.setCapability("platformName", "Android");
- capabilities.setCapability("deviceName", "Android Emulator");
- capabilities.setCapability("platformVersion", "5.1.1");
- capabilities.setCapability("appPackage", "com.example.android.contactmanager");
- capabilities.setCapability("appActivity", ".ContactManager");
-
- AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
-
-
- WebElement el = driver.findElementByAndroidUIAutomator("text(\"Add Contact\")");
- el.click();
- List<MobileElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
- textFieldsList.get(0).sendKeys("Some Name");
- textFieldsList.get(2).sendKeys("Some@example.com");
- driver.swipe(100, 500, 100, 100, 2);
- driver.findElementByAndroidUIAutomator("text(\"Save\")").click();
-
- driver.quit();
-
- }
-
- }
一些adb命令
传文件到设备:adb push D:\xxx\ContactManager.apk /data
启动shell: adb shell
adb remount
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10742815/viewspace-2138392/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10742815/viewspace-2138392/