Steps:

  • you have to prepare environment for Android. Details are provided here: http://appium.io/slate/en/master/?java#setup-(android)//准备安卓环境。

  • you have to download the desktop app for Windows or Mac OS X or install it using npm $ npm install -g appium or $ npm install appium@required_version//安装appium server。

  • it needs to launch the appium server. If you use the server installed via npm then

    $ node the_path_to_js_file --arg1 value1 --arg2 value2 where the_path_to_js_file is the full path to appium.js file (if the node server version version <= 1.4.16) or main.js (if the node server version version >= 1.5.0). It is not necessary to use arguments. The list of arguments: http://appium.io/slate/en/master/?java#appium-server-arguments//启动appium server。

The starting of an app

It looks like creation of a common RemoteWebDriver instance.

Common capabilities

Android-specific capabilities

Common capabilities provided by Java client

Android-specific capabilities provided by Java client

//范例一:启动一个app。

 import java.io.File;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.MobileElement;
import java.net.URL; ...
File app = new File("The absolute or relative path to an *.apk file");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
//you are free to set additional capabilities
AppiumDriver<MobileElement> driver = new AndroidDriver<>(
new URL("http://target_ip:used_port/wd/hub"), //if it needs to use locally started server
//then the target_ip is 127.0.0.1 or 0.0.0.0
//the default port is 4723
capabilities);

//范例二:启动手机浏览器。

If it needs to start browser then:

 import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.remote.RemoteWebElement;
import java.net.URL; ...
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.CHROME);//使用谷歌浏览器
//if it is necessary to use the default Android browser then MobileBrowserType.BROWSER//使用自带浏览器
//is your choise
...
//you are free to set additional capabilities
AppiumDriver<MobileElement> driver = new AndroidDriver<>(
new URL("http://target_ip:used_port/wd/hub"), capabilities);

or

 import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.remote.MobilePlatform;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL; ...
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.CHROME);
//you are free to set additional capabilities
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://target_ip:used_port/wd/hub"), capabilities);

最新文章

  1. Jsp的九个内置对象
  2. Markdown 写作工具选择
  3. find命令学习
  4. Intel OIT demo
  5. JAVA跑马灯实现1
  6. phpmyadmin安装出错,缺少 mysqli 扩展。请检查 PHP 配置
  7. C++ Const成员函数
  8. volatile举列说明const
  9. 虚拟机设备直通的两种方式(Working in Progress)
  10. 混合使用Azure LB和ILB访问相同web服务(2)
  11. TestNG简介与安装步骤
  12. 【Netty】源码分析目录
  13. 多态&amp;nbsp;OC——第十天
  14. TypeScript 错误property does not exist on type Object
  15. js处理有序列表、js处理无序列表
  16. MySQL联合索引VS单列索引
  17. js 面向对象的三大特性
  18. ThreadPoolExecutor参数
  19. myeclipse debug模式 报错source not found
  20. Android——Activity跳转

热门文章

  1. LeetCode OJ-- Spiral Matrix II
  2. 关于Red5整合springMVC提示scope not found 的错误
  3. HTML-loading动画1
  4. ASP.NET HttpContext类
  5. Geoserver跨域请求设置
  6. C#网络编程系列文章(一)之Socket实现异步TCPserver
  7. C#报错&quot;线程间操作无效: 从不是创建控件“XXX”的线程访问它&quot;--解决示例
  8. 百科知识 .tar.xz文件如何打开
  9. youtube-dl取代you-get?
  10. wince开发_摩托罗拉MC3100_打开条码设置