APP H5 混合自动化使用说明 [基于 Appium+Python+微信/钉钉 系列]

前言:

  1. 微信:已成功定位并解决自动化问题
  2. 钉钉:目前可以定位到,但是代码无法切换webview

appium+微信

  1. 把微信的开发者模式调出 debugx5.qq.com
    随意发送消息,内容为“debugx5.qq.com”。点击debugx5.qq.com, 这就会跳转至微信的x5内核调试页面
    信息—勾选"是否打开TBS内核Inspector调试功能
    在这里插入图片描述
    2.在谷歌输入“chrome://inspect/#devices” ,点击微信内部
    会显示出相应链接,点击inspect即可出现定位页面
    在这里插入图片描述
    注意
    如果inspect之后,页面不能显示/显示404,则需要登录vpn,即可显示

  2. 代码部分
    import time
    import unittest
    import warnings

import unittest2
from appium import webdriver

class BaseTestCaseWX3(unittest2.TestCase):

def setUp(self):
    warnings.filterwarnings("ignore")
    self.caps={
        "platformName": "Android",
        # mate8
        "platformVersion": "8.0.0",
        "deviceName": "5LM0216729001841",
        "automationName": "Appium",   # Appium版本:1.8.2
        # 微信
        "appPackage": "com.tencent.mm",
        "appActivity": "com.tencent.mm.ui.LauncherUI",
        "noReset": "true",
        # 键盘
        "unicodeKeyboard": True,  # 使用unicode编码方式发送字符串
        "resetKeyboard": True,   # 把键盘隐藏起来
        
        # webview的进程名,查到的是com.tencent.mm:tools
        "chromeOptions": {
            "androidProcess": "com.tencent.mm:tools"
        }
    }
    self.driver=webdriver.Remote("http://localhost:4723/wd/hub", self.caps)
    #self.driver.implicitly_wait(10)
    time.sleep(10)
    
    # 打印所有页面会打印出俩: ['NATIVE_APP','WEBVIEW_com.tencent.mm:tools']
    print(self.driver.contexts)       
    time.sleep(3)
    # 切换至webview页面
    self.driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
    time.sleep(5)

亲自使用,可以正常使用,作为记录也为他人提供方便。
发布了5 篇原创文章 · 获赞 0 · 访问量 896

猜你喜欢

转载自blog.csdn.net/akuiblog/article/details/101348767