<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Appium简明教程 on 重定向学院</title><link>https://itest2025.pages.dev/categories/appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B/</link><description>Recent content in Appium简明教程 on 重定向学院</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Tue, 17 Jun 2025 17:29:15 +0800</lastBuildDate><atom:link href="https://itest2025.pages.dev/categories/appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B/index.xml" rel="self" type="application/rss+xml"/><item><title>appium新手入门（1）—— appium介绍</title><link>https://itest2025.pages.dev/tutorials/21-001-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A81-appium%E4%BB%8B%E7%BB%8D/</link><pubDate>Fri, 08 Sep 2017 12:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-001-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A81-appium%E4%BB%8B%E7%BB%8D/</guid><description>&lt;h3 id="appium介绍">appium介绍&lt;/h3>
&lt;hr>
&lt;p>&lt;a href="http://appium.io/" target="_blank" rel="noopener noreffer ">官方网站&lt;/a>&lt;/p>
&lt;h4 id="1特点">1、特点&lt;/h4>
&lt;hr>
&lt;p>appium 是一个自动化测试开源工具，支持 iOS 平台和 Android 平台上的原生应用，web应用和混合应用。&lt;/p>
&lt;ul>
&lt;li>
&lt;p>“移动原生应用”是指那些用iOS或者 Android SDK 写的应用（Application简称app）。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>“移动web应用”是指使用移动浏览器访问的应用（appium支持iOS上的Safari和Android上的 Chrome）。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>“混合应用”是指原生代码封装网页视图——原生代码和 web 内容交互。比如，像 Phonegap，可以帮助开发者使用网页技术开发应用，然后用原生代码封装，这些就是混合应用。&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>重要的是，appium是一个跨平台的工具：它允许测试人员在不同的平台（iOS，Android）使用同一套API来写自动化测试脚本，这样大大增加了iOS和Android测试套件间代码的复用性。&lt;/p>
&lt;h4 id="2appium与selenium">2、appium与Selenium&lt;/h4>
&lt;hr>
&lt;p>appium类库封装了标准Selenium客户端类库，为用户提供所有常见的JSON格式selenium命令以及额外的移动设备控制相关的命令，如多点触控手势和屏幕朝向。&lt;/p>
&lt;p>appium客户端类库实现了Mobile JSON Wire Protocol（一个标准协议的官方扩展草稿）和W3C WebDriver spec（一个传输不可预知的自动化协议，该协议定义了MultiAction 接口）的元素。&lt;/p>
&lt;p>appium服务端定义了官方协议的扩展，为appium 用户提供了方便的接口来执行各种设备动作，例如在测试过程中安装/卸载App。这就是为什么我们需要appium特定的客户端，而不是通用的Selenium 客户端。当然，appium 客户端类库只是增加了一些功能，而实际上这些功能就是简单的扩展了Selenium 客户端，所以他们仍然可以用来运行通用的Selenium会话。&lt;/p>
&lt;h4 id="3支持多平台多语言">3、支持多平台、多语言&lt;/h4>
&lt;hr>
&lt;p>appium是跨平台的，可以用在OSX，Windows以及Linux桌面系统上运行。&lt;/p>
&lt;p>appium选择了Client/Server的设计模式。只要client能够发送http请求给server，那么的话client用什么语言来实现都是可以的，这就是appium及Selenium(WebDriver)如何做到支持多语言的原因；&lt;/p>
&lt;p>appium扩展了WebDriver的协议，没有自己重新去实现一套。这样的好处是以前的WebDriver API能够直接被继承过来，以前的Selenium（WebDriver）各种语言的binding都可以拿来就用，省去了为每种语言开发一个client的工作量；&lt;/p>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th style="text-align: left">语言/框架&lt;/th>
 &lt;th style="text-align: left">Github地址&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td style="text-align: left">Ruby&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/appium/ruby_lib" target="_blank" rel="noopener noreffer ">https://github.com/appium/ruby_lib&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">Python&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/appium/python-client" target="_blank" rel="noopener noreffer ">https://github.com/appium/python-client&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">Java&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/appium/java-client" target="_blank" rel="noopener noreffer ">https://github.com/appium/java-client&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">JavaScript (Node.js)&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/admc/wd" target="_blank" rel="noopener noreffer ">https://github.com/admc/wd&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">Objective C&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/appium/selenium-objective-c" target="_blank" rel="noopener noreffer ">https://github.com/appium/selenium-objective-c&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">PHP&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/appium/php-client" target="_blank" rel="noopener noreffer ">https://github.com/appium/php-client&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">C# (.NET)&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/appium/appium-dotnet-driver" target="_blank" rel="noopener noreffer ">https://github.com/appium/appium-dotnet-driver&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">RobotFramework&lt;/td>
 &lt;td style="text-align: left">&lt;a href="https://github.com/jollychang/robotframework-appiumlibrary" target="_blank" rel="noopener noreffer ">https://github.com/jollychang/robotframework-appiumlibrary&lt;/a>&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;h4 id="4appium工作原理">4、appium工作原理&lt;/h4>
&lt;hr>
&lt;p>在安装和介绍appium之前，非常有必要介绍一下appium是如何工作的。&lt;/p></description></item><item><title>appium简明教程（1）——appium和它的哲学世界</title><link>https://itest2025.pages.dev/tutorials/21-001-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B1appium%E5%92%8C%E5%AE%83%E7%9A%84%E5%93%B2%E5%AD%A6%E4%B8%96%E7%95%8C/</link><pubDate>Sun, 20 Aug 2017 06:05:07 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-001-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B1appium%E5%92%8C%E5%AE%83%E7%9A%84%E5%93%B2%E5%AD%A6%E4%B8%96%E7%95%8C/</guid><description>&lt;h3 id="什么是appium">什么是appium？&lt;/h3>
&lt;p>下面这段介绍来自于appium的官网。&lt;/p>
&lt;blockquote>
&lt;p>Appium is an open-source tool you can use to automate mobile native, mobile web, and mobile hybrid applications on iOS and Android platforms. “Mobile native apps” are those written using the iOS or Android SDKs. “Mobile web apps” are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome on Android). “Mobile hybrid apps” have a native wrapper around a “webview” – a native control that enables interaction with web content. Projects like Phonegap, for example, make it easy to build apps using web technologies that are then bundled into a native wrapper – these are hybrid apps.&lt;/p></description></item><item><title>appium新手入门（2）—— 安装 Android SDK</title><link>https://itest2025.pages.dev/tutorials/21-002-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A82-%E5%AE%89%E8%A3%85-android-sdk/</link><pubDate>Thu, 07 Sep 2017 12:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-002-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A82-%E5%AE%89%E8%A3%85-android-sdk/</guid><description>&lt;p>&lt;font color=#DC143C>&lt;strong>注明：&lt;/strong> 理论上这一章不是必须的，如果你不想使用 Android 模拟器运行测试的话可以跳过，不过，建议安装；原生 Android 好折腾！关键是它自带的一些工具是你做 appium 测试必须要用的！&lt;/font>&lt;/p>
&lt;h3 id="安装android-sdk">安装Android SDK&lt;/h3>
&lt;hr>
&lt;p>Android SDK（Software Development Kit，软件开发工具包）提供了 Android API 库和开发工具构建，测试和调试应用程序。简单来讲，Android SDK 可以看做用于开发和运行 Android 应用的一个软件。&lt;/p>
&lt;h4 id="1下载android-sdk">1、下载Android SDK&lt;/h4>
&lt;hr>
&lt;p>我在官网上没有找到单独 Android SDK 的下载链接，官方推荐下载包含 Android SDK 的 Android Studio。&lt;/p>
&lt;p>Android Studio &amp;amp; Android SDK 下载地址：https://developer.android.com/studio/index.html?hl=zh-cn&lt;/p>
&lt;p>拖到页面底部，你将找到下载链接，根据自己的平台选择对应的链接下载。&lt;/p>
&lt;p>一方面是包含 Android SDK 的 Android Studio 的安装包很大。另一方面它们二者也不是强关联的。因为 Appium也会用到 Android SDK，而 Android Studio 也可以调用真机来运行 Android程序。&lt;/p>
&lt;p>所以，Android SDK 下载地址（才是我们想要的）：&lt;/p>
&lt;p>&lt;a href="http://tools.android-studio.org/index.php/sdk" target="_blank" rel="noopener noreffer ">http://tools.android-studio.org/index.php/sdk&lt;/a>&lt;/p>
&lt;p>你可以通过别的网站进行下载，身为IT从业人员，如何利用搜索工具和科学上网工具是你的必备技能。&lt;/p>
&lt;p>将下载的 Android SDK 解压，将得到如下目录。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_sdk_path.png"
 data-srcset="http://img.testclass.net/appium_sdk_path.png, http://img.testclass.net/appium_sdk_path.png 1.5x, http://img.testclass.net/appium_sdk_path.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_sdk_path.png"
 title="http://img.testclass.net/appium_sdk_path.png" />&lt;/p></description></item><item><title>appium简明教程（2）——appium的基本概念</title><link>https://itest2025.pages.dev/tutorials/21-002-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B2appium%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5/</link><pubDate>Sat, 19 Aug 2017 06:14:09 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-002-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B2appium%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5/</guid><description>&lt;h3 id="clientserver-architecture">Client/Server Architecture&lt;/h3>
