1.toast获取
def hook_toast_method(self, selector, inner_text=None):
"""
封装hook wx API接口,获取回调 showToast
:param selector: 触发元素选择器
:return: toast
"""
before = Callback()
# hook wx API接口,获取回调后执行callback
self.mini.app.hook_wx_method("showToast", before=before)
# 点击元素,会触发toast的操作
self.get_element(selector, inner_text=inner_text).tap()
before_args = before.get_callback_result(10)
# 释放hook
self.mini.app.release_hook_wx_method("showToast")
toast = before_args['title']
self.logger(toast)
return toast
2.模态弹框操作
def show_modal(self, btn_text='确定'):
"""
模态弹框,属于native控件,无法直接定位操作,需要用到 native方法
:param btn_text:
:return:
"""
self.mini.native.handle_modal(btn_text=btn_text)
3.等待某个元素出现某个属性,比如,等待按钮可以点击
def wait_for_attribute(self, selector, name, value, max_timeout=10):
"""
等待元素属性出现
:param selector:
:param name:
:param value:
:param max_timeout:
:return:
"""
def page_wait():
value1 = self.mini.page.get_element(selector).attribute(name)[0]
return value1 == value
self.mini.assertTrue(self.mini.page.wait_for(page_wait, max_timeout=max_timeout))
self.logger(f"等待元素属性 {name} {value}")