appium 驱动 对应9.0 系统_以后做Appium自动化测试,再也不会踩这些坑了!
一、前言
APP的 webview 自動(dòng)化是依賴于 chromedriver 的,并且每個(gè)APP的 webview 版本號(hào)都不太一樣,這就導(dǎo)致了每次都需要重新去下載對(duì)應(yīng)的chromedriver 版本。如何根據(jù)當(dāng)前的 webdriver 版本去匹配對(duì)應(yīng) chromedriver 版本,這是一個(gè)難題。
根據(jù)官方文檔翻譯過來看,版本不匹配的話一般會(huì)報(bào)錯(cuò):
An unknown server-side error occurred while processing the command.
Original error: unknown error: Chrome version must be >= 55.0.2883.0
二、chromedriver啟動(dòng)
用chrome瀏覽器運(yùn)行自動(dòng)化測(cè)試用例時(shí),如果報(bào)這樣的錯(cuò)誤
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing value
可以這樣來解決:指定chromedriver.exe驅(qū)動(dòng)絕對(duì)路徑
driver = webdriver.Chrome(r'e:\xxx\chromedriver.exe')三、常遇錯(cuò)誤
我們?cè)谑褂胣ative和h5混合的應(yīng)用程序測(cè)試時(shí),可能會(huì)遇到報(bào)錯(cuò)
E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:1031:
UserWarning: name used for saved screenshot does not match file type. It should end with a `.png` extension。
"type. It should end with a `.png` extension", UserWarning)
..['NATIVE_APP', 'WEBVIEW_chrome', 'WEBVIEW_com.android.browser']
NATIVE_APP
Doctor my center Test Over.
E
=====================================================
ERROR: test_e_AboutContact (__main__.center)
----------------------------------------------------------------------
Traceback (most recent call last):
File "E:/ATS/TCyDoctorNew/test_case/test_dir/test_4doctormycenter.py", line 371, in test_e_AboutChengyiContact driver.switch_to.context('WEBVIEW_com.android.browser')
File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\appium\webdriver\switch_to.py", line 31, in context
self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})
File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response raise wde
File"E:\ProgramFiles(x86)\Python\Python37\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "E:\Program Files (x86)\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '55.0.2883'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details.
----------------------------------------------------------------------
Ran 3 tests in 66.001s
FAILED (errors=1)
Process finished with exit code 0
我們來看報(bào)錯(cuò)信息,第一個(gè)是warning,是指截圖的格式最好是png,這個(gè)與本文無關(guān)我們先忽略,關(guān)鍵看第二個(gè)錯(cuò)誤,它主要源于“No Chromedriver found that can automate Chrome '55.0.2883”,在appium日志里也能看到詳情
四、了解chromedriver
通過管理chromedriver, Appium支持安卓網(wǎng)頁(yè)和支持谷歌的混合app的自動(dòng)化。通過npm package安裝的總是綁定最新的chromedriver。
但是,每一版chromedriver的更新會(huì)支持最小的新增谷歌的版本,所以早期的版本不能再跟綁定的版本兼容。這時(shí)在appium server日志里會(huì)有類似的錯(cuò)誤:
An unknown server-side error occurred while processing the command.
Original error: unknown error: Chrome version must be >= 55.0.2883.0
為解決這個(gè)問題,appium可以通過加上:chromedriver_version屬性配置使用特定的chromedriver版本,比如
npm install appium –chromedriver_version="2.16"
或者在chromedriver_version環(huán)境變量指定版本,如
chromedriver_version=2.20 npm install appium
這也能得到最新的版本。最后,還可以被指定在運(yùn)行時(shí),通過 chromedriver-executable 服務(wù)器標(biāo)識(shí)與chromedriver執(zhí)行路徑手動(dòng)下載,比如
appium --chromedriver-executable /path/to/my/chromedriver
五、chromedriver/chrome兼容
下面是chromedriver與最小的chrome版本對(duì)應(yīng)表:
六、自動(dòng)查找匹配的chromedriver
從 Appium1.8.0開始,appium可以得到這個(gè)正確的基于chrome的chromedriver版本。當(dāng)appium發(fā)布時(shí),appium與chromedriver綁定,更多chromedriver版本可供下載到appium的安裝文件里(不建議這樣做,因?yàn)楦耡ppium時(shí)將會(huì)刪除它們)。
當(dāng)一個(gè)appium版本發(fā)布,最新的chromedriver版本可以被獲取,可以通過chromedriver與最小chrome版本映射關(guān)系,得到映射的絕對(duì)路徑文件。這個(gè)文件內(nèi)容必須做成json對(duì)象,例如
{
? "2.42": "63.0.3239",
? "2.41": "62.0.3202"
}
七、安裝網(wǎng)絡(luò)問題
當(dāng)appium安裝時(shí)需要下載chromedriver,所以會(huì)遇到安裝失敗的網(wǎng)絡(luò)問題。
默認(rèn)下chromedriver從https://chromedriver.storage.googleapis.com/ 獲取。使用chromedrivre的npm鏡像配置chromedriver_cdnurl。
npm install appium-chromedriver --chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver
或者在你的.npmrc文件增加屬性
chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver
另一種選擇是使用Path環(huán)境變量CHROMEDRIVER_CDNURL
CHROMEDRIVER_CDNURL=http://npm.taobao.org/mirrors/chromedriver npm install appium-chromedriver
在國(guó)內(nèi),可以用cnpm~
首先,安裝cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
輸入cnpm -v,顯示cnpm不是內(nèi)部或外部命令,也不是可運(yùn)行命令或批處理文件。
cnpm默認(rèn)會(huì)安裝在C:\Users\admin\AppData\Roaming\npm個(gè)人用戶路徑下。所以追溯到這個(gè)文件夾,在這里可以執(zhí)行cnpm ?v,因此推測(cè)沒有把cnpm路徑加入到path系統(tǒng)環(huán)境變量中。
添加到path后,再關(guān)閉打開cmd,執(zhí)行cnpm –v命令,
解決這個(gè)之后執(zhí)行安裝chromedriver
cnpm install -g appium --chromedriver_version="2.28" --chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver
推薦閱讀點(diǎn)擊閱讀?盤點(diǎn)!細(xì)數(shù)Appium+Pytest是如何實(shí)現(xiàn)App并發(fā)測(cè)試的?
點(diǎn)擊閱讀?Appium定位方法策略,好像還挺簡(jiǎn)單呢!
點(diǎn)擊閱讀?記一次搭建Appium自動(dòng)化測(cè)試環(huán)境的完整過程
點(diǎn)擊閱讀?開啟iOS Appium自動(dòng)化測(cè)試之門
點(diǎn)擊閱讀?Appium之與Jenkins集成發(fā)送測(cè)試報(bào)告
戳總結(jié)
以上是生活随笔為你收集整理的appium 驱动 对应9.0 系统_以后做Appium自动化测试,再也不会踩这些坑了!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 结束时间要大于开始时间_CPA考试结束,
- 下一篇: 按钮隐藏_Win10系统:如何隐藏登录界