&lt;p>appium的核心其实是一个暴露了一系列REST API的server。&lt;/p>
&lt;p>这个server的功能其实很简单：监听一个端口，然后接收由client发送来的command。翻译这些command，把这些command转成移动设备可以理解的形式发送给移动设备，然后移动设备执行完这些command后把执行结果返回给appium server，appium server再把执行结果返回给client。&lt;/p>
&lt;p>在这里client其实就是发起command的设备，一般来说就是我们代码执行的机器，执行appium测试代码的机器。狭义点理解，可以把client理解成是代码，这些代码可以是java/ruby/python/js的，只要它实现了webdriver标准协议就可以。&lt;/p>
&lt;p>这样的设计思想带来了一些好处：&lt;/p>
&lt;ul>
&lt;li>1，可以带来多语言的支持；&lt;/li>
&lt;li>2，可以把server放在任意机器上，哪怕是云服务器都可以；（是的，appium和webdriver天生适合云测试）&lt;/li>
&lt;/ul>
&lt;h3 id="session">Session&lt;/h3>
&lt;p>session就是一个会话，在webdriver/appium，你的所有工作永远都是在session start后才可以进行的。一般来说，通过POST /session这个URL，然后传入&lt;strong>Desired Capabilities&lt;/strong>就可以开启session了。&lt;/p>
&lt;p>开启session后，会返回一个全局唯一的session id，以后几乎所有的请求都必须带上这个session id，因为这个seesion id代表了你所打开的浏览器或者是移动设备的模拟器。&lt;/p>
&lt;p>进一步思考一下，由于session id是全局唯一，那么在同一台机器上启动多个session就变成了可能，这也就是selenium gird所依赖的具体理论根据。&lt;/p>
&lt;h3 id="desired-capabilities">Desired Capabilities&lt;/h3>
&lt;p>Desired Capabilities携带了一些配置信息。从本质上讲，这个东东是key-value形式的对象。你可以理解成是java里的map，python里的字典，ruby里的hash以及js里的json对象。实际上Desired Capabilities在传输时就是json对象。&lt;/p>
&lt;p>Desired Capabilities最重要的作用是告诉server本次测试的上下文。这次是要进行浏览器测试还是移动端测试？如果是移动端测试的话是测试android还是ios，如果测试android的话那么我们要测试哪个app？ server的这些疑问Desired Capabilities都必须给予解答，否则server不买账，自然就无法完成移动app或者是浏览器的启动。&lt;/p>
&lt;p>具体例子如下：&lt;/p>
&lt;blockquote>
&lt;p>For example, we might set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android one. Or we might set the safariAllowPopupscapability to true in order to ensure that, during a Safari automation session, we’re allowed to use JavaScript to open up new windows. See the capabilities doc for the complete list of capabilities available for Appium&lt;/p></description></item><item><title>appium新手入门（3）—— 安装 appium Server</title><link>https://itest2025.pages.dev/tutorials/21-003-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A83-%E5%AE%89%E8%A3%85-appium-server/</link><pubDate>Thu, 07 Sep 2017 11:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-003-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A83-%E5%AE%89%E8%A3%85-appium-server/</guid><description>&lt;p>我们可以在Appium官方网站上下载操作系统相应的Appium版本。&lt;/p>
&lt;p>&lt;a href="https://bitbucket.org/appium/appium.app/downloads/" target="_blank" rel="noopener noreffer ">https://bitbucket.org/appium/appium.app/downloads/&lt;/a>&lt;/p>
&lt;p>当前最新版本为 &lt;strong>AppiumForWindows_1_4_16_1.zip&lt;/strong> ，注意这是一个 Windows 版本，如果你的电脑为MAC请下载 &lt;strong>appium-1.5.3.dmg&lt;/strong> 。虽然你已经看到了这些下载包，但我不保证你能下载的下来。&lt;/p>
&lt;p>所以，再来提供一个百度网盘的下载链接：https://pan.baidu.com/s/1pKMwdfX&lt;/p>
&lt;p>我们以 Windows 为例，将下载的 AppiumForWindows.zip 进行解压，点击 &lt;strong>appium-installer.exe&lt;/strong> 进行安装。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_server_install.png"
 data-srcset="http://img.testclass.net/appium_server_install.png, http://img.testclass.net/appium_server_install.png 1.5x, http://img.testclass.net/appium_server_install.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_server_install.png"
 title="http://img.testclass.net/appium_server_install.png" />&lt;/p>
&lt;p>根据提示，一步一步进行安装，这里不再啰嗦。最终在会桌面上生成 &lt;strong>Appium图标&lt;/strong> , 双击启动，appium server 界面如下。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_server_view.png"
 data-srcset="http://img.testclass.net/appium_server_view.png, http://img.testclass.net/appium_server_view.png 1.5x, http://img.testclass.net/appium_server_view.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_server_view.png"
 title="http://img.testclass.net/appium_server_view.png" />&lt;/p>
&lt;p>Appium-Server已经可以打开了。至于Appium的使用我们放到后面的章节进行介绍。&lt;/p>
&lt;p>最后，打开Windows命令提示符，输入“appium-doctor”命令，如果出现以下提示，说明你Appium所需要的各项环境都已准备完成。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_server_environment.png"
 data-srcset="http://img.testclass.net/appium_server_environment.png, http://img.testclass.net/appium_server_environment.png 1.5x, http://img.testclass.net/appium_server_environment.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_server_environment.png"
 title="http://img.testclass.net/appium_server_environment.png" />&lt;/p>
&lt;p>注：如果提示：&lt;strong>“appium-doctor”不是内部或外部命令&lt;/strong>，找到Appium的安装目录，例如：&lt;/p>
&lt;p>&lt;strong>C:\Program Files\Appium\node_modules\.bin&lt;/strong>&lt;/p>
&lt;p>添加到环境变量path下面（参考Java环境的设置）。&lt;/p>
&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1534088568595-a066f410bcda?w=300"
 data-srcset="https://images.unsplash.com/photo-1534088568595-a066f410bcda?w=300, https://images.unsplash.com/photo-1534088568595-a066f410bcda?w=300 1.5x, https://images.unsplash.com/photo-1534088568595-a066f410bcda?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1534088568595-a066f410bcda?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium简明教程（3）——appium的安装windows版</title><link>https://itest2025.pages.dev/tutorials/21-003-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B3appium%E7%9A%84%E5%AE%89%E8%A3%85windows%E7%89%88/</link><pubDate>Fri, 18 Aug 2017 07:14:54 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-003-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B3appium%E7%9A%84%E5%AE%89%E8%A3%85windows%E7%89%88/</guid><description>&lt;p>appium的哲学里有一条就是不重新发明轮子。同样，官方已经有明确的安装步骤了，因此在这里纯属搬砖。&lt;/p>
