Appium0.18.x遷移到Appium1.x須知事項(灰常有用,解答了本人幾個疑問),戶口遷移證本人
英文原版:https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/migrating-to-1-0.mdMigrating 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將不再使用:
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:
我們把以下的控制項尋找器策略給移除掉了:
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”。為了取得所有可用的上下文或者你的應用特有的上下文,請使用如下方式:
# pythondriver.contextscurrent = driver.context
// javascriptdriver.contexts().then(function (contexts) { /*...*/ })
// c#driver.GetContexts ()driver.GetContext ()
// javaSet<String> contextNames = driver.getContextHandles();String context = driver.getContext();
// php$contexts = $this->contexts();$context = $this->context();
# rubycontexts = available_contextscontext = current_context
And to switch between them, you use
請使用如下方式進行切換:
# pythondriver.switch_to.context("WEBVIEW")
// javascriptdriver.currentContext().then(function (context) { /*...*/ })
// c#driver.SetContext ("WEBVIEW");
javadriver.context(contextName);
// php$this->context('WEBVIEW');
# rubyset_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!
完!遷移快樂!