Пример #1
0
def test_error_callback(c: wda.Client):
    def err_handler(client: wda.Client, err):
        if isinstance(err, wda.WDARequestError):
            print("ERROR:", err)
            return wda.Callback.RET_ABORT # 直接退出
            return wda.Callback.RET_CONTINUE # 忽略错误继续执行
            return wda.Callback.RET_RETRY # 重试一下

    c.register_callback(wda.Callback.ERROR, err_handler)
    c.send_keys("hello callback")
Пример #2
0
def test_send_keys_callback(c: wda.Client):
    def _handle_alert_before_send_keys(client: wda.Client, urlpath: str):
        if not urlpath.endswith("/wda/keys"):
            return
        if client.alert.exists:
            client.alert.accept()
        print("callback called")

    c.register_callback(wda.Callback.HTTP_REQUEST_BEFORE, _handle_alert_before_send_keys)
    c.send_keys("hello callback")