&lt;p>&lt;a href="https://github.com/appium/appium/blob/master/docs/cn/appium-setup/running-on-windows.md" target="_blank" rel="noopener noreffer ">原文地址&lt;/a>&lt;/p>
&lt;p>感谢testerhome的辛勤翻译。&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;h3 id="限制">限制&lt;/h3>
&lt;p>如果你在windows上安装appium，你没法使用预编译专用于OS X的.app文件，你也将不能测试IOS apps，因为appium依赖OS X专用的库来支持IOS测试。这意味着你只能通过在mac上来运行IOS的app测试。这点限制挺大。&lt;/p>
&lt;h3 id="开始安装">开始安装&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>安装nodejs 通过官方的安装程序来安装。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>安装android的sdk包，(&lt;a href="http://developer.android.com/sdk/index.html%29" target="_blank" rel="noopener noreffer ">http://developer.android.com/sdk/index.html)&lt;/a>, 运行依赖sdk中的&amp;rsquo;android&amp;rsquo;工具。并确保你安装了Level17或以上的版本api。设置ANDROID_HOME系统变量为你的Android SDK路径，并把tools platform-tools两个目录加入到系统的Path路径里。因为这里面包含有一些执行命令&lt;/p>
&lt;/li>
&lt;li>
&lt;p>安装java的JDK，并设置JAVA_HOME 变量为你的JDK目录。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>安装Apache Ant 或者直接使用Android Windows SDK自带的ant，地址在eclipse\plugins目录，你需要把这个目录加到你的系统PATH变量中&lt;/p>
&lt;/li>
&lt;li>
&lt;p>安装&lt;a href="http://maven.apache.org/download.cgi" target="_blank" rel="noopener noreffer ">Apache Maven&lt;/a>. 并且设置M2HOME和M2环境变量，把M2环境变量添加到你的系统PATH变量中。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>安装&lt;a href="https://git-scm.com/download/win" target="_blank" rel="noopener noreffer ">Git&lt;/a>. 确保你安装了windows下的Git，以便可以运行常用的command命令&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>现在，你已经下载安装了所有的依赖，开始运行 reset.bat&lt;/p>
&lt;h3 id="运行appium">运行Appium&lt;/h3>
&lt;p>要在windows上运行测试用例，你需要先启动Android模拟器或者连接上一个API Level17以上的android真机。 然后在命令行运行appium node .&lt;/p>
&lt;h3 id="备注">备注&lt;/h3>
&lt;ul>
&lt;li>你必须带上&amp;ndash;no-reset和&amp;ndash;full-reset标记，以用于windows上的android&lt;/li>
&lt;li>有一个硬件加速模拟器用于android，但是它有自己的一些限制，如果你想了解更多，请参考页面&lt;/li>
&lt;li>确保在你的AVD的config.ini中有一个配置项为hw.battery=yes&lt;/li>
&lt;/ul>
&lt;h3 id="最简略的安装方式">最简略的安装方式&lt;/h3>
&lt;p>出于对官方文档的尊重，我按照原文翻译，如下介绍我的安装心得。官方提到的一些工具，其实并不需要安装。 下面介绍我已经测试过的安装和使用过程&lt;/p>
&lt;h3 id="安装appium">安装appium&lt;/h3>
&lt;ol>
&lt;li>
&lt;p>安装nodejs&lt;/p>
&lt;/li>
&lt;li>
&lt;p>使用npm安装appium: &lt;code>npm install -g appium&lt;/code>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>注意：在某些情况下，appium安装的时候并不会把appium的路径放进系统的PATH里，这时候需要手工去加一下。&lt;/p>
&lt;h3 id="运行appium-1">运行appium&lt;/h3>
&lt;p>启动appium，直接运行appium 即可。&lt;/p>
&lt;h3 id="更新appium">更新appium&lt;/h3>
&lt;p>通过&lt;code>npm install -g appium&lt;/code> 来更新appium即可&lt;/p>
&lt;p>下一节，appium client的安装&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p></description></item><item><title>appium新手入门（4）—— java-client安装与测试</title><link>https://itest2025.pages.dev/tutorials/21-004-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A84-java-client%E5%AE%89%E8%A3%85%E4%B8%8E%E6%B5%8B%E8%AF%95/</link><pubDate>Thu, 07 Sep 2017 10:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-004-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A84-java-client%E5%AE%89%E8%A3%85%E4%B8%8E%E6%B5%8B%E8%AF%95/</guid><description>&lt;p>&lt;strong>关联阅读：&lt;/strong>&lt;/p>
&lt;p>&lt;a href="https://itest2025.pages.dev/appium/appium-base-summary/" rel="">appium新手入门（1）—— appium介绍&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://itest2025.pages.dev/appium/appium-base-sdk/" rel="">appium新手入门（2）—— 安装 Android SDK&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://itest2025.pages.dev/appium/appium-base-server/" rel="">appium新手入门（3）—— 安装 appium Server&lt;/a>&lt;/p>
&lt;br>
#### 前提条件
----
&lt;p>当你点击这一章时，说明你是打算使用 Java 语言编写 appium 自动化测试脚本的。&lt;/p>
&lt;p>1、安装 &lt;a href="https://itest2025.pages.dev/selenium_java/install-java/" rel="">Java 环境&lt;/a> ,我想这一步你已经搞定了&lt;/p>
&lt;p>2、安装 &lt;a href="https://itest2025.pages.dev/selenium_java/install-idea/" rel="">IntelliJ IDEA&lt;/a> , 当然，你喜欢用 Eclipse 也可以，不过，我仍然推荐 IDEA。&lt;/p>
&lt;p>3、安装 &lt;a href="https://itest2025.pages.dev/selenium_java/install-selenium/" rel="">Maven&lt;/a>, Java开发必备啊！&lt;/p>
&lt;h4 id="maven-安装-java-client">Maven 安装 Java-client&lt;/h4>
&lt;hr>
&lt;p>首先，启动IntelliJ IDEA，创建Maven项目（参考selenium java教程），然后在maven配置文件中添加Java-client配置。&lt;/p>
&lt;pre>&lt;code>&amp;lt;dependency&amp;gt;
 &amp;lt;groupId&amp;gt;io.appium&amp;lt;/groupId&amp;gt;
 &amp;lt;artifactId&amp;gt;java-client&amp;lt;/artifactId&amp;gt;
 &amp;lt;version&amp;gt;5.0.0-BETA9&amp;lt;/version&amp;gt;
 &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code>&lt;/pre>
&lt;p>最新版本号可以到 github &lt;a href="https://github.com/appium/java-client" target="_blank" rel="noopener noreffer ">Java-client开源项目&lt;/a>上查看。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_idea_maven.png"
 data-srcset="http://img.testclass.net/appium_idea_maven.png, http://img.testclass.net/appium_idea_maven.png 1.5x, http://img.testclass.net/appium_idea_maven.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_idea_maven.png"
 title="http://img.testclass.net/appium_idea_maven.png" />&lt;/p>
&lt;br>
#### 运行第一个Appium测试
----
* __第一步__，启动Android模拟器。
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_android_system.png"
 data-srcset="http://img.testclass.net/appium_android_system.png, http://img.testclass.net/appium_android_system.png 1.5x, http://img.testclass.net/appium_android_system.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_android_system.png"
 title="http://img.testclass.net/appium_android_system.png" />&lt;/p></description></item><item><title>appium简明教程（4）——appium client的安装</title><link>https://itest2025.pages.dev/tutorials/21-004-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B4appium-client%E7%9A%84%E5%AE%89%E8%A3%85/</link><pubDate>Thu, 17 Aug 2017 07:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-004-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B4appium-client%E7%9A%84%E5%AE%89%E8%A3%85/</guid><description>&lt;p>appium client是对webdriver原生api的一些扩展和封装。它可以帮助我们更容易的写出用例，写出更好懂的用例。&lt;/p>
&lt;p>appium client是配合原生的webdriver来使用的，因此二者必须配合使用缺一不可。&lt;/p>
&lt;p>从本节开始，教程的内容将涵盖3个语言，ruby/python/java。&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;h3 id="安装appium-client">安装appium client&lt;/h3>
&lt;h4 id="ruby篇一定要在线安装">ruby篇（一定要在线安装）&lt;/h4>
&lt;p>ruby的appium client叫做appium lib，为什么是这样就不解释了，总之是历史原因。&lt;/p>
&lt;p>首先update rubygem和bundler(说老实话，真的不需要，但官方文档上这么写)&lt;/p>
&lt;pre tabindex="0">&lt;code>gem update --system ;\
gem update bundler
&lt;/code>&lt;/pre>&lt;p>然后使用gem安装&lt;/p>
&lt;pre tabindex="0">&lt;code>gem uninstall -aIx appium_lib ;\(这个也不是必须的)
gem install --no-rdoc --no-ri appium_lib
&lt;/code>&lt;/pre>&lt;h4 id="python篇尽量在线安装">python篇（尽量在线安装）&lt;/h4>
&lt;p>推荐使用pip安装&lt;/p>
&lt;pre tabindex="0">&lt;code>pip install Appium-Python-Client
&lt;/code>&lt;/pre>&lt;p>当然了也可以在Pipy上下载源码安装&lt;/p>
&lt;pre tabindex="0">&lt;code>tar -xvf Appium-Python-Client-X.X.tar.gz（windows上用7zip可以解压）
cd Appium-Python-Client-X.X
python setup.py install
&lt;/code>&lt;/pre>&lt;p>最后，也可以通过github安装（要git客户端）&lt;/p>
&lt;pre tabindex="0">&lt;code>git clone git@github.com:appium/python-client.git
cd python-client
python setup.py install
&lt;/code>&lt;/pre>&lt;h4 id="java篇在线安装">java篇（在线安装）&lt;/h4>
&lt;p>java的话用maven安装就可以了&lt;/p>
&lt;pre tabindex="0">&lt;code>&amp;lt;dependency&amp;gt;
 &amp;lt;groupId&amp;gt;io.appium&amp;lt;/groupId&amp;gt;
 &amp;lt;artifactId&amp;gt;java-client&amp;lt;/artifactId&amp;gt;
 &amp;lt;version&amp;gt;1.3.0&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code>&lt;/pre>&lt;p>当然了，也可以自己&lt;a href="http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.appium%22%20AND%20a%3A%22java-client%22" target="_blank" rel="noopener noreffer ">下载jar包&lt;/a>，请自行选择最新版本。&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1462332420958-a05d1e002413?w=300"
 data-srcset="https://images.unsplash.com/photo-1462332420958-a05d1e002413?w=300, https://images.unsplash.com/photo-1462332420958-a05d1e002413?w=300 1.5x, https://images.unsplash.com/photo-1462332420958-a05d1e002413?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1462332420958-a05d1e002413?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium新手入门（5）—— python-client安装与测试</title><link>https://itest2025.pages.dev/tutorials/21-005-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A85-python-client%E5%AE%89%E8%A3%85%E4%B8%8E%E6%B5%8B%E8%AF%95/</link><pubDate>Thu, 07 Sep 2017 10:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-005-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A85-python-client%E5%AE%89%E8%A3%85%E4%B8%8E%E6%B5%8B%E8%AF%95/</guid><description>&lt;p>&lt;strong>关联阅读：&lt;/strong>&lt;/p>
&lt;p>&lt;a href="https://itest2025.pages.dev/appium/appium-base-summary/" rel="">appium新手入门（1）—— appium介绍&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://itest2025.pages.dev/appium/appium-base-sdk/" rel="">appium新手入门（2）—— 安装 Android SDK&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://itest2025.pages.dev/appium/appium-base-server/" rel="">appium新手入门（3）—— 安装 appium Server&lt;/a>&lt;/p>
&lt;br>
#### 前提条件
----
&lt;p>当你点击这一章时，说明你是打算使用 Python 语言编写 appium 自动化测试脚本的。&lt;/p>
&lt;p>1、安装 &lt;a href="https://itest2025.pages.dev/selenium_python/install-selenium/" rel="">Python 语言&lt;/a> , Python的安装相对相简单得多。&lt;/p>
&lt;p>2、Python 编辑器很多，推荐：PyCharm、Atom、Sublime text3等。这几款都是我常用的。&lt;/p>
&lt;h4 id="安装-python-client">安装 python-client&lt;/h4>
&lt;hr>
&lt;p>其实，&lt;a href="https://github.com/appium/python-client" target="_blank" rel="noopener noreffer ">python-client&lt;/a> 的项目名称叫：Appium-Python-Client。&lt;/p>
&lt;p>推荐pip安装：&lt;/p>
&lt;pre>&lt;code>(venv) λ pip install Appium-Python-Client
Collecting Appium-Python-Client
 Using cached Appium-Python-Client-0.24.tar.gz
Requirement already satisfied: selenium&amp;gt;=2.47.0 in d:\pyflask\venv\lib\site-packages (from Appium-Python-Client)
Building wheels for collected packages: Appium-Python-Client
 Running setup.py bdist_wheel for Appium-Python-Client ... done
 Stored in directory: C:\Users\fnngj\AppData\Local\pip\Cache\wheels\2e\cf\10\0e3f177c9869147b16584d402f79d9007df1139105ea3ecc2c

Successfully built Appium-Python-Client
Installing collected packages: Appium-Python-Client
Successfully installed Appium-Python-Client-0.24
&lt;/code>&lt;/pre>
&lt;br>
#### 运行第一个Appium测试
----
* __第一步__，启动Android模拟器。
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_android_system.png"
 data-srcset="http://img.testclass.net/appium_android_system.png, http://img.testclass.net/appium_android_system.png 1.5x, http://img.testclass.net/appium_android_system.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_android_system.png"
 title="http://img.testclass.net/appium_android_system.png" />&lt;/p></description></item><item><title>appium简明教程（5）——appium client方法一览</title><link>https://itest2025.pages.dev/tutorials/21-005-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B5appium-client%E6%96%B9%E6%B3%95%E4%B8%80%E8%A7%88/</link><pubDate>Wed, 16 Aug 2017 07:30:01 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-005-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B5appium-client%E6%96%B9%E6%B3%95%E4%B8%80%E8%A7%88/</guid><description>&lt;p>appium client扩展了原生的webdriver client方法&lt;/p>
&lt;p>下面以java代码为例，简单过一下appium client提供的适合移动端使用的新方法&lt;/p>
&lt;pre tabindex="0">&lt;code>resetApp()
getAppString()
sendKeyEvent()
currentActivity()
pullFile()
pushFile()
pullFolder()
hideKeyboard()
runAppInBackground()
performTouchAction()
performMultiTouchAction()
tap()
swipe()
pinch()
zoom()
getNamedTextField()
isAppInstalled()
installApp()
removeApp()
launchApp()
closeApp()
endTestCoverage()
lockScreen()
shake()
complexFind()
scrollTo()
scrollToExact()
openNotifications()
Context Switching: .context(), .getContextHandles(), getContext())
&lt;/code>&lt;/pre>&lt;p>新增的locator&lt;/p>
&lt;pre tabindex="0">&lt;code>findElementByAccessibilityId()
findElementsByAccessibilityId()
findElementByIosUIAutomation()
findElementsByIosUIAutomation()
findElementByAndroidUIAutomator()
findElementsByAndroidUIAutomator()
&lt;/code>&lt;/pre>&lt;p>这些方法主要覆盖了3大类：&lt;/p>
&lt;ul>
&lt;li>driver扩展：比如增加了resetApp等操作app的方法&lt;/li>
&lt;li>action扩展：增加一些移动端的特有的action（怎么描述呢，相当于是移动端 特有的操作），比如swipe，shake(嗯，有了这个方法就可以让代码帮你摇一摇了)等；&lt;/li>
&lt;li>locator扩展：增加了一些移动端专属的定位策略&lt;/li>
&lt;/ul>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1504387103978-e4ee71416c38?w=300"
 data-srcset="https://images.unsplash.com/photo-1504387103978-e4ee71416c38?w=300, https://images.unsplash.com/photo-1504387103978-e4ee71416c38?w=300 1.5x, https://images.unsplash.com/photo-1504387103978-e4ee71416c38?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1504387103978-e4ee71416c38?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium新手入门（6）—— appium-desktop</title><link>https://itest2025.pages.dev/tutorials/21-006-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A86-appium-desktop/</link><pubDate>Thu, 07 Sep 2017 10:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-006-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A86-appium-desktop/</guid><description>&lt;h4 id="什么是-appium-desktop">什么是 Appium-desktop？&lt;/h4>
