XTEST:
https://www.cnblogs.com/Test-xiaobai/p/9066331.html
APPIUM:
python摩拜:https://www.cnblogs.com/yoyoketang/p/9144987.html
java美團(tuán):https://testerhome.com/topics/7053
https://blog.csdn.net/windanchaos/article/details/70210341
https://testerhome.com/topics/14552
https://www.cnblogs.com/ai594ai/p/8615835.html
https://testerhome.com/topics/15479 近期
https://www.cnblogs.com/yyoba/p/9455519.html
https://mp.weixin.qq.com/s/U0jFiRsVsChHb8K9995QKQ
https://testerhome.com/topics/6954
AIRTEST:
https://testerhome.com/topics/14736
pocoui:
https://poco.readthedocs.io/en/latest/source/doc/poco-example/play_with_unittest_framework.html
https://poco-chinese.readthedocs.io/zh_CN/latest/source/doc/integration.html
調(diào)試騰訊tbs的webview:
http://www.reibang.com/p/e62e99050084
騰訊tbs文檔
https://x5.tencent.com/tbs/guide/debug/season7.html
http://bbs.mb.qq.com/thread-1945940-1-1.html
https://testerhome.com/topics/7112
appium測試混合應(yīng)用原理:http://appium.io/docs/cn/advanced-concepts/chromedriver/
chrome和chromedriver版本關(guān)系:
官網(wǎng)查看支持版本:http://chromedriver.chromium.org/downloads
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md
chromedriver下載:http://chromedriver.storage.googleapis.com/index.html
導(dǎo)入poco.drivers提示no module
原因是只裝了poco,沒有安裝pocoui酗电,安裝后解決
微信獲取contexts魄藕,只有app_native,沒有webview
微信打開debugx5.qq.com撵术,切換到信息背率,打開tbs調(diào)試模式
微信打開debugx5.qq.com,提示不是x5內(nèi)核
暫未解決
appium獲取微信小程序元素獲取問題嫩与。
只有find_element_by_accessibility_id有效寝姿,find_element_by_class_name無效。暫未解決划滋,可能需要切換到webveiw
切換微信webveiw時饵筑,chrome not reachable
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d1a6d9df13b1023338b6405fe87ac6be","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
可能原因是chromedriver版本與微信webveiw版本不一致?注意不是手機里chrome瀏覽器的版本古毛,是微信webview使用的chrome內(nèi)核版本翻翩。
如何查看微信webview版本
微信瀏覽器打開網(wǎng)頁,抓useragent稻薇,如User-Agent: Mozilla/5.0 (Linux; Android 6.0.1; vivo Y66 Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044207 Mobile Safari/537.36 MicroMessenger/6.7.2.1340(0x2607023A) NetType/WIFI Language/zh_CN
查看appium使用的chromedriver版本
查appium的日志嫂冻,有C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win,要替換的話塞椎,直接下載然后放到該目錄
chromedriver版本與微信webview已經(jīng)一致桨仿,還是報chrome not reachable
pc的chrome瀏覽器,輸入chrome:inspect案狠,已經(jīng)可以看到微信webview打開的頁面
關(guān)于chrone not reachable
https://github.com/appium/appium/issues/9469
https://github.com/appium/appium/issues?utf8=%E2%9C%93&q=reachable
https://stackoverflow.com/questions/48310994/cannot-set-context-to-webview
https://github.com/appium/appium/issues/8958
https://testerhome.com/topics/15479 重
https://testerhome.com/topics/16226
有的說是因為沒有設(shè)置Capabilities.SetCapability("chromeAndroidPackage", "app_package_name")導(dǎo)致服傍,但這個bug已經(jīng)修復(fù),而且我也加了骂铁。
https://github.com/appium/appium/issues/8032
https://github.com/appium/appium-android-driver/pull/243
同樣的環(huán)境吹零,換了一臺小米6,居然能切換成功了拉庵,無奈了灿椅。之前是vivo y66
切換到webview后報:unable to discover open pages
有說是options.add_experimental_option('androidProcess', 'com.tencent.mm:tools')這個設(shè)置不對,但未解決
https://github.com/appium/appium/issues/8032
有說得加--no-sandbox钞支,添加后解決問題茫蛹,但是仍然無法find element by class name
desired_caps = {
'platformName': 'android',
'deviceName': 'vivo Y66',
'appPackage': 'com.tencent.mm',
'appActivity': '.ui.LauncherUI',
'automationName': 'appium',
'unicodeKeyboard': True,
'resetKeyboard': True,
'noReset': True,
'newCommandTimeout': 600,
'chromeAndroidPackage': 'com.tencent.mm',
'recreateChromeDriverSessions': True,
'chromeOptions':
{'androidProcess': 'com.tencent.mm:tools',
'args': ['--no-sandbox']
}
}
遇到一種情況是微信沒有打開H5頁面也會報這個,當(dāng)我打開一個頁面的時候烁挟,一會就切換成功了
切換webview后仍然無法操作元素
不管是找什么元素婴洼,都找不到,看到driver有一個page_source接口撼嗓,返回如下:
driver=webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.contexts
['NATIVE_APP', 'WEBVIEW_com.tencent.mm:tools', 'WEBVIEW_com.tencent.mm:toolsmp']
>>>driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')
>>>driver.page_source()
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: 'str' object is not callable
>>>driver.page_source
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" ......
appium返回的response如下:
[debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/572ece24-a830-40f5-b684-2dfc3f067e28/source] to [GET http://127.0.0.1:8000/wd/hub/session/ed760fbb7208051a2fad2e9d299cd690/source] with body: {"sessionId":"572ece24-a830-40f5-b684-2dfc3f067e28"} [debug] [JSONWP Proxy]
Got response with status 200: "{\"sessionId\":\"ed760fbb7208051a2fad2e9d299cd690\",\"status\":0,\"value\":\"\\u003C!DOCTYPE html>\\u003Chtml xmlns=\\\"http://www.w3.org/1999/xhtml\\\" style=\\\"text-size-adjust: 100%;\\\">\\u003Chead>\\n \\u003Cscript type=\\\"text/javascript\\\">\\n var points = [];\\n points[0] = new Date().getTime();\\n var oldPoint = [];\\n oldPoint[0] = new Date().getTime();\\n \\u003C/script>\\n \\u003Cmeta charset=\\\"UTF-8\\\" />\\n \\u003Ctitle>搜一搜\\u003C/title>\\n \\u003Cmeta name=\\\"format-detection\\\" content=\\\"t
elephone=no\\\" />\\n \\u003Cmeta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\\\" />\\n \\u003Clink rel=\\\"stylesheet\\\" type=\\\"text/css\\\" href=\\\"dist/style.css?t=1535632682922\\\" />\\n\\u003C/head>\\n\\n\\u003Cbody id=\\\"body\\\" ontouchstart=\\\"\\\">\\n \\u003Cdiv id=\\\"search_test\\\" class=\\\"weui-cells\\\" style=\\\"display:none;margin:0;z-index: 99\\\">\\n
初步看里面的內(nèi)容柬采,看起像是一個網(wǎng)頁欢唾,之前用chrome inspct,看到過這個搜一搜警没,所以懷疑是切錯webview了匈辱,這個webveiw應(yīng)該是微信打開H5頁面時用的webview。如下圖所示:
>>>driver.get("http://m.baidu.com")
>>>driver.page_source
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class
確實能打開百度網(wǎng)頁杀迹,但就是在手機端看不到頁面
查看當(dāng)前窗口,然后切換押搪,發(fā)現(xiàn)切換是成功的树酪,只是不能在手機上顯示
>>>driver.window_handles
['CDwindow-56b52630-ffcc-4b1f-88cc-c26d4b5e10ed', 'CDwindow-3168289f-c448-4597-bf21-cf825fd29b5c', 'CDwindow-4a0d4647-27a5-4cfa-92a7-357ee6901c2a']
>>>driver.switch_to.window('CDwindow-3168289f-c448-4597-bf21-cf825fd29b5c')
>>>driver.current_window_handle
'CDwindow-3168289f-c448-4597-bf21-cf825fd29b5c'
>>>driver.title
'中國新說唱官方投票通道'
>>>driver.switch_to.window('CDwindow-4a0d4647-27a5-4cfa-92a7-357ee6901c2a')
>>>driver.title
''
>>>driver.switch_to_window('CDwindow-56b52630-ffcc-4b1f-88cc-c26d4b5e10ed')
>>>driver.title
'百度一下'
看了下,有的人獲取的context有很多大州,比如:
也許真的是微信更新后续语,無法獲取小程序的webview了
https://testerhome.com/topics/14770
另一提到更新導(dǎo)致無法切換的:
https://testerhome.com/topics/8990
于是去安智市場或豌豆莢下載了一個2017年1月6號版本6.5.3,安裝后厦画,利用chrome://inspect可以看到小程序相關(guān)的webview疮茄。再之前的版本不行,因為還沒有小程序入口根暑。
操作:
下載6.5.3安裝力试,打開debugx5.qq.com,提示不是x5排嫌,要安裝tbs內(nèi)核畸裳,點鏈接安裝,安裝后再打開(需要等一會e)淳地,切到信息欄怖糊,把inspect勾選。再重啟微信打開小程序颇象,發(fā)現(xiàn)chrome inspect成功伍伤,重啟微信很重要
在安智市場可以下載微信歷史版本
3月21日版本6.5.6,ok
3月30日版本6.5.7遣钳,ok
7月6日版本6.5.10扰魂,ok
9月30日版本6.5.16,ok
12月25版本6.6.0耍贾,ok
201803月6日6.6.5阅爽,ok
6月11日版本6.6.7,切換context報錯chrome not reach able荐开。將androidProcess換為com.tencent.mm:tools后可以切換成功付翁,但不是小程序的。chrome:inspect也失敗晃听。androidProcess如何確定百侧,見下面
4月11日版本6.6.6砰识,chrome:inspect失敗,報錯chrome not reach able
看來就是666版本開始的佣渴,我們搜索一下微信6.6.6版本的更新記錄日志辫狼。發(fā)現(xiàn)只有一條,可保留未編輯完的朋友圈...
再去看看小程序的更新日志
https://developers.weixin.qq.com/miniprogram/dev/framework/release.html
https://developers.weixin.qq.com/miniprogram/dev/framework/release/v1.html
也沒發(fā)現(xiàn)什么相關(guān)的辛润。
那目前就這樣了膨处,想要小程序的自動化,必須安裝6.6.5版本的微信砂竖。
點擊inspect后可以成功真椿,只不過是左邊沒有預(yù)覽畫面,后來發(fā)現(xiàn)高版本的6.6.0后能預(yù)覽了
然后再重新用appium跑乎澄,代碼如下:
from appium import webdriver
desired_caps = {
'platformName': 'android',
'deviceName': 'vivo Y66',
'appPackage': 'com.tencent.mm',
'appActivity': '.ui.LauncherUI',
'automationName': 'appium',
'unicodeKeyboard': True,
'resetKeyboard': True,
'noReset': True,
'newCommandTimeout': 600,
'chromeAndroidPackage': 'com.tencent.mm',
'recreateChromeDriverSessions': True,
'chromeOptions':
{'androidProcess': 'com.tencent.mm:appbrand0',
'args': ['--no-sandbox']
}
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.contexts # ['NATIVE_APP', 'WEBVIEW_com.tencent.mm:tools', 'WEBVIEW_com.tencent.mm:appbrand0']
print(driver.page_source)
driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')
總結(jié)幾點:
- androidProcess如何確定
$ adb shell
# 打開小程序突硝,然后輸入以下命令查看當(dāng)前活動的進(jìn)程號
shell@PD1621:/ $ dumpsys activity top|grep ACTIVITY
ACTIVITY com.tencent.mm/.plugin.appbrand.ui.AppBrandInToolsUI ad729c6 pid=28902
# 查看當(dāng)前進(jìn)程號的進(jìn)程信息,進(jìn)程名置济。
shell@PD1621:/ $ ps 28902
USER PID PPID VSIZE RSS WCHAN PC NAME
u0_a227 28902 669 1900832 246896 00000000 R com.tencent.mm:tools
shell@PD1621:/ $
這個值是哪個應(yīng)該是與打開方式有關(guān)解恰,比如從首頁下拉進(jìn)的小程序,一般是appbrand0浙于,從搜索的搜一搜入口進(jìn)的是toolsmp等护盈,也有時候是tools÷访模可能與第一次打開的時候操作順序有關(guān)黄琼。
6.6.5是tools,升級到6.7.3后是toolsmp(從搜一搜進(jìn)去)整慎,退出登錄后脏款,搜一搜入口也無法切webview了,只能升級到6.7.3才行裤园。不知道為什么撤师。
- 出來的兩個WEBVIEW,切換到哪個效果是一樣
進(jìn)展到這拧揽,以為離成功不遠(yuǎn)了剃盾,沒想到后面還是一堆的問題
無法找到對應(yīng)的元素,no such element
# 查找div貌似正常淤袜,但這個div元素是空的痒谴,什么都沒有
driver.find_element_by_tag_name("div") #正常
# 其他的查找方法都是報錯找不到
driver.find_element_by_tag_name("wx-view")
div.find_element_by_class_name("c-icon-search")
div.find_element_by_class_name("http://*[@class='c-icon-search']")
div.find_element_by_xpath("http://*[contains(@text, '上升榜')]")
在chrome inspect里面試了下xpath,是沒問題的
于是打印了一下driver.page_source铡羡,發(fā)現(xiàn)這個page_source很特殊积蔚,有點像亂碼,可能小程序代碼編譯后就是這樣子烦周?
把這字符串尽爆,粘貼到文本編輯器里怎顾,然后稍微處理了下,將\n轉(zhuǎn)為換行符漱贱,將\t變?yōu)?個空格槐雾,將'變?yōu)?,處理完后用chrome打開是個空白頁幅狮。
嘗試了chrome和火狐都無法正常顯示募强。所有元素相關(guān)的都在<script>標(biāo)簽里,大概是這個是源代碼彪笼,在driver里并沒有得到真正的執(zhí)行钻注,所以查找元素都是失敗,但是有個div的標(biāo)簽配猫。那為什么driver里沒有執(zhí)行,只是一坨script代碼杏死?泵肄??
然后再看看chrome:inspect里淑翼,發(fā)現(xiàn)有兩個頁簽腐巢,也就是打開了兩個頁面,inspect第一個玄括,發(fā)現(xiàn)跟我獲取的page_source是一樣的冯丙,一坨js代碼,沒有生成元素遭京,inspect第二個發(fā)現(xiàn)是有元素的胃惜。所以在driver里切換了一下window_handle
>>>driver.window_handles
['CDwindow-d91965e5-b473-4a5a-9448-36cc3129254a', 'CDwindow-41e4c376-ebb9-4fd1-accd-e0611cf9ea0d']
>>>driver.current_window_handle
'CDwindow-d91965e5-b473-4a5a-9448-36cc3129254a'
>>>driver.switch_to_window( 'CDwindow-41e4c376-ebb9-4fd1-accd-e0611cf9ea0d')
>>>driver.page_source
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"
>>>driver.find_element_by_class_name("c-icon-search")
<appium.webdriver.webelement.WebElement (session="748fec7a-fc1d-489a-a1ea-4c36650b228a", element="0.969712313378926-1")>
>>>driver.find_element_by_class_name("c-icon-search").click()
switch_to.window()報'name' must be a string
appium1.9的問題,降級到1.7.2解決
如何操作input輸入內(nèi)容
看小程序代碼里是<input>標(biāo)簽哪雕,但是渲染后變?yōu)榱?lt;wx-input>船殉,獲取元素后send_keys一直不行
>>>wxinput = driver.find_element_by_xpath("http://wx-input")
>>>wxinput .get_attribute("data-defaultkey")
'延禧攻略'
>>>wxinput.send_keys("haha")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "E:\pyvenv\wx-uiauto\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "E:\pyvenv\wx-uiauto\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "E:\pyvenv\wx-uiauto\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "E:\pyvenv\wx-uiauto\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
raise wde
File "E:\pyvenv\wx-uiauto\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "E:\pyvenv\wx-uiauto\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=57.0.2987.132)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)
adb自動化輸入中文問題
adb默認(rèn)不支持uicode,所以用adb shell input text "哈哈"是無法輸入的斯嚎。解決辦法查看以下文章
https://www.cnblogs.com/yoyoketang/p/8998789.html
ADBKeyBoard輸入法下載:
https://github.com/wangshub/Douyin-Bot/blob/master/apk/ADBKeyBoard.apk
window handle多個之間的切換問題
小程序里利虫,每打開一個頁面,會多一個window_handle堡僻,但是并不會自動切換糠惫,目前能想到的笨辦法是,找一個能標(biāo)識每個頁面的唯一性元素钉疫,然后遍歷每個頁簽硼讽,如果page_source有該元素,則切到該頁簽陌选,這個方法非常慢
也可以每次遍歷確認(rèn)window_handle和頁面的對應(yīng)關(guān)系后理郑,就保存到一個字典里蹄溉,這樣切不同的頁面就可以直接切?
java版報錯:
try{
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
} catch(Exception e) {
System.out.println("create driver error");
}
報錯如下:
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;
at org.openqa.selenium.remote.ProtocolHandshake.streamW3CProtocolParameters(ProtocolHandshake.java:262)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:255)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237)
開始的時候您炉,caps.setCapability(ChromeOptions.CAPABILITY, options2);也報這個錯柒爵,然后換了個selenium的版本,從3.14.0降低到3.5.0后解決了赚爵。但是這個appium的錯誤棉胀,從6.0降低到3.0還是沒解決
新版本的自動化問題
微信從6.6.6版本后,小程序的調(diào)試入口被封冀膝,但無疑間發(fā)現(xiàn)從搜索入口進(jìn)入小程序唁奢,仍然可以chrome:inspect,比如搜一搜窝剖,搜索愛奇藝麻掸,點擊小程序打開,這時候可以赐纱。
但是從6.7.3開始脊奋,vivo y66連這個入口也被封了。但小米6新安裝可以疙描。vivo手機從6.6.5升級到6.7.3又可以诚隙,比較奇怪。
appium啟動方式:
https://m.aliyun.com/jiaocheng/551181.html
https://www.cnblogs.com/testway/p/8177278.html
https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
FAtest框架
https://blog.csdn.net/qq_39745963/article/details/84337441?tdsourcetag=s_pcqq_aiomsg
https://cloud.tencent.com/developer/article/1132257
https://testerhome.com/topics/17037