1
0

test-adb1.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import uiautomator2 as u2
  2. import time
  3. from adbutils import adb
  4. from uiautomator2 import Direction
  5. d = u2.connect('127.0.0.1:6555') # 例如:"127.0.0.1:61468"
  6. # d = u2.connect_usb()
  7. print('>0>>>', d.info)
  8. res = d.shell('settings get global device_name')
  9. print('>>1>>', str(res.output).strip())
  10. #
  11. # el=d.xpath('//*[@content-desc="开仓"]').scroll_to(xpath='//*[@content-desc="市价全平"]', direction=Direction.FORWARD,
  12. # max_swipes=100)
  13. #
  14. # print('>>>>', el)
  15. #
  16. # while True:
  17. # time.sleep(9999)
  18. # d.xpath("//*[@text='私人FM']/../android.widget.ImageView")
  19. # d.screen_off();
  20. # d.sleep(4)
  21. # d.screen_on();
  22. # # d.keyevent('24')
  23. #
  24. # urls = ['https://www.baidu.com', 'https://www.qq.com']
  25. # idx = 0
  26. # for d in adb.device_list():
  27. # print('--->', d.serial) # print device serial
  28. # print('>>>', d.info) # print device
  29. # # d.open_browser(urls[idx])
  30. # idx += 1
  31. # d.switch_wifi(False)
  32. # ctx = d.dump_hierarchy()
  33. # print(f'>>{idx}>>', ctx)
  34. # pck = d.list_packages()
  35. # print(pck)
  36. # # d.switch_wifi(True)
  37. # # d.app_start("com.android.chrome")
  38. # img= d.screenshot()
  39. # img.save(f'screenshot{idx}.png')
  40. # print(img)
  41. # time.sleep(10)
  42. # d = adb.device(serial="127.0.0.1:50269")
  43. # print('>>1>', d.info) # print device
  44. #
  45. # # d.sleep = lambda seconds: d.shell(f'sleep {seconds}')
  46. # # d.sleep(3)
  47. # # print('>>2>', d.info) # print device
  48. #
  49. # w, h = d.window_size()
  50. # print('>>3>', w, h) # print device
  51. # # or
  52. # d = adb.device(transport_id=24) # transport_id can be found in: adb devices -l
  53. # You do not need to offer serial if only one device connected
  54. # RuntimeError will be raised if multi device connected
  55. # d = adb.device()
  56. # print('>>>',d.info)