appium(12)-The starting of an app
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 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);
最新文章
- Jsp的九个内置对象
- Markdown 写作工具选择
- find命令学习
- Intel OIT demo
- JAVA跑马灯实现1
- phpmyadmin安装出错,缺少 mysqli 扩展。请检查 PHP 配置
- C++ Const成员函数
- volatile举列说明const
- 虚拟机设备直通的两种方式(Working in Progress)
- 混合使用Azure LB和ILB访问相同web服务(2)
- TestNG简介与安装步骤
- 【Netty】源码分析目录
- 多态&;nbsp;OC——第十天
- TypeScript 错误property does not exist on type Object
- js处理有序列表、js处理无序列表
- MySQL联合索引VS单列索引
- js 面向对象的三大特性
- ThreadPoolExecutor参数
- myeclipse debug模式 报错source not found
- Android——Activity跳转
热门文章
- LeetCode OJ-- Spiral Matrix II
- 关于Red5整合springMVC提示scope not found 的错误
- HTML-loading动画1
- ASP.NET HttpContext类
- Geoserver跨域请求设置
- C#网络编程系列文章(一)之Socket实现异步TCPserver
- C#报错";线程间操作无效: 从不是创建控件“XXX”的线程访问它";--解决示例
- 百科知识 .tar.xz文件如何打开
- youtube-dl取代you-get?
- wince开发_摩托罗拉MC3100_打开条码设置