app_h5 hybrid applications

 Acquaintance h5 hybrid application essays ~~

When embedded in a web app web application (mixed page), how the web page element positioning?

1, how to identify the html page, using ui first positioning element when automator viewer tool, andriod.webkit.webview class attribute categories represented on the selected element is embedded in a web page can not be directly used app element positioned directly targeting tool need to switch to html page elements can be positioned on this page

 

 

2, to determine the page when the page are mixed, to obtain the context of the page, and then switch into webview view of context names; driver.switch_to.context ( 'webview name')

Example:

# 1, acquired in the context of the application page (typically a need to develop open debug mode of application webview) 
cons = # driver.contexts get all context of the page - native above control, the following is a html page 
Print (cons) 

# 2 The context name switching in Webview 
driver.switch_to.context ( 'WEBVIEW_com.lemon.lemonban')

 


Prerequisite: Open the debug mode applications webview can only get NATIVE_APP when not open, can not get WEBVIEW
Solution
Method 1: app to open the package when the need to develop webview application of the debug attribute, setWebContentDebuggingEnabled (true)
Method 2: Reference blog https : //www.cnblogs.com/yyoba/p/11149614.html mixing app open h5 debugging

 

3, the switching element into the positioning webview pages, will be described for Method 2

方法1:driver.page_source  --得到html页面,保存到html里用浏览器打开后f12进行定位

方法2:使用uc-devtools第三方工具 app-web页面定位工具(uc浏览器提供的),需要提前安装:https://dev.ucweb.com/docs/pwa/docs-zh/xy3whu,安装后打开uc工具,在设置中勾选本地devtools inspector UI资源即可
   前提:使用真机或模拟器打开app应用需要提前进入混合页面,此时打开uc-devtools工具才能直接识别到该web页面;如果模拟器当前所打开的页面没有 webview,在uc工具中也会相应显示:没有检测到 webview
另外uc-devtools工具能够自动识别该模拟器设备名称127.0.0.1:62001及系统自带的webview版本号74,然后在工具上点inspect按钮,进入html界面,此时就可以按照web页面元素定位方法进行元素定位了

 

 

方法3:chrome://inspect/ ,直接使用chrome访问该地址也可以定位,但是需要翻墙

 

4、切回app


driver.switch_to.context('NATIVE_APP')
# driver.switch_to.context(None)

 5、执行脚本

    比如安卓系统驱动程序使用的是chromedriver驱动,但要和手机的webview版本要匹配

    检查appium中chromedriver驱动版本和手机/模拟器系统的webview版本号是否一致,否则会报错

chromedriver版本:

http://npm.taobao.org/mirrors/chromedriver

 

 总结:

# =============前提=============
# html5 -- html页面
# 混合应用 -hybrid -安卓操作系统(app应用-原生控件)--嵌入了web网页
# 识别到混合页面
# 打开webview的调试模式 --打开应用的webview的debug模式

# =============app自动化=============
# 进入到混合页面
# 获取context: driver.contexts
# 切换到html页面:从原生控件 切换到 html页面 driver.switch_to.context(webview的名字)
# =============web自动化=============
# 1.元素定位:使用工具uc-devtools 进行混合页面的元素定位
# 2.后续执行python脚本时,如果使用了不同的手机或模拟器进行测试,那么不同的设备对应的webview版本是不同的,可以下载匹配手机webview的chromedriver驱动,并通过启动会话参数chromedriverExecutable指定路径 

Guess you like

Origin www.cnblogs.com/lemon---/p/11853216.html