def __init__(self, app_info, devic_info, **kwargs): self.delay_time = 3 self.app_info = app_info self.devic_info = devic_info self.desired_caps = app_info['desired_capabilities'] self.desired_caps['platformName'] = devic_info['platformName'] self.desired_caps['platformVersion'] = devic_info['platformVersion'] self.desired_caps['deviceName'] = devic_info['deviceName'] self.desired_caps['udid'] = devic_info['udid'] self.actions = app_info['actions'] #self.driver = wda.Client("http://localhost:8100") self.driver = wda.USBClient(udid=self.desired_caps['udid']) self.session = None self.dns_proxy_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.dns_proxy_socket.settimeout(100000)
def driver(): if platform == "android": driver = u2.connect() # 连接设备(usb只能插入单个设备) driver.set_fastinput_ime(True) # 启用自动化定制的输入法 driver.settings["operation_delay"] = (0, 0) # 操作后的延迟,(0, 0)表示操作前等待0s,操作后等待0s driver.settings['operation_delay_methods'] = ['click', 'swipe', 'drag', 'press'] driver.implicitly_wait(ReadConfig().get_implicitly_wait) # 设置隐式等待时间,默认20s driver.unlock() # 解锁设备 with driver.watch_context(builtin=True) as ctx: ctx.when("^(下载|更新)").when("取消").click() # 当同时出现(下载 或 更新)和 取消 按钮时,点击取消 ctx.when("跳过%").click() ctx.when("%允许%").click() ctx.when("继续").click() ctx.when("每次开启").click() ctx.when("创建").when("取消").click() ctx.when("恢复").when("取消").click() for element in ReadConfig().get_popup_elements: ctx.when(element).click() ctx.wait_stable(seconds=1.5) # 开启弹窗监控,并等待界面稳定(两个弹窗检查周期内没有弹窗代表稳定) yield driver driver.set_fastinput_ime(False) # 关闭自动化定制的输入法 driver.app_stop_all() # 停止所有应用 driver.screen_off() # 息屏 elif platform == "ios": driver = wda.USBClient().session(alert_action=wda.AlertAction.ACCEPT) driver.wait_ready() driver.implicitly_wait(ReadConfig().get_implicitly_wait) driver.unlock() # 解锁 with driver.alert.watch_and_click(): for element in ReadConfig().get_popup_elements: ele = driver(labelContains=element).get(timeout=2.5, raise_error=False) if ele is None: continue else: ele.tap() yield driver driver.close() driver.lock() # 息屏
# -*- coding: utf-8 -*- import wda import time uuid = "58dad54ccf463a7cf3752365408d766808f40ffd" port = 8100 wda_bundle_id = "com.facebook.WebDriverAgentRunner.xctrunner" c = wda.USBClient(uuid, port=port, wda_bundle_id=wda_bundle_id)
print("className:", el.className) el.click() print("alertExists:", c.alert.exists) print("alertButtons:", c.alert.buttons()) print("alertClick:", c.alert.click("Dismiss")) def test_xpath(c: wda.Client): c.xpath("//Window/Other/Other").exists def test_invalid_session(c: wda.Client): app = c.session("com.apple.Preferences") # kill app here app.session_id = "no-exists" app(label="Haha").exists if __name__ == "__main__": c = wda.USBClient() # c.healthcheck() # 恢复WDA状态 # test_error_callback(c) # test_elememt_operation(c) # test_preferences(c) # test_open_safari(c) # test_xpath(c) wda.DEBUG = True test_invalid_session(c)
def c() -> wda.Client: _c = wda.USBClient() _c.unlock() yield _c
def c(): if os.getenv("DEVICE_URL"): return wda.Client(os.getenv("DEVICE_URL")) return wda.USBClient()
def c(): return wda.USBClient() wda.DEBUG = True __target = os.getenv("DEVICE_URL") or 'http://localhost:8100' return wda.Client(__target)