Appium appium 迁移到 1.x 的指导文档

思寒_seveniruby · 2014年05月07日 · 最后由 先进 回复于 2014年05月15日 · 63 次阅读


  1. 使用了 appium 自己的客户端库替换传统的 webdriver 客户端库
  2. capabilities 的命名发生了改变
  3. 定位策略也进行了调整, 需要使用控件的全类名, 而不再是影射的 tag 名字了. 定位策略也去掉了 name 定位
  4. windows_handles 修改为 context 方法
  5. execute_script mobile 方法被移除, 目前支持正规的 api 了
  6. 增加了一个新的手势 api

Migrating your tests from Appium 0.18.x to Appium 1.x

Appium 1.0 has removed a number of deprecated features from the previous versions. This guide will help you know what needs to change in your test suite to take advantage of Appium 1.0.

New client libraries

The biggest thing you need to worry about is using the new Appium client libraries instead of the vanilla WebDriver clients you are currently using. Visit the Appium client list to find the client for your language. Downloads and instructions for integrating into your code are available on the individual client websites.

Ultimately, you'll be doing something like (to use Python as an example):

from appium import webdriver

Instead of:

from selenium import webdriver

New desired capabilities

The following capabilities are no longer used:

  • device
  • version

Instead, use these capabilities:

  • platformName (either "iOS" or "Android")
  • platformVersion (the mobile OS version you want)
  • deviceName (the kind of device you want, like "iPhone Simulator")
  • automationName ("Selendroid" if you want to use Selendroid, otherwise, this can be omitted)

The app capability remains the same, but now refers exclusively to non-browser apps. To use browsers like Safari or Chrome, use the standard browserName cap. This means that app and browserName are exclusive.

We have also standardized on camelCase for Appium server caps. That means caps like app-package or app-wait-activity are now appPackage and appWaitActivity respectively. Of course, since Android app package and activity are now auto-detected, you should be able to omit them entirely in most cases.

New locator strategies

We've removed the following locator strategies:

  • name
  • tag name

We have now added the accessibility_id strategy to do what name used to do. The specifics will be relative to your Appium client.

tag name has been replaced by class name. So to find an element by its UI type, use the class name locator strategy for your client.

Note about class name and xpath strategies: these now require the fully-qualified class name for your element. This means that if you had an xpath selector that looked like this:


It would now need to be:


(And likewise for Android: button now needs to be android.widget.Button)

We've also added the following locator strategies:

  • -ios uiautomation
  • -android uiautomator

Refer to your client for ways to use these new locator strategies.


App source methods, which previously returned JSON, now return XML, so if you have code that relies on parsing the app source, it will need to be updated.

Hybrid support through context, not window

Hybrid apps were previously supported by switching between "windows" using

  • window_handles
  • window
  • switch_to.window

Now Appium supports the more conceptually consistent concept of "context". To get all of the available contexts, or the particular context the application is is, you use

current = driver.context

And to switch between them, you use


No more execute_script("mobile: xxx")

All the mobile: methods have been removed, and have been replaced by native methods in the Appium client libraries. This means that a method call like driver.execute("mobile: lock", [5]) will now look something more like driver.lock(5) (where lock has been turned into a native client method). Of course, the details on calling these methods will differ by client.

Of particular note, the gesture methods have been replaced by the new TouchAction / MultiAction API which allows for a much more powerful and general way of putting gestural automation together. Refer to your Appium client for usage notes on TouchAction / MultiAction.

And that's it! Happy migrating!

共收到 12 条回复 时间 点赞

官方文档隐藏得太深了。。。前两天升了之后用例挂了一大片,找了半天没找到稳定看,果断退回 0.18



#3 楼 @xiaomayi0323 examplecode 都有,都在各自的 client 里,例如 java 的

有点不明白 1.0 版本的改进
期待中 能获取 token、webview 等方法 貌似都没有实现,有点郁闷

#5 楼 @tomdejia webview 的已经实现了, 只是修改了名字. 1.x 的主要目的是为了向标准靠拢.
appium1.x 是完全遵守 webdriver 的 jsonwp 协议标准的.

#6 楼 @seveniruby 嗯,我试了 context,可是完全不识别 webview。用 print driver.contexts 后只打印出 NATIVE_APP,没有 webview,但是在 0.18 的 selendroid 下是 webview 存在的。
而且我看了 webdriver 的协议后,就不理解为什么 1.0 的 method 返回值改为 XML 而舍弃了 JSON?


#7 楼 @tomdejia 那就有可能是 appium 的 bug 了, 你可以排查下. 改用 xml 是为了完整的 xpath 支撑, 跟协议标准无关.

#4 楼 @cjtcwyk 谢谢, 找到可用的测试例子.

#7 楼 @tomdejia
我遇见了和你一样的问题,尝试了几天,都没搞定,1.0 版本这里在 4.4 系统上,这个属性出来了。。在 4.3,4.2,4.1.2 都不行。。。

from selenium import webdriver
from appium import webdriver 两种方式有什么区别吗?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册