H5-ios自动化相关源码

def open_wx_app(name="", attr=None):
    """
    发现-小程序-点击小程序
    :param name: 小程序名称
    :param attr: 小程序类型,例如开发版、体验版
    :return:
    """
    if not attr or attr == '正式版':
        xps = f"//android.widget.TextView[@text='{name}']/../android.widget.FrameLayout[not(android.widget.TextView)]"
    else:
        xps = f"//android.widget.TextView[@text='{name}']/../../android.widget.TextView[@text='{attr}']"
    try:
        self.driver.find_element_by_xpath(xps).click()
        return True
    except NoSuchElementException:
        pass
    return False


​​​​​​​desired_caps_a = {
    "platformName": "Android",
    "platformVersion": "10",
    "deviceName": "xxxxxx",
    "udid": "sssss", 
    "clearSystemFiles": True,
    "newCommandTimeout": "360",
    "automationName": "uiautomator2",
    "resetKeyboard": True,
    "unicodeKeyboard": True,
    "skipServerInstallation": True,
    "skipDeviceInitialization": True,
    "noReset": True,    # 不清除掉微信的数据!!!一定记得加!!!避免再次安装app不要停止应用程序,不要清除应用数据,不要卸载apk
    "unlockType": "pattern",
    "unlockKey": "",
    "appPackage": "com.tencent.mm",
    "appActivity": ".ui.LauncherUI",
    "chromedriverExecutable": "/Applications/Appium.app/Contents/Resources/app/node_modules/appium/"
                              "node_modules/appium-chromedriver/chromedriver/mac/chromedriver",
    "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},    # ChromeOptions使用来定制启动选项
    # 在appium中切换context识别webview时,小程序在一个单独进程中,故必加androidProcess,第二个参数要改成你查询到的小程序进程名
    "recreateChromeDriverSessions": True,   # 移动到非ChromeDriver webview时终止ChromeDriver会话。
    "browserName": "",    # 初始化会默认将chrome浏览器打开,需要将Browser置为空
    "sessionOverride": True,   # 不必每次重启session
    "autoWebviewTimeout": 30000,
    "enableWebviewDetailsCollection": True
}
# 微信使用的是77版本webview(X5内核),不能按照常规匹配模式去找对应的chromeDriver
device_a = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps_a)
time.sleep(5)
print('进入小程序')
# 打开微信小程序:有的手机中的三键导航开启后才能识别最底部的文本元素,关闭时超出屏幕以外的位置无法识别元素,所以使用坐标点击。
​​​​​​​print('进入微信,点击发现按钮')
try:
    pp_driver.find_element_by_xpath('//android.widget.TextView[@text="发现"]').click()
except:
    bf.swipe_special(0.63, 0.99, 0.63, 0.99, 1)
sleep(1)
print('点击小程序tab')
self.driver.find_element_by_xpath('//android.widget.TextView[@text="小程序"]').click()
sleep(2)
print('点击要测试的小程序')
self.open_wx_app(attr='体验版')
sleep(5)

dev_contexts = device_a.contexts
print(dev_contexts)
print('切换到小程序登陆页面, 获取web view的title,有效上下文和句柄')
web_title, active_context, active_win = bf.find_valid_webview(dev_contexts)
print('切换到登录页的句柄')
win_handles = device_a.window_handles
source = device_a.page_source

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值