【新人】appium使用過程中的踩坑集
1. nodejs 版本不比對問題
錯誤:
error: uncaughtException: Cannot find module ‘internal/fs’ date=Thu May 17 2018 20:39:28 GMT+0800 (中國标準時間), pid=8620, uid=null, gid=null, cwd=D:\appium\node_modules\appium, execPath=C:\Program Files\nodejs\node.exe, version=v10.0.3, argv=[C:\Program Files\nodejs\node.exe
解決方案:
nodejs和appium版本不比對
appium的版本為1.4.16,對應的nodejs的版本是6.9.4
卸了nodejs重新裝一個 v 6.9.4
2. 端口拒絕通路
錯誤:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=4725): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x00000248683A6FD0>: Failed to establish a new connection: [WinError 10061] 由于目标計算機積極拒絕,無法連接配接。’,))
解決方案:
端口拒絕通路,原因可能有:
1) 端口被占用(找到端口被占用的程序,如果是殘留程序則選擇直接關閉;或者可以選擇更換其他端口)
檢視目前端口被什麼程序占用的方法有很多,就不在這裡介紹了
2) 端口服務未開啟(未開啟appium服務,或者開啟appium服務的端口和通路的端口不一緻)
appium用戶端:

腳本代碼:
檢查這兩者設定和通路的端口是否一緻
3.Original error: Could not extract PIDs from ps output.
錯誤:
selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created.
(Original error: Could not extract PIDs from ps output. PIDS: [], Procs: [“bad pid ‘uiautomator’”])
解決方案:
修改Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js檔案
var procs = [];
var outlines = stdout.split("\n");
// 添加下面這行
outlines.shift()
4.appium 運作時向手機安裝的兩個apk
分析:
Appium settings 用于設定網絡狀态
Unclock 用于自動解鎖,在手機是滑動鎖屏的情況下,則會自動解鎖并啟動apk,注意:圖案鎖屏與數字鎖不可以自動解鎖,隻能是滑動鎖屏
解決方案:
修改Appium\node_modules\appium\lib\devices\android\android.js檔案
Android.prototype.start = function (cb, onDie) {
······
this.pushAppium.bind(this),
this.initUnicode.bind(this),
//this.pushSettingsApp.bind(this), 手動注釋此2行代碼,即可解決問題
//this.pushUnlock.bind(this),
function (cb) {this.uiautomator.start(cb);}.bind(this),
······
5. 找不到apk
錯誤:
selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created. (Original error: Bad app: C:\Users\xxx\Downloads\com.tencent.mobileqq.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\Users\xxx\Downloads\com.tencent.mobileqq.apk’)
解決方案:
原因 可能是路徑錯了
如果路徑正确的情況下,添加如下代碼:
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
desired_caps['app'] = PATH('×××(最好是相對路徑,本人使用絕對路徑失敗了)/com.tencent.mobileqq.apk')
6. 缺少appActivity的參數
錯誤:
selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created. (Original error: Parameter ‘appActivity’ is required for launching application)
解決方案:
找到apk的appActivity(傳送門),然後再代碼中添加
7. Requested a new session but one was in progress
錯誤:
selenium.common.exceptions.SessionNotCreatedException: Message: A new session could not be created. (Original error: Requested a new session but one was in progress)
解決方案:
在重新開啟測試腳本時,已經有一session在執行還未關閉
關閉appium的服務,重新開啟