问题一:
公司在做微信公众号,想进行自动化测试,网上查的资料都说 Appium 不支持微信公众号的自动化测试,最近又有听说最新的 1.6 版本能够支持,请问到底是支不支持?
=================================================================================================
问题二:
公司产品后台提供配置,能够直接在浏览器打开测试页面,但在执行脚本时发现 click 操作页面没有反应,日志贴在了后面。元素定位正常点击操作也没有错误
测试页面:
测试代码:
from appium import webdriver
import time
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['deviceName'] = '25b389ad'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.get('http://qlcqd.test.jkt.guahao-inc.com/User/login')
time.sleep(2)
driver.find_element_by_css_selector('#login').click()
问题原因:
请教开发同学后,开发同学说这里调用 touchstart 事件,只能通过触摸屏幕点击触发。
解决方法:
通过查找到资料,发现 tap 操作能够触发,但是需要注意的是,执行 tap 时需要先切换到 NATIVE_APP,然后再通过手机绝对坐标进行点击。请问大家这种情况除了使用 tap 还有其它好的方法吗?
例:
driver.switch_to.context('NATIVE_APP')
driver.tap([(560,768)])
12-18 日更新,已找到解决方法,通过进行实验,发现通过切换到 NATIVE_APP 后,直接通过以下两种查找元素的方式都可以实现点击操作,具体原理虽然还没太搞清楚,还需要努力学习。
driver.switch_to.context('NATIVE_APP')
方法一:
el = driver.find_element_by_android_uiautomator('new UiSelector().resourceId("login")')
方法二:
el = driver.find_element_by_xpath('//android.view.View[@resource-id=\"resetPwd\"]')
TouchAction(driver).tap(el).release().perform()
=================================================================================================
问题三: 第二步的方法已解决这个问题,但如果 xpath 和 uiautomator 如果找到元素的时候就不知道该怎么办了。
虽然 tap 方法能够解决这个问题,但使用坐标这种方法感觉有点不靠谱,如果页面元素位置变更,所有的用例都会执行失败,后面发现可以通过 location 得到元素在浏览器中的位置
driver.find_element_by_css_selector(css).location
于是我想到一个思路,能不能先通过 location 方法获取到元素在浏览器中的坐标,再通过浏览器的坐标换算成手机的坐标进行点击。请问大家像这种思路有没有可能实现?
=================================================================================================
这里是 appium 执行时的日志:
info: [debug] Appium session started with sessionId 51bfc513e7450c19a218014e06e5fd28
info: <-- POST /wd/hub/session 303 14190.327 ms - 70
info: --> GET /wd/hub/session/51bfc513e7450c19a218014e06e5fd28 {}
info: JSONWP Proxy: Proxying [GET /wd/hub/session/51bfc513e7450c19a218014e06e5fd28] to [GEThttp://127.0.0.1:9515/wd/hub/session/51bfc513e7450c19a218014e06e5fd28] with body: {}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"51bfc513e7450c19a218014e06e5fd28","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSel...
info: JSONWP Proxy: Replacing sessionId 51bfc513e7450c19a218014e06e5fd28 with 51bfc513e7450c19a218014e06e5fd28
info: <-- GET /wd/hub/session/51bfc513e7450c19a218014e06e5fd28 200 20.300 ms - 528
info: --> POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/url {"url":"http://qlcqd.test.jkt.guahao-inc.com/User/login,sessionId:51bfc513e7450c19a218014e06e5fd28"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/url] to [POST http://127.0.0.1:9515/wd/hub/session/51bfc513e7450c19a218014e06e5fd28/url] with body: {"url":"http://qlcqd.test.jkt.guahao-inc.com/User/login,sessionId:51bfc513e7450c19a218014e06e5fd28"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"51bfc513e7450c19a218014e06e5fd28","status":0,"value":null}
info: JSONWP Proxy: Replacing sessionId 51bfc513e7450c19a218014e06e5fd28 with 51bfc513e7450c19a218014e06e5fd28
info: <-- POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/url 200 3791.238 ms - 72
===============================元素查找正常
info: --> POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element {"using":"css selector","sessionId":"51bfc513e7450c19a218014e06e5fd28","value":"#login"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element] to [POST http://127.0.0.1:9515/wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element] with body: {"using":"css selector","sessionId":"51bfc513e7450c19a218014e06e5fd28","value":"#login"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"51bfc513e7450c19a218014e06e5fd28","status":0,"value":{"ELEMENT":"0.6230404864695509-1"}}
info: JSONWP Proxy: Replacing sessionId 51bfc513e7450c19a218014e06e5fd28 with 51bfc513e7450c19a218014e06e5fd28
==============================click 事件没有出现报错或或异常
info: <-- POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element 200 144.749 ms - 102
info: --> POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element/0.6230404864695509-1/click {"sessionId":"51bfc513e7450c19a218014e06e5fd28","id":"0.6230404864695509-1"}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element/0.6230404864695509-1/click] to [POST http://127.0.0.1:9515/wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element/0.6230404864695509-1/click] with body: {"sessionId":"51bfc513e7450c19a218014e06e5fd28","id":"0.6230404864695509-1"}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"51bfc513e7450c19a218014e06e5fd28","status":0,"value":null}
info: JSONWP Proxy: Replacing sessionId 51bfc513e7450c19a218014e06e5fd28 with 51bfc513e7450c19a218014e06e5fd28
info: <-- POST /wd/hub/session/51bfc513e7450c19a218014e06e5fd28/element/0.6230404864695509-1/click 200 236.021 ms - 72