用一套方法論去設計許多方法來解決工程上遇到的問題。 即 "一生萬法、萬法圓通"。

Recent in Recipes

3/Food/post-list
顯示具有 uiautomator 標籤的文章。 顯示所有文章
顯示具有 uiautomator 標籤的文章。 顯示所有文章

Appium + Python for Android UI Automation

 Robotframework 也是透過 Appium的Service 完成的喔!

也許我們也可以考慮選擇Appium作為Mobile Testing的Solution


1. 安裝Appium (使用AppImage)

Initiate Global Config

Setup Session Connection

referring to:  [Day 26] 利用Appium測試Android App 


2. 安裝Python 套件

first

second


3. 設定Pycharm使用虛擬環境 virtualenv



4. 所以要先開啟 Appium Service



5. Execute the Python Code



6. Some other commercial reference

6-1. experitest

Appium Python Testing: The Complete Guide

6-2.BrowserStack

Run your first test







透過Appium 快速取得UI元件

 1. Launch Appium Server

2. click Inspection

3. Set Connection Capabilities with DUT

4. Start to see the UI



沒有App Main 的 AndroidTest~ uiauto2

沒有要測試的對象App

完全從首頁Home啟動Test Case



我們關注這三個檔案:

1. 測試程式主檔

2.測試程式屬性檔

3.編譯工具配置檔



Android Studio 專案版本移植 (舊版移植到新版)

 有關Gradle版本的說明可以先參考這裡


從專案目錄夾打看會看到如下架構




再來重點就是修改下面三個檔案 (時否符合最新API的封裝/格式/版號)



舉個例子,用diff 就可以了解其間的差異了
  1. build.gradle

  1. app/build.gradle

  1. gradle-wrapper.property


再來就是透過IDE來移植新版本的套件

  1. migrate to AndroidX



從命令列啟動uiautomator

從命令列啟動uiautomator

事先用AS先把測試代碼寫好,編成apk,然後安裝到手機上。

接下來可以透過command line啟動,有兩種方法

referring to: https://developer.android.com/studio/test/command-line

referring to: https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner

1.用gradlew

./gradlew connectedAndroidTest
./gradlew cAT

2.用adb

 $ adb shell am instrument -w <test_package_name>/<runner_class>

adb2 shell am instrument -w com.stlab.uiauto2.test/androidx.test.runner.AndroidJUnitRunner
adb2 shell am instrument -w  com.example.android.testing.uiautomator.BasicSample.test/androidx.test.runner.AndroidJUnitRunner
但是要事先把這些apk裝在手機裡面

比較一下 Google範例檔案的 AndroidManifest
這是IDE自動產生的Manifest, 不需要去改動他!
referring to:https://source.android.com/compatibility/tests/development/instrumentation



回歸 原創者 構思

 

https://github.com/xiaocong/uiautomator

https://github.com/openatx/uiautomator2

Python 封裝的 uiautomator 源碼學習

原生 Androidx Uiautomator API

 

Androidx Uiautomator API reference

舊版是 android.support.test.uiautomator 這點要特別注意自行轉換