Appium0.18.x迁移到Appium1.x须知事项(灰常有用,解答了本人几个疑问)

英文原版:https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/migrating-to-1-0.md

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

把你的测试从Appium版本0.18.x迁移至Appium1.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.

Appium1.0把一些陈旧无效的功能从老版本中踢走,如果你想把你的测试升级到基于Appium1.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.

你需要做得最重大的事情是用我们最新的Appium客户端库来取代掉原来在用的普通平凡的WebDriver客户端库,请查看Appium
client list
 来找到你在使用的对应开发语言的客户端版本。至于怎么下载和集成到你的代码的话里面各自有对应的页面做解答。

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

最终其实你需要做得事情大概如下(以Python为例):

from appium import webdriver

Instead of:

取代原来的:

from selenium import webdriver

New
desired capabilities

新的capabilities选项

The following capabilities are no longer used: 

以下的capabilities将不再使用:

  • device
  • version

Instead, use these capabilities:

以下的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.

之前的app这项capability保留不变,但该项现在专门用在非browser类型的app上面。如果你要测试的是基于Safari或Chrome等浏览器的应用,请使用标准的browserName这项capability。也就是说app和browserName都是专用的选项。

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.

同时我们也用骆驼命名法重新统一命名了我们的Appium Server的capabilities。比如说原来的app-package和app-wait-activity将改成appPackage和appWaitActivity。当然,鉴于我们能自动检测到Android应用的包和activity,所以你可以大多时候忽略掉这些选项了。

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.

我们现在引入了accessibility_id这个策略来取代原来name所做的事情(译者注:也就是说原来的AppiumDriver.findElementByName将会被现在的AppiumDriver.findElementByAccessibilityId取代)。当中细节将会根据你使用的Appium客户端(译者注:客户端语言)而有所不同。

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.

新的class name将会取代原来的tag name(译者注:也就说原来的findElementByTagName将会被想在的findElementByClassName取代),所以如果你要根据一个控件的UI类型来查找出该控件,请使用class name这个控件查找器。

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:

注意class name和xpath策略的变化:你现在需要使用FQCN来描述你的控件。也就是说如果你由一个xpath选择子如下所述:

//table/cell/button

It would now need to be:

