顯示具有 Appium 標籤的文章。 顯示所有文章
顯示具有 Appium 標籤的文章。 顯示所有文章

2024-11-14

Appium iOS - 你確定 build 了 simulator 可以執行的 app,但還是一直噴錯怎辦?要不要用一下 bundleId?

事情是這樣的,我和開發拿到了可以給 simulator 執行的 .app 檔案。
直接拖曳 app 丟到 simulator 裡它可以順順打開、可以妥妥操作。

但是當我用 Appium 以這個 capability 開 app 就出4了:
  "appium:deviceName": "iPhone 15 Pro",
  "appium:automationName": "XCUITest",
  "platformName": "iOS",
  "appium:platformVersion": "17.5",
  "appium:app": "/Users/username/Desktop/folder/Demo.app" 
}

會遇到錯誤: Failed to create session. An unknown server-side error occurred while processing the command. Original error: The com.testdomain.test-demo-ios.dev application does not support the x86_64 Simulator architecture: Non-fat file: /Users/username/Desktop/folder/Demo.app/Demo is architecture: arm64 Please rebuild your application to support the x86_64 platform. 

為什麼?為什麼???直接裝也可跑啊?人家真的就有 support x86_64 啊。
我問天——我問天——甘會當莫創治—— 

然後啊,在我跟開發確認了幾次,很怕被揍的時候,我才想到我先在 simulator 安裝好就可以用 bundleId 開啟嘛:
  "appium:deviceName": "iPhone 15 Pro",
  "appium:automationName": "XCUITest", 
  "platformName": "iOS",
  "appium:platformVersion": "17.5", 
  "appium:bundleId": "com.testdomain.test-demo-ios.dev"
}

太好了,太好了!
流程上不同的大概只有要先指令裝 app,需要的話加個 reset capability。

2024-11-11

Appium Android 起手式 - 取得 appPackage 和 appActivity

在使用 Appium 進行 Android 自動化測試時,appPackage 和 appActivity 是必要的參數。

取得方式很多,記錄一下我習慣用的方法:
adb shell dumpsys window | grep -E "mCurrentFocus"
確定已經連到了 Android 裝置,並開啟 app,輸入上面的指令。

回傳的結果會是目前開啟的 app 和 app 頁面,如:appPackage/appActivity 的格式的資訊。

實際例子,開啟 Chrome app 之後: mCurrentFocus=Window{1c35821 u0 com.android.chrome/com.google.android.apps.chrome.Main} appPackage 是 com.android.chrome,appActivity 是 com.google.android.apps.chrome.Main。
-
要注意的是,appActivity 是能進 app 的第一個畫面,有些 app 開啟時可能閃現一下就跳到下一個畫面。沒有找到正確的可能會有類似以下的錯誤:
exited with code 255'; Command output: Exception occurred while executing 'start': java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000
這種時候可以拼手速,在一開啟載入閃現那個第一個畫面就趕快 enter 指令,但也可以用 Android Studio 或其他編輯器打開 apk 檔的 AndroidMainfest.xml,找到含有 android.intent.action.MAIN 的 Activity。
實際例子,有個 Activity 有這樣的內容 :
<activity
    android:name="com.example.app.loading.LoadingActivity"
    android:exported="true"
    android:screenOrientation="1"
    android:hardwareAccelerated="false">

    <intent-filter>
        <action
            android:name="android.intent.action.MAIN" />
        <category
            android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>
那就是這個 Activity 了!

2024-11-06

Appium 2.0 錯誤 Could not find a driver for automationName 'xxxxxx' and platformName 'xxxxxx'

剛升到 Appium 2.0 執行以前的 code 可能會遇到錯誤:
could not find a driver for automationname 'uiautomator2' and platformname 'android'

因為 Appium 2.0 版本開始,driver(例如 uiautomator2、xcuitest 等)都變成獨立的套件,需要單獨安裝。

安裝:
appium driver install uiautomator2 

確認安裝了哪些 driver:
appium driver list 

會顯示你目前裝了什麼和沒裝什麼:
✔ Listing available drivers
- uiautomator2@3.8.1 [installed (npm)]
- xcuitest [not installed]
- espresso [not installed]
- mac2 [not installed]
- windows [not installed]
- safari [not installed]
- gecko [not installed]
- chromium [not installed]

裝自己要用到的就好! 

另外 appium driver list 有參數可以只看有裝的 driver:
appium driver list --installed

會顯示: 
✔ Listing installed drivers 
- uiautomator2@3.8.1 [installed (npm)] 

裝完之後,如果你原本有跑 appium server,記得重開才會生效~

2019-12-24

Appium xpath 顯示的小坑

用 Appium Desktop 抓 xpath 會遇到一些顯示上的小問題。

目前遇過幾種類型:
1.文字換行會被去掉
在 Appium 上顯示的 xpath:
//XCUIElementTypeOther[@name="20% off $4,100")]
卻怎麼樣都沒辦法抓到。
dump xml 才發現,原來文字間有換行:
//XCUIElementTypeOther[@name="20%
off $4,100")]


2.文字首尾空白會被去掉
在 Appium 上顯示成這樣的text:
$530,000
怎麼又沒辦法抓到?
dump xml 才發現,原來文字前端(尾端)有空白:
$530,000

3.不換行空白會顯示為空白
這邊太無奈就不放範例了,放一下不換行空白 wiki