&lt;hr>
&lt;p>项目地址：https://github.com/appium/appium-desktop&lt;/p>
&lt;p>项目描述：&lt;/p>
&lt;blockquote>
&lt;p>Appium Server and Inspector in Desktop GUIs for Mac, Windows, and Linux。&lt;/p>&lt;/blockquote>
&lt;p>Appium 移动测试中有个很重新的组件 &lt;a href="https://itest2025.pages.dev/appium/appium-base-server/" rel="">Appium-Server&lt;/a>，它主要用来监听我们的移动设备（真机或模拟器），然将不同编程语言编写的 appium 测试脚本进行解析，然后，驱动移动设备来运行测试。&lt;/p>
&lt;p>但Appium-Server有一两年没有更新了。Windows版在 2015 年底止步于的 &lt;strong>AppiumForWindows_1_4_16_1.zip&lt;/strong>&lt;/p>
&lt;p>于是，新的工具 Appium-desktop 来了！ 它来继续 Appium-Server的使命，当然， Appium-Server当前仍然是可用的。&lt;/p>
&lt;h4 id="下载与安装">下载与安装&lt;/h4>
&lt;hr>
&lt;p>appium-desktop 下载地址：&lt;a href="https://github.com/appium/appium-desktop/releases" target="_blank" rel="noopener noreffer ">这里&lt;/a>&lt;/p>
&lt;p>根据自己的平台选择相关的包进行下载。本文以 Windows 为例，所以选择 &lt;strong>appium-desktop-Setup-1.2.4.exe&lt;/strong> 文件进行下载。&lt;/p>
&lt;p>安装过程太简单了，双击 exe 文件，然后，等待安装完就好了，中间都不需要你设置任何选项。所以，这里就不贴图了。&lt;/p>
&lt;h4 id="启动运行">启动运行&lt;/h4>
&lt;hr>
&lt;p>安装完成桌面会生成一个紫色的 appium 图标，双击打开。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_desktop_01.png"
 data-srcset="http://img.testclass.net/appium_desktop_01.png, http://img.testclass.net/appium_desktop_01.png 1.5x, http://img.testclass.net/appium_desktop_01.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_desktop_01.png"
 title="http://img.testclass.net/appium_desktop_01.png" />&lt;/p>
&lt;p>默认显示监控的 host 和 port ，这和 Appium-Server中是一致的。点击 &lt;strong>“Start Server V 1.7.1”&lt;/strong> 按钮启动服务。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_desktop_02.png"
 data-srcset="http://img.testclass.net/appium_desktop_02.png, http://img.testclass.net/appium_desktop_02.png 1.5x, http://img.testclass.net/appium_desktop_02.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_desktop_02.png"
 title="http://img.testclass.net/appium_desktop_02.png" />&lt;/p></description></item><item><title>appium简明教程（6）——启动appium及android模拟器</title><link>https://itest2025.pages.dev/tutorials/21-006-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B6%E5%90%AF%E5%8A%A8appium%E5%8F%8Aandroid%E6%A8%A1%E6%8B%9F%E5%99%A8/</link><pubDate>Tue, 15 Aug 2017 07:33:41 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-006-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B6%E5%90%AF%E5%8A%A8appium%E5%8F%8Aandroid%E6%A8%A1%E6%8B%9F%E5%99%A8/</guid><description>&lt;p>一般情况下，我们都从命令行启动appium。&lt;/p>