那么现在要改为(译者注:也就是说原来的findElementByXpath(""//TextView[contains(@text,‘Add note‘)]"")将需要改成findElementByXpath("//android.widget.TextView[contains(@text,‘Add note‘)]"):

//UIATableView/UIATableCell/UIAButton

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

(如此类推:button现在就要写成android.widget.Button)

We‘ve also added the following locator strategies:

同时我们也添加了如下的控件定位器策略(译者注:也就是说入Andoid增加了AppiumDriver.findElementByUiAutomator):

  • -ios uiautomation
  • -android uiautomator

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

请根据你使用的客户端(根据不同语言)库来确定如何使用新的控件定位器策略。

XML,
not JSON 

使用JSON取代XML

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.

取得当前窗口的源码(译者注:也就是AppiumDriver.getPageSource函数)返回的格式将从原来的JSON改成XML。所以如果你之前的代码有依赖分析控件源码的地方必须做相应的更新。

Hybrid
support through context, not window

混合应用通过context而非window进行支持

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

之前的混合应用是通过切换"windows"来获得支持的:

  • 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

如今Appium支持(跟切换上下文这个概念)更加概念一致的的“context”。为了取得所有可用的上下文或者你的应用特有的上下文,请使用如下方式:

# python
driver.contexts
current = driver.context
// javascript
driver.contexts().then(function (contexts) { /*...*/ })
// c#
driver.GetContexts ()
driver.GetContext ()
// java
Set<String> contextNames = driver.getContextHandles();
String context = driver.getContext();
// php
$contexts = $this->contexts();
$context = $this->context();
# ruby
contexts = available_contexts
context = current_context

And to switch between them, you use

请使用如下方式进行切换:

# python
driver.switch_to.context("WEBVIEW")
// javascript
driver.currentContext().then(function (context) { /*...*/ })
// c#
driver.SetContext ("WEBVIEW");
java
driver.context(contextName);
// php
$this->context(‘WEBVIEW‘);
# ruby
set_context "WEBVIEW"

No
more execute_script("mobile: xxx")

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 likedriver.lock(5) (where lock has
been turned into a native client method). Of course, the details on calling these methods will differ by client.

所有”mobile:”相关的方法讲都会被剔除掉,并且被Appium客户端库的原生方法给替代掉。例如原来的driver.execute("mobile:lock",[5])将会被现在的driver.lock(5)所取代(这里lock这个功能已经成为了原生的客户方法了)。当然,具体的调用方法将会根据你所使用的不同的客户端库而有所不同了。

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.

需要特别声明的是,手势操作相关的方法将会被新的TouchAction/MultiAction API所替代,把这些手势操作集合在一起将会使得你的手势操作相关的自动化更强大和通俗易懂。更详细的TouchAction/MultiAction的使用请查看你的的Appium客户端。

And that‘s it! Happy migrating!

完!迁移快乐!

时间: 2024-08-10 15:09:01

Appium0.18.x迁移到Appium1.x须知事项(灰常有用,解答了本人几个疑问)的相关文章

Appium0.18.x迁移到Appium1.x须知事项(灰常实用,解答了本人几个疑问)

英文原版:https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/migrating-to-1-0.md Migrating your tests from Appium 0.18.x to Appium 1.x 把你的測试从Appium版本号0.18.x迁移至Appium1.x版本号 Appium 1.0 has removed a number of deprecated features from the

网站迁移时有哪些需要注意事项

以前使用传统物理服务器的企业,在进行服务器升级的时候,选择了性能更好的云服务器.那么在做服务器迁移的时候,有哪些是需要我们注意的地方呢?和宵云一起来看看吧. 网站迁移到云服务器需要做哪些测试准备? 1.功能测试 这包括软件即服务(SaaS)和云服务器的管理功能,以及针对性能问题测试端到端应用程序.一旦将所有数据和遗留应用程序移动到新环境,就应该进行这些测试. 2.可伸缩性和性能测试 迁移到云服务器的关键优势之一是它支持扩展的能力.企业必须确保其系统和应用程序按预期进行扩展.可伸缩性和性能测试包括

将数据从MySQL迁移到Oracle的注意事项

1.自动增长的数据类型处理MYSQL有自动增长的数据类型,插入记录时不用操作此字段,会自动获得数据值.ORACLE没有自动增长的数据类型,需要建立一个自动增长的序列号,插入记录时要把序列号的下一个值赋于此字段.CREATE SEQUENCE 序列号的名称 (最好是表名+序列号标记)INCREMENT BY 1 START WITH 1 MAXVALUE 99999 CYCLE NOCACHE;INSERT 语句插入这个字段值为: 序列号的名称.NEXTVAL 2. 单引号的处理MYSQL里可以用

Xamarin迁移到 Unified API 注意事项

参考官方文档: Migrating to Unified API for Components #if __UNIFIED__ ... // Mappings Unified CoreGraphic classes to MonoTouch classes using RectangleF = global::CoreGraphics.CGRect; using SizeF = global::CoreGraphics.CGSize; using PointF = global::CoreGra

TP框架中用tp模版迁移smarty模版的注意事项

ThinkPHP使用Smarty模板引擎的流程及注意事项在多人合作的项目中,Smarty模板使用的最多,具体原因百度. 而ThinkPHP中默认使用的模板是Think自己的模板,这就需要修改默认的模板引擎变量. 步骤如下: ①在config.php中定义如下配置项 'TMPL_ENGINE_TYPE'=>'Smarty',②上一步已经切换了模板引擎,css样式如果有{},需要使用{literal}标签禁止smarty解析,使用{literal}{/literal}标签包含起来. ③如果业内css

Appium基于安卓的各种FindElement的控件定位方法实践和建议

AppiumDriver的各种findElement方法的尝试,尝试的目标应用是SDK自带的Notepad应用. 1. findElementByName 1.1 示例 el = driver.findElementByName("Add note"); assertThat(el.getText(),equalTo("Add note")); 1.2 如何获得Name 安卓设备没有找到适合的方法,尝试用Appium Inspector,但是使用了当前最新的&quo

Appium基于安卓的各种FindElement的控件定位

转自:http://www.2cto.com/kf/201410/340345.html 1. findElementByName 1.1 示例 ? 1 2 el = driver.findElementByName("Add note"); assertThat(el.getText(),equalTo("Add note")); 1.2 如何获得Name 安卓设备没有找到适合的方法,尝试用Appium Inspector,但是使用了当前最新的“AppiumFor

【转】Appium基于安卓的各种FindElement的控件定位方法实践

原文地址:http://blog.csdn.net/zhubaitian/article/details/39754041#t11 AppiumDriver的各种findElement方法的尝试,尝试的目标应用是SDK自带的Notepad应用. 1. findElementByName 1.1 示例 [java] view plaincopy el = driver.findElementByName("Add note"); assertThat(el.getText(),equal

appium 控件定位

转自:http://www.2cto.com/kf/201410/340345.html AppiumDriver的各种findElement方法的尝试,尝试的目标应用是SDK自带的Notepad应用. 1. findElementByName 1.1 示例 ? 1 2 el = driver.findElementByName("Add note"); assertThat(el.getText(),equalTo("Add note")); 1.2 如何获得Na