def test_swipe_duration(d: u2.Device): w, h = d.window_size() start = time.time() d.debug = True d.swipe(w // 2, h // 2, w - 1, h // 2, 2.0) duration = time.time() - start assert duration >= 1.5 # actually duration is about 7s in my TT
def test_operation_delay(d: u2.Device): x, y = d(text="App").center() # 测试前延迟 start = time.time() d.settings['operation_delay'] = (1, 0) d.click(x, y) time_used = time.time() - start assert 1 < time_used < 1.5 # 测试后延迟 start = time.time() d.settings['operation_delay_methods'] = ['press', 'click'] d.settings['operation_delay'] = (0, 2) d.press("back") time_used = time.time() - start assert time_used > 2 #2 < time_used < 2.5 # 测试operation_delay_methods start = time.time() d.settings['operation_delay_methods'] = ['press'] d.click(x, y) time_used = time.time() - start assert 0 < time_used < .5
def worker(d: u2.Device): d.app_start("io.appium.android.apis", stop=True) d(text="App").wait() for el in d.xpath("@android:id/list").child("/android.widget.TextView").all(): logger.info("%s click %s", d.serial, el.text) el.click() d.press("back") logger.info("%s DONE", d.serial)
def test_push_and_pull(d: u2.Device): device_target = "/data/local/tmp/hello.txt" content = b"hello world" d.push(io.BytesIO(content), device_target) d.pull(device_target, "tmpfile-hello.txt") with open("tmpfile-hello.txt", "rb") as f: assert f.read() == content os.unlink("tmpfile-hello.txt")
def test_screenrecord(d: u2.Device): with pytest.raises(RuntimeError): d.screenrecord.stop() d.screenrecord("output.mp4", fps=10) start = time.time() with pytest.raises(RuntimeError): d.screenrecord("output2.mp4") time.sleep(5.0) d.screenrecord.stop() print("Time used:", time.time() - start) # check with imageio.get_reader("output.mp4") as f: meta = f.get_meta_data() assert isinstance(meta, dict) from pprint import pprint pprint(meta)
def __init__(self, raw: bool, session: frida.core.Session, frida_device: frida.core.Device, pid, u2_device: u2.Device): self.raw = raw self.session = session self.frida_device = frida_device self.pid = pid self.u2_device = u2_device self.screen_width, self.screen_height = u2_device.window_size() self.original_screen_width, self.original_screen_height = None, None with open('scripts/replayer.js', 'r') as f: s = script.Script(self.session, f.read()) s.set_on_message(self.on_message) self.rpc = s.rpc
def __init__(self, device: Device = None, max_task: int = 0): if isinstance(device, Device): self.device = device else: self.device = Device(device) self.queue: Queue = Queue(maxsize=max_task)
def test_watch_context(sess: u2.Device): with sess.watch_context(builtin=True) as ctx: ctx.when("App").click() sess(text='Menu').click() assert sess(text='Inflate from XML').wait()
def show_click_position(d: u2.Device, point: Point): # # pprint(result.widget) # # pprint(dict(result.node.attrib)) im = draw_point(d.screenshot(), point.x, point.y) im.show()