&lt;p>windows下，dos命令窗口输入&lt;/p>
&lt;pre tabindex="0">&lt;code>appium
&lt;/code>&lt;/pre>&lt;p>如果该命令报错，那么请重装appium&lt;/p>
&lt;pre tabindex="0">&lt;code>npm install -g appium
&lt;/code>&lt;/pre>&lt;p>如果安装出错，请使用淘宝源。&lt;/p>
&lt;p>&lt;a href="http://npm.taobao.org/" target="_blank" rel="noopener noreffer ">淘宝源地址&lt;/a>&lt;/p>
&lt;p>&lt;strong>然后请打开android的模拟器，如果没有请新建一个虚拟设备。请自行解除设备锁定（手动把屏幕解锁了），以防万一。&lt;/strong>&lt;/p>
&lt;p>下面的代码以启动android原生的计算器程序为例&lt;/p>
&lt;h3 id="ruby篇">ruby篇&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-ruby" data-lang="ruby">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">require&lt;/span> &lt;span class="s1">&amp;#39;appium_lib&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">caps&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="ss">caps&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="ss">platformName&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s1">&amp;#39;Android&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="ss">appActivity&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s1">&amp;#39;.Calculator&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="ss">appPackage&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s1">&amp;#39;com.android.calculator2&amp;#39;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="ss">appium_lib&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="ss">sauce_username&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kp">nil&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="ss">sauce_access_key&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kp">nil&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="no">Appium&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="no">Driver&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">new&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">caps&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">start_driver&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>讨论：可以看出ruby lib里面的Appium::Driver类实际上就是原生的webdriver类的子类，当然了，由于ruby语法灵活，也可以使用monkey patch来实现类似功能。&lt;/p>
&lt;h3 id="python篇">python篇&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">appium&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">webdriver&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">desired_caps&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">desired_caps&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;platformName&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;Android&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">desired_caps&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;platformVersion&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;4.2&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">desired_caps&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;deviceName&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;Android Emulator&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">desired_caps&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;appPackage&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;com.android.calculator2&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">desired_caps&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;appActivity&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;.Calculator&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">webdriver&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">Remote&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;http://localhost:4723/wd/hub&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">desired_caps&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>讨论：webdriver.Remote实际上就是原生webdriver的子类，另外Remote()构造函数的第一个参数中需要显示指定appium server监听的端口&lt;/p>
&lt;h3 id="java篇">java篇&lt;/h3>
&lt;p>新建java项目时候，请注意将selenium-webdriver以及appium client的jar包导入&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nn">io.appium.java_client.AppiumDriver&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kn">import&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nn">org.openqa.selenium.By&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kn">import&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nn">org.openqa.selenium.WebElement&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kn">import&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nn">org.openqa.selenium.remote.CapabilityType&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kn">import&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nn">org.openqa.selenium.remote.DesiredCapabilities&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">DesiredCapabilities&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DesiredCapabilities&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">CapabilityType&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">BROWSER_NAME&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="c1">//这句不是必须的&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;deviceName&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">&amp;#34;Android Emulator&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;platformVersion&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;4.4&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;platformName&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">&amp;#34;Android&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;appPackage&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;com.android.calculator2&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;appActivity&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;.Calculator&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">AppiumDriver&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">AppiumDriver&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">URL&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;http://127.0.0.1:4723/wd/hub&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>讨论:AppiumDrvier是原生webdriver的子类。&lt;/p></description></item><item><title>appium新手入门（7）—— Desired Capabilities</title><link>https://itest2025.pages.dev/tutorials/21-007-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A87-desired-capabilities/</link><pubDate>Thu, 07 Sep 2017 10:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-007-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A87-desired-capabilities/</guid><description>&lt;p>&lt;font color="blue">从后台统计来看，appium 系列的教程很受欢迎！于是，我继续更新，也希望你把这个教程推荐给更多学习 appium 的小伙伴！&lt;/font>&lt;/p>
&lt;h4 id="desired-capabilities">Desired Capabilities&lt;/h4>
&lt;hr>
&lt;p>Desired Capabilities 在启动 session 的时候是必须提供的。&lt;/p>
&lt;p>Desired Capabilities 本质上是以 key value 字典的方式存放，客户端将这些键值对发给服务端，告诉服务端我们想要怎么测试。它告诉 appium Server这样一些事情：&lt;/p>
&lt;ul>
&lt;li>
&lt;p>本次测试是启动浏览器还是启动移动设备。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>是启动Andorid还是启动iOS。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>启动Android时，app的package是什么。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>启动Android时，app的activity是什么。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&amp;hellip;&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h4 id="desired-capabilities-配置">Desired Capabilities 配置&lt;/h4>
&lt;hr>
&lt;p>Appium 的 Desired Capabilities 基本配置如下：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Java" data-lang="Java">&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">DesiredCapabilities&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DesiredCapabilities&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;deviceName&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Android Emulator&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;automationName&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Appium&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;platformName&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Android&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;platformVersion&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;5.1&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;appPackage&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;com.android.calculator2&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCapability&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;appActivity&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;.Calculator&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">WebDriver&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">AndroidDriver&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">URL&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;http://127.0.0.1:4723/wd/hub&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">capabilities&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>
&lt;p>deviceName：启动哪种设备，是真机还是模拟器？iPhone Simulator，iPad Simulator，iPhone Retina 4-inch，Android Emulator，Galaxy S4&amp;hellip;&lt;/p>
&lt;/li>
&lt;li>
&lt;p>automationName：使用哪种自动化引擎。appium（默认）还是Selendroid。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>platformName：使用哪种移动平台。iOS, Android, orFirefoxOS。&lt;/p></description></item><item><title>appium简明教程（7）——Desired Capabilities详解</title><link>https://itest2025.pages.dev/tutorials/21-007-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B7desired-capabilities%E8%AF%A6%E8%A7%A3/</link><pubDate>Mon, 14 Aug 2017 08:01:35 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-007-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B7desired-capabilities%E8%AF%A6%E8%A7%A3/</guid><description>&lt;p>Desired Capabilities在启动session的时候是必须提供的。&lt;/p>
&lt;p>Desired Capabilities本质上是key value的对象，它告诉appium server这样一些事情：&lt;/p>
&lt;ul>
&lt;li>本次测试是启动浏览器还是启动移动设备？&lt;/li>
&lt;li>是启动andorid还是启动ios？&lt;/li>
&lt;li>启动android时，app的package是什么？&lt;/li>
&lt;li>启动android时，app的activity是什么？&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Appium的Desired Capabilities是扩展了webdriver的Desired Capabilities的，下面的一些通用配置是需要指定的：&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>automationName：使用哪种自动化引擎。appium（默认）还是Selendroid？&lt;/li>
&lt;li>platformName：使用哪种移动平台。iOS, Android, orFirefoxOS？&lt;/li>
&lt;li>deviceName：启动哪种设备，是真机还是模拟器？iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4, etc&amp;hellip;&lt;/li>
&lt;li>app：应用的绝对路径，注意一定是绝对路径。如果指定了appPackage和appActivity的话，这个属性是可以不设置的。另外这个属性和browserName属性是冲突的。&lt;/li>
&lt;li>browserName：移动浏览器的名称。比如Safari&amp;rsquo; for iOS and &amp;lsquo;Chrome&amp;rsquo;, &amp;lsquo;Chromium&amp;rsquo;, or &amp;lsquo;Browser&amp;rsquo; for Android；与app属性互斥。&lt;/li>
&lt;li>udid：物理机的id。比如1ae203187fc012g。&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>下面这些属性是android平台特定的：&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>appActivity：待测试的app的Activity名字。比如MainActivity, .Settings。注意，原生app的话要在activity前加个&amp;quot;.&amp;quot;。&lt;/li>
&lt;li>appPackage：待测试的app的java package。比如com.example.android.myApp, com.android.settings。&lt;/li>
&lt;/ul>
&lt;p>本文主要讨论android平台的appium测试方法和技巧，因此在这里就不列出ios设备特定的属性了。&lt;/p>
&lt;p>更多信息请参考&lt;a href="https://github.com/appium/appium/blob/master/docs/en/caps.md" target="_blank" rel="noopener noreffer ">官方文档&lt;/a>&lt;/p>
&lt;p>在这里我们发现，我们经常要获取app的package和activity名字，那么有什么工具可以让我们方便的获取到这些信息呢？下一节讲回答这个问题。&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1447433553548-2fc162393482?w=300"
 data-srcset="https://images.unsplash.com/photo-1447433553548-2fc162393482?w=300, https://images.unsplash.com/photo-1447433553548-2fc162393482?w=300 1.5x, https://images.unsplash.com/photo-1447433553548-2fc162393482?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1447433553548-2fc162393482?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium新手入门（8）—— 定位控件</title><link>https://itest2025.pages.dev/tutorials/21-008-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A88-%E5%AE%9A%E4%BD%8D%E6%8E%A7%E4%BB%B6/</link><pubDate>Thu, 07 Sep 2017 10:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-008-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A88-%E5%AE%9A%E4%BD%8D%E6%8E%A7%E4%BB%B6/</guid><description>&lt;p>appium 通过 uiautomatorviewer.bat 工具来查看控件的属性。该工具位于 &lt;a href="https://itest2025.pages.dev/appium/appium-base-sdk/" rel="">Android SDK&lt;/a> 的 &lt;strong>/tools/bin/&lt;/strong> 目录下。&lt;/p>
&lt;h4 id="id-定位">id 定位&lt;/h4>
&lt;hr>
&lt;p>通过uiautomatorviewer.bat 工具可以查看对象的id属性。&lt;/p>
&lt;p>如果目标设备的API Level低于18则UIAutomatorViewer不能获得对应的Resource ID，只有等于大于18的时候才能使用。&lt;/p>
&lt;p>打开uiautomatorviewer.bat工具：&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_find_element_id.png"
 data-srcset="http://img.testclass.net/appium_find_element_id.png, http://img.testclass.net/appium_find_element_id.png 1.5x, http://img.testclass.net/appium_find_element_id.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_find_element_id.png"
 title="http://img.testclass.net/appium_find_element_id.png" />&lt;/p>
&lt;p>resource-id 就是我们理解的id属性了。&lt;/p>
&lt;p>&lt;em>&lt;strong>使用方法：&lt;/strong>&lt;/em>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findElement&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">By&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;com.android.calculator2:id/formula&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="name-定位">name 定位&lt;/h4>
&lt;hr>
&lt;p>打开uiautomatorviewer.bat工具：&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_find_element_class.png"
 data-srcset="http://img.testclass.net/appium_find_element_class.png, http://img.testclass.net/appium_find_element_class.png 1.5x, http://img.testclass.net/appium_find_element_class.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_find_element_class.png"
 title="http://img.testclass.net/appium_find_element_class.png" />&lt;/p>
&lt;p>text就是我们要查找的name了，为什么在命名上毫无关联啊！&lt;/p>
&lt;p>&lt;em>&lt;strong>使用方法：&lt;/strong>&lt;/em>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findElement&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">By&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">name&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;9&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="class-name-定位">class name 定位&lt;/h3>
&lt;hr>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://img.testclass.net/appium_find_element_class_name.png"
 data-srcset="http://img.testclass.net/appium_find_element_class_name.png, http://img.testclass.net/appium_find_element_class_name.png 1.5x, http://img.testclass.net/appium_find_element_class_name.png 2x"
 data-sizes="auto"
 alt="http://img.testclass.net/appium_find_element_class_name.png"
 title="http://img.testclass.net/appium_find_element_class_name.png" />&lt;/p>
&lt;p>计算器界面上的的class属性是：android.widget.Button。
&lt;em>&lt;strong>使用方法：&lt;/strong>&lt;/em>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">WebElement&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">button&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findElement&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">By&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">className&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;android.widget.Button&amp;#34;&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>使用 Class Name 一般获得的 view 都不止一个，所以应该需要遍历一遍得到的 views，然后缩小搜索条件来获得目标控件。&lt;/p>
&lt;h4 id="xpath定位">XPath定位&lt;/h4>
&lt;hr>
&lt;p>在 WebDriver 上 XPath 定位是功能强大的一种定位方式。我个人惯用于此方法来定位Web页面上的元素。下面看看在 Android 上 XPath 定位的用法。&lt;/p></description></item><item><title>appium简明教程（8）——那些工具</title><link>https://itest2025.pages.dev/tutorials/21-008-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B8%E9%82%A3%E4%BA%9B%E5%B7%A5%E5%85%B7/</link><pubDate>Sun, 13 Aug 2017 08:07:13 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-008-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B8%E9%82%A3%E4%BA%9B%E5%B7%A5%E5%85%B7/</guid><description>&lt;p>正所谓工欲善其事必先利其器，对于appium实战android来说，下面的这些工具(以windows系统为例)是必须熟练使用的。&lt;/p>
&lt;p>&lt;strong>monitor.bat（hierarchyviewer.bat已经不赞成继续使用了）&lt;/strong>&lt;/p>
&lt;p>该文件位于your_andriod_sdk_path\tools下面。以乙醇的机器为例，其位于E:\adt-bundle-windows-x86-20131030\sdk\tools下。&lt;/p>
&lt;p>该工具可以帮我们找到android控件的content-description，为以后的find_element_by_accessibility_id 定位方法做参数使用。&lt;/p>
&lt;p>关于什么是content-description，可以参考&lt;a href="http://developer.android.com/training/accessibility/accessible-app.html" target="_blank" rel="noopener noreffer ">官方文档&lt;/a>。&lt;/p>
&lt;p>好，露个脸。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://oriphg3yh.bkt.clouddn.com/tool1.png"
 data-srcset="http://oriphg3yh.bkt.clouddn.com/tool1.png, http://oriphg3yh.bkt.clouddn.com/tool1.png 1.5x, http://oriphg3yh.bkt.clouddn.com/tool1.png 2x"
 data-sizes="auto"
 alt="http://oriphg3yh.bkt.clouddn.com/tool1.png"
 title="http://oriphg3yh.bkt.clouddn.com/tool1.png" />&lt;/p>
&lt;p>&lt;strong>uiautomatorviewer.bat&lt;/strong>&lt;/p>
&lt;p>该文件位于your_andriod_sdk_path\tools下面。以乙醇的机器为例，其位于E:\adt-bundle-windows-x86-20131030\sdk\tools下。&lt;/p>
&lt;p>该工具主要用来查看控件的属性，比如resource id，class name等。&lt;/p>
&lt;p>该工具也可查看被测app的appPackage（Desired Capabilities中使用）。&lt;/p>
&lt;p>爆照。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://oriphg3yh.bkt.clouddn.com/tool2.png"
 data-srcset="http://oriphg3yh.bkt.clouddn.com/tool2.png, http://oriphg3yh.bkt.clouddn.com/tool2.png 1.5x, http://oriphg3yh.bkt.clouddn.com/tool2.png 2x"
 data-sizes="auto"
 alt="http://oriphg3yh.bkt.clouddn.com/tool2.png"
 title="http://oriphg3yh.bkt.clouddn.com/tool2.png" />&lt;/p>
&lt;p>好了，是不是感觉还缺了点什么呢？&lt;/p>
&lt;p>确实如此，被测app的appActivity怎么获取呢？&lt;/p>
&lt;p>下一讲我们详细讲解如何获取被测app的appActivity。&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1589517628174-5698bcf47311?w=300"
 data-srcset="https://images.unsplash.com/photo-1589517628174-5698bcf47311?w=300, https://images.unsplash.com/photo-1589517628174-5698bcf47311?w=300 1.5x, https://images.unsplash.com/photo-1589517628174-5698bcf47311?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1589517628174-5698bcf47311?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium新手入门（9）—— appium API 之应用操作</title><link>https://itest2025.pages.dev/tutorials/21-009-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A89-appium-api-%E4%B9%8B%E5%BA%94%E7%94%A8%E6%93%8D%E4%BD%9C/</link><pubDate>Thu, 07 Sep 2017 10:24:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-009-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A89-appium-api-%E4%B9%8B%E5%BA%94%E7%94%A8%E6%93%8D%E4%BD%9C/</guid><description>&lt;p>本小节的所罗列的方法主要针对应用的操作，如应用的安装、卸载、关闭、启动等。&lt;/p>
&lt;h4 id="1安装应用">1、安装应用&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>installApp()&lt;/li>
&lt;/ul>
&lt;p>安装应用到设备中去。需要apk包的路径。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">installApp&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;path/to/my.apk&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">installApp&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;D:\\android\\apk\\ContactManager.apk&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="2卸载应用">2、卸载应用&lt;/h4>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>removeApp()&lt;/li>
&lt;/ul>
&lt;p>从设备中删除一个应用。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">removeApp&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;com.example.android.apis&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="3关闭应用">3、关闭应用&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>closeApp()&lt;/li>
&lt;/ul>
&lt;p>关闭打开的应用，默认关闭当前打开的应用，所以不需要入参。这个方法并非真正的关闭应用，相当于按home键将应用置于后台，可以通过launchApp()再次启动。&lt;/p>
&lt;h4 id="4启动应用">4、启动应用&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>launchApp()&lt;/li>
&lt;/ul>
&lt;p>启动应用。你一定很迷惑，不是在初始化的配置信息已经指定了应用，脚本运行的时候就需要启动应用，为什么还要有这个方法去启动应用呢？重新启动应用也是一个测试点，该方法需要配合closeApp()使用的。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">closeApp&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">launchApp&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="5检查应用是否安装">5、检查应用是否安装&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>isAppInstalled()&lt;/li>
&lt;/ul>
&lt;p>检查应用是否已经安装。需要传参应用包的名字。返回结果为Ture或False。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">isAppInstalled&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="n">com&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">example&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">android&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">apis&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="6将应用置于后台">6、将应用置于后台&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>runAppInBackground()&lt;/li>
&lt;/ul>
&lt;p>将当前活跃的应用程序发送到后台。这个方法需要入参，需要指定应用置于后台的时长。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">runAppInBackground&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">2&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="7应用重置">7、应用重置&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>resetApp()&lt;/li>
&lt;/ul>
&lt;p>重置当前被测程序到出始化状态。该方法不需要入参。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">resetApp&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1495490311930-678c8ecdd120?w=300"
 data-srcset="https://images.unsplash.com/photo-1495490311930-678c8ecdd120?w=300, https://images.unsplash.com/photo-1495490311930-678c8ecdd120?w=300 1.5x, https://images.unsplash.com/photo-1495490311930-678c8ecdd120?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1495490311930-678c8ecdd120?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium简明教程（9）——如何获取android app的Activity</title><link>https://itest2025.pages.dev/tutorials/21-009-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B9%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96android-app%E7%9A%84activity/</link><pubDate>Sat, 12 Aug 2017 08:11:31 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-009-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B9%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96android-app%E7%9A%84activity/</guid><description>&lt;p>有时候在appium的Desired Capabilities中需要指定被测app的appActivity，下面的方法可能会对你有所帮助。&lt;/p>
&lt;p>&lt;strong>方法一&lt;/strong>&lt;/p>
&lt;p>如有你有待测项目的源码，那么直接查看源码就好。如果没有，那么请联系有源码的同学，这是推荐方法。&lt;/p>
&lt;p>&lt;strong>方法二&lt;/strong>&lt;/p>
&lt;p>如果你没有代码，那么可以反编译该app。&lt;/p>
&lt;p>这里将用到2个工具，分别是dex2jar和jd-gui。你可以在这里下载目前为止的最新版本以及示例apk。&lt;/p>
&lt;p>我们以工具包里的ContactManager.apk为例，简单介绍一下反编译的流程。&lt;/p>
&lt;ul>
&lt;li>1，重命名ContactManager.apk为ContactManager.zip并解压得到文件classes.dex；&lt;/li>
&lt;li>2，解压dex2jar-0.0.9.15.zip，并从命令行进入该文件夹；&lt;/li>
&lt;li>3，运行命令&lt;/li>
&lt;/ul>
&lt;pre tabindex="0">&lt;code>d2j-dex2jar.bat path_to\classes.dex
在当前文件夹下得到classes-dex2jar.jar；
&lt;/code>&lt;/pre>&lt;ul>
&lt;li>4，解压jd-gui-0.3.6.windows.zip得到文件jd-gui.exe；&lt;/li>
&lt;li>5，使用jd-gui.exe打开classes-dex2jar.jar；&lt;/li>
&lt;/ul>
&lt;p>嗯，好了，可以尽情欣赏了。上图。&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="http://oriphg3yh.bkt.clouddn.com/get_activity.png"
 data-srcset="http://oriphg3yh.bkt.clouddn.com/get_activity.png, http://oriphg3yh.bkt.clouddn.com/get_activity.png 1.5x, http://oriphg3yh.bkt.clouddn.com/get_activity.png 2x"
 data-sizes="auto"
 alt="http://oriphg3yh.bkt.clouddn.com/get_activity.png"
 title="http://oriphg3yh.bkt.clouddn.com/get_activity.png" />&lt;/p>
&lt;p>上图所示的ContactManager就是待测app的main activity。&lt;/p>
&lt;p>&lt;strong>方法三&lt;/strong>&lt;/p>
&lt;p>参考testerhome的&lt;a href="http://testerhome.com/topics/1030" target="_blank" rel="noopener noreffer ">这个帖子&lt;/a>&lt;/p>
&lt;p>使用log查看大法(嗯，windows上没grep不幸福，好在有powershell的Select-String，可以拿来勉强一用)，直接搬砖。&lt;/p>
&lt;ul>
&lt;li>a、启动待测apk&lt;/li>
&lt;li>b、开启日志输出：adb logcat&amp;gt;D:/log.txt&lt;/li>
&lt;li>c、关闭日志输出：ctrl+c&lt;/li>
&lt;li>d、查看日志&lt;/li>
&lt;/ul>
&lt;p>找寻：&lt;/p>
&lt;pre tabindex="0">&lt;code>Displayed com.mm.android.hsy/.ui.LoginActivity: +3s859ms
appPackage = com.mm.android.hsy
appActivity = .ui.LoginActivity
&lt;/code>&lt;/pre>&lt;p>好了，准备活动做的差不多了。下一节乙醇带大家进行控件定位之旅。&lt;/p>
&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1566352207769-3a591a2c9567?w=300"
 data-srcset="https://images.unsplash.com/photo-1566352207769-3a591a2c9567?w=300, https://images.unsplash.com/photo-1566352207769-3a591a2c9567?w=300 1.5x, https://images.unsplash.com/photo-1566352207769-3a591a2c9567?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1566352207769-3a591a2c9567?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium新手入门（10）—— appium API 之上下文操作</title><link>https://itest2025.pages.dev/tutorials/21-010-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A810-appium-api-%E4%B9%8B%E4%B8%8A%E4%B8%8B%E6%96%87%E6%93%8D%E4%BD%9C/</link><pubDate>Thu, 07 Sep 2017 10:22:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-010-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A810-appium-api-%E4%B9%8B%E4%B8%8A%E4%B8%8B%E6%96%87%E6%93%8D%E4%BD%9C/</guid><description>&lt;p>其实上下文的操作主要针对于混合应用。啥是混合应用，简单来说就是APP用里面嵌入网页。Android上的浏览器就属于混合应用。&lt;/p>
&lt;h4 id="1获取当前上下文">1、获取当前上下文&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>getContext()&lt;/li>
&lt;/ul>
&lt;p>获取当前所有的可用的上下文。该方法不需要入参。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ct&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getContext&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">System&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">out&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">println&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ct&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-----------&lt;/span>&lt;span class="n">计算器应用的打印结果&lt;/span>&lt;span class="o">-----------------------&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">NATIVE_APP&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="2当前所有上下文句柄">2、当前所有上下文句柄&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>getContextHandles()&lt;/li>
&lt;/ul>
&lt;p>获取当前所有可用的上下文。该方法不需要入参。&lt;/p>
&lt;h4 id="3切换上下文">3、切换上下文&lt;/h4>
&lt;hr>
&lt;ul>
&lt;li>context()&lt;/li>
&lt;/ul>
&lt;p>切换到特定的上下文中。需要指定上下文的名称。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">context&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="n">NATIVE_APP&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">context&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="n">WEBVIEW_1&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>原始封面&lt;/p>
&lt;p>&lt;img
 class="lazyload"
 src="https://itest2025.pages.dev/svg/loading.min.svg"
 data-src="https://images.unsplash.com/photo-1505312926838-645f295a20e1?w=300"
 data-srcset="https://images.unsplash.com/photo-1505312926838-645f295a20e1?w=300, https://images.unsplash.com/photo-1505312926838-645f295a20e1?w=300 1.5x, https://images.unsplash.com/photo-1505312926838-645f295a20e1?w=300 2x"
 data-sizes="auto"
 alt="https://images.unsplash.com/photo-1505312926838-645f295a20e1?w=300"
 title="课程图片" />&lt;/p></description></item><item><title>appium简明教程（10）——控件定位基础</title><link>https://itest2025.pages.dev/tutorials/21-010-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B10%E6%8E%A7%E4%BB%B6%E5%AE%9A%E4%BD%8D%E5%9F%BA%E7%A1%80/</link><pubDate>Fri, 11 Aug 2017 08:40:32 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-010-appium%E7%AE%80%E6%98%8E%E6%95%99%E7%A8%8B10%E6%8E%A7%E4%BB%B6%E5%AE%9A%E4%BD%8D%E5%9F%BA%E7%A1%80/</guid><description>&lt;p>狭义上讲，UI级的自动化测试就是让机器代替人去点来点去的过程。&lt;/p>
&lt;p>但机器去点什么（点上面还是点左边），怎么点（是长按还是轻触），这些东西是必须由代码的编写者所指示清楚的。&lt;/p>
&lt;p>控件定位就是解决机器点什么的问题的。&lt;/p>
&lt;p>一般说来，我们可以这样告诉机器：去点登陆按钮。&lt;/p>
&lt;p>机器很笨，它并不知道什么是登陆按钮。因为登陆按钮是自然语言的描述。&lt;/p>
&lt;p>如果你让一个人去点登陆按钮，那么他其实也是要经过一系列的脑补以后才可以做这件事的。&lt;/p>
&lt;p>这个脑补的过程还原如下：&lt;/p>
&lt;pre tabindex="0">&lt;code>这个一定是个按钮

这个按钮一定在被测的应用上

这个按钮大概上面有登陆这个文字信息

嗯，还真有一个，那么点吧。
&lt;/code>&lt;/pre>&lt;p>这就是人探索性测试的一个简单过程。一般来说，如果你给出的信息不太充分，人类还是可以通过一系列的探索性思维去理解你的描述的。这个属于心理学的问题，不展开解释。&lt;/p>
&lt;p>但是机器并不是人，如果你给出的描述不精确的话，机器是不会自发性的进行探索和脑补的。&lt;/p>
&lt;p>因此控件定位就是精确的描述控件特征并告诉机器的过程。&lt;/p>
&lt;p>本文版权归乙醇所有，欢迎转载，但请注明作者与出处，严禁用于任何商业用途&lt;/p>
&lt;p>控件的特征就是控件的属性，我们可以通过上一讲中的uiautomatorviewer去获取。&lt;/p>
&lt;p>在appium的定位世界里，下面这些方法是可以为我们使用的。也就是说，我们通过下面几个约定好的方式，按照webdriver和appium的DSL（自行搜索并理解）进行控件特征的描述和定位。&lt;/p>
&lt;p>继承自webdriver的方法，也就是通过这3个特征可以定位控件&lt;/p>
&lt;ul>
&lt;li>find by &amp;ldquo;class&amp;rdquo; (i.e., ui component type，andorid上可以是android.widget.TextView)&lt;/li>
&lt;li>find by &amp;ldquo;xpath&amp;rdquo; (i.e., an abstract representation of a path to an element, with certain constraints，由于appium的xpath库不完备的原因，这个不太推荐)&lt;/li>
&lt;li>find by &amp;ldquo;id&amp;rdquo;(android上是控件的resource id)&lt;/li>
&lt;/ul>
&lt;p>由&lt;a href="https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile" target="_blank" rel="noopener noreffer ">Mobile JSON Wire Protocol&lt;/a> 协议中定义的方法，更适合移动设备上的控件定位&lt;/p>
&lt;ul>
&lt;li>-ios uiautomation: a string corresponding to a recursive element search using the UIAutomation library (iOS-only)&lt;/li>
&lt;li>-android uiautomator: a string corresponding to a recursive element search using the UiAutomator Api (Android-only)&lt;/li>
&lt;li>accessibility id: a string corresponding to a recursive element search using the Id/Name that the native Accessibility options utilize.&lt;/li>
&lt;/ul>
&lt;p>在appium 的client对&lt;a href="https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile" target="_blank" rel="noopener noreffer ">Mobile JSON Wire Protocol&lt;/a>中定义的方法进行了封装，使其调用起来更加方便&lt;/p></description></item><item><title>appium新手入门（11）—— appium API 之键盘操作</title><link>https://itest2025.pages.dev/tutorials/21-011-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A811-appium-api-%E4%B9%8B%E9%94%AE%E7%9B%98%E6%93%8D%E4%BD%9C/</link><pubDate>Thu, 07 Sep 2017 10:20:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-011-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A811-appium-api-%E4%B9%8B%E9%94%AE%E7%9B%98%E6%93%8D%E4%BD%9C/</guid><description>&lt;p>模拟键盘输入也是非常重要的操作。这一小节来介绍那些关于键盘的操作。&lt;/p>
&lt;h4 id="1sendkeys方法">1、sendKeys()方法&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>sendKeys()&lt;/li>
&lt;/ul>
&lt;p>用法：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findElements&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">By&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">name&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;Name&amp;#34;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="na">sendKeys&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;jack&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2presskeycode方法">2、pressKeyCode()方法&lt;/h3>
&lt;hr>
&lt;p>除此之外，appium扩展提供了pressKeyCode()方法。该方法Android特有。&lt;/p>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>pressKeyCode()&lt;/li>
&lt;/ul>
&lt;p>发送一个键码的操作。需要一个入参。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Java" data-lang="Java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">pressKeyCode&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">29&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 字母“a”&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>如果想点击Android的HOME键应该怎么实现的呢？如下&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">pressKeyCode&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">AndroidKeyCode&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">HOME&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;font color="blue">&lt;strong>下面提供Android keycode参考表：&lt;/strong>&lt;/font>&lt;/p>
&lt;p>&lt;strong>电话键&lt;/strong>&lt;/p>
&lt;p>KEYCODE_CALL 拨号键 5&lt;/p>
&lt;p>KEYCODE_ENDCALL 挂机键 6&lt;/p>
&lt;p>KEYCODE_HOME 按键Home 3&lt;/p>
&lt;p>KEYCODE_MENU 菜单键 82&lt;/p>
&lt;p>KEYCODE_BACK 返回键 4&lt;/p>
&lt;p>KEYCODE_SEARCH 搜索键 84&lt;/p>
&lt;p>KEYCODE_CAMERA 拍照键 27&lt;/p>
&lt;p>KEYCODE_FOCUS 拍照对焦键 80&lt;/p>
&lt;p>KEYCODE_POWER 电源键 26&lt;/p>
&lt;p>KEYCODE_NOTIFICATION 通知键 83&lt;/p>
&lt;p>KEYCODE_MUTE 话筒静音键 91&lt;/p>
&lt;p>KEYCODE_VOLUME_MUTE 扬声器静音键 164&lt;/p>
&lt;p>KEYCODE_VOLUME_UP 音量增加键 24&lt;/p>
&lt;p>KEYCODE_VOLUME_DOWN 音量减小键 25&lt;/p>
&lt;p>&lt;strong>控制键&lt;/strong>&lt;/p>
&lt;p>KEYCODE_ENTER 回车键 66&lt;/p>
&lt;p>KEYCODE_ESCAPE ESC键 111&lt;/p>
&lt;p>KEYCODE_DPAD_CENTER 导航键 确定键 23&lt;/p>
&lt;p>KEYCODE_DPAD_UP 导航键 向上 19&lt;/p></description></item><item><title>appium新手入门（12）—— appium API 之 TouchAction 操作</title><link>https://itest2025.pages.dev/tutorials/21-012-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A812-appium-api-%E4%B9%8B-touchaction-%E6%93%8D%E4%BD%9C/</link><pubDate>Thu, 07 Sep 2017 10:10:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-012-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A812-appium-api-%E4%B9%8B-touchaction-%E6%93%8D%E4%BD%9C/</guid><description>&lt;p>Appium的辅助类，主要针对手势操作，比如滑动、长按、拖动等。&lt;/p>
&lt;h4 id="1按压控件">1、按压控件&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>press()&lt;/li>
&lt;/ul>
&lt;p>开始按压一个元素或坐标点（x,y）。通过手指按压手机屏幕的某个位置。&lt;/p>
&lt;p>&lt;strong>press(WebElement el, int x, int y)&lt;/strong>&lt;/p>
&lt;p>press也可以接收屏幕的坐标（x,y）。&lt;/p>
&lt;p>例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">TouchAction&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">press&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">x&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">y&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">308&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">perform&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>除了press()方法之外，本例中还用到了别外两个新方法。&lt;/p>
&lt;ul>
&lt;li>
&lt;p>release()
结束的行动取消屏幕上的指针。&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Perform()
执行的操作发送到服务器的命令操作。&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h4 id="2长按控件">2、长按控件&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>longPress()&lt;/li>
&lt;/ul>
&lt;p>开始按压一个元素或坐标点（x,y）。
相比press()方法，longPress()多了一个入参，既然长按，得有按的时间吧。duration以毫秒为单位。1000表示按一秒钟。其用法与press()方法相同。&lt;/p>
&lt;p>&lt;strong>longPress(WebElement el, int x, int y, Duration duration)&lt;/strong>&lt;/p>
&lt;p>例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">TouchAction&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">action&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TouchAction&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">action&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">longPress&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">names&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="n">1000&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">perform&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">action&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">longPress&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">302&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">1000&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">perform&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="3点击控件">3、点击控件&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>tap()&lt;/li>
&lt;/ul>
&lt;p>对一个元素或控件执行点击操作。用法参考press()。&lt;/p>
&lt;p>&lt;strong>tap(WebElement el, int x, int y)&lt;/strong>&lt;/p>
&lt;p>例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">TouchAction&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">action&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TouchAction&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">action&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">tap&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">names&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="na">perform&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">action&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">tap&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">302&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">perform&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="4移动">4、移动&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>moveTo()&lt;/li>
&lt;/ul>
&lt;p>将指针（光标）从过去指向指定的元素或点。&lt;/p>
&lt;p>&lt;strong>movTo(WebElement el, int x, int y)&lt;/strong>&lt;/p></description></item><item><title>appium新手入门（13）—— appium API 之其他操作</title><link>https://itest2025.pages.dev/tutorials/21-013-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A813-appium-api-%E4%B9%8B%E5%85%B6%E4%BB%96%E6%93%8D%E4%BD%9C/</link><pubDate>Thu, 07 Sep 2017 10:01:12 +0800</pubDate><guid>https://itest2025.pages.dev/tutorials/21-013-appium%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A813-appium-api-%E4%B9%8B%E5%85%B6%E4%BB%96%E6%93%8D%E4%BD%9C/</guid><description>&lt;p>其它操作针对移动设备上特有的一些操作。&lt;/p>
&lt;h4 id="1熄屏">1、熄屏&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>lockDevice()&lt;/li>
&lt;/ul>
&lt;p>点击电源键熄灭屏幕。&lt;/p>
&lt;p>在iOS设备可以设置熄屏一段时间。Android上面不带参数，所以熄屏之后就不会再点亮屏幕了。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">lockDevice&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1000&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// iOS&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">lockDriice&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">//Android &lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="2当前activityandroid-only">2、当前Activity（Android only）&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>currentActivity()&lt;/li>
&lt;/ul>
&lt;p>得到当前应用的activity。只适用于Android。
例（通讯录）：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Java" data-lang="Java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ca&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">currentActivity&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">System&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">out&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ca&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-------------&lt;/span>&lt;span class="n">输出结果为&lt;/span>&lt;span class="o">-------------&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">activities&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">PeopleActivity&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3收起键盘">3、收起键盘&lt;/h3>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>hideKeyboard()&lt;/li>
&lt;/ul>
&lt;p>收起键盘，这个方法很有用，当我们对一个输入框输入完成后，需要将键盘收起，再切换到一下输入框进行输入。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Java" data-lang="Java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">hideKeyboard&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">//收起键盘&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="4滑动">4、滑动&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>swipe()&lt;/li>
&lt;/ul>
&lt;p>模拟用户滑动。将控件或元素从一个位置（x,y）拖动到另一个位置（x,y）。&lt;/p>
&lt;p>&lt;strong>swipe(int startx, int starty, int endx, int endy, int duration)&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>start_x：开始滑动的x坐标。&lt;/li>
&lt;li>start_y：开始滑动的y坐标。&lt;/li>
&lt;li>end_x：结束滑动的x坐标。&lt;/li>
&lt;li>end_y：结束滑动的y坐标。&lt;/li>
&lt;li>duration：持续时间。&lt;/li>
&lt;/ul>
&lt;p>例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Java" data-lang="Java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">swipe&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">75&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">500&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">75&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">800&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="5拉出文件">5、拉出文件&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>pullFile()&lt;/li>
&lt;/ul>
&lt;p>从设备中拉出文件。&lt;/p>
&lt;p>例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Java" data-lang="Java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">driver&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">pullFile&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="n">Library&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">AddressBook&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">AddressBook&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">sqlitedb&lt;/span>&lt;span class="err">&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="6推送文件">6、推送文件&lt;/h4>
&lt;hr>
&lt;p>方法：&lt;/p>
&lt;ul>
&lt;li>pushFile()&lt;/li>
&lt;/ul>
&lt;p>推送文件到设备中去。&lt;/p>
&lt;p>&lt;strong>pushFile(String remotePath, byte[] base64Data)&lt;/strong>&lt;/p></description></item></channel></rss>