piaoquan_tv_v1.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # -*- coding: utf-8 -*-
  2. # @Author: luojunhui
  3. # @Time: 2023/12/14
  4. import time
  5. from appium import webdriver
  6. from appium.webdriver.extensions.android.nativekey import AndroidKey
  7. from selenium.webdriver.common.by import By
  8. class PQuanTv(object):
  9. def __init__(self):
  10. self.platform = "票圈|3亿人喜欢的视频平台"
  11. self.caps = {
  12. "platformName": "Android",
  13. "deviceName": "Android",
  14. "appPackage": "com.tencent.mm",
  15. "appActivity": ".ui.LauncherUI",
  16. "autoGrantPermissions": True,
  17. "unicodekeyboard": True,
  18. "resetkeyboard": True,
  19. "noReset": True,
  20. "recreateChromeDriverSessions": True,
  21. "printPageSourceOnFailure": True,
  22. "newCommandTimeout": 6000,
  23. "automationName": "UiAutomator2",
  24. "showChromedriverLog": True,
  25. "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
  26. "enableWebviewDetailsCollection": True,
  27. "setWebContentsDebuggingEnabled": True,
  28. "chromedriverExecutable": "/usr/bin/chromedriver",
  29. }
  30. self.driver = webdriver.Remote("http://localhost:4750/wd/hub", self.caps)
  31. def open_wechat(self):
  32. self.driver.implicitly_wait(1)
  33. for i in range(5):
  34. if self.driver.find_elements(By.ID, "com.tencent.mm:id/f2s"):
  35. break
  36. elif self.driver.find_element(By.ID, "com.android.systemui:id/dismiss_view"):
  37. self.driver.find_element(By.ID, "com.android.system:id/dismiss_view").click()
  38. else:
  39. pass
  40. self.driver.find_elements(By.XPATH, '//*[@text="{}"]'.format(self.platform))[-1].click()
  41. def click_ad(self):
  42. elements = self.driver.find_elements(By.ID, "com.tencent.mm:id/fhs")
  43. print(elements)
  44. elements[0].click()
  45. return
  46. class PQuanTvDev(object):
  47. def __init__(self, rule_dict):
  48. self.platform = "票圈|3亿人喜欢的视频平台"
  49. self.rule_dict = rule_dict
  50. self.caps = {
  51. "platformName": "Android",
  52. "deviceName": "Android",
  53. "appPackage": "com.tencent.mm",
  54. "appActivity": ".ui.LauncherUI",
  55. "autoGrantPermissions": True,
  56. "unicodekeyboard": True,
  57. "resetkeyboard": True,
  58. "noReset": True,
  59. "recreateChromeDriverSessions": True,
  60. "printPageSourceOnFailure": True,
  61. "newCommandTimeout": 6000,
  62. "automationName": "UiAutomator2",
  63. "showChromedriverLog": True,
  64. "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
  65. "enableWebviewDetailsCollection": True,
  66. "setWebContentsDebuggingEnabled": True,
  67. "chromedriverExecutable": "/usr/bin/chromedriver",
  68. }
  69. self.driver = webdriver.Remote("http://localhost:4750/wd/hub", self.caps)
  70. def open_minigram(self):
  71. self.driver.implicitly_wait(5)
  72. for i in range(10):
  73. if self.driver.find_elements(By.ID, "com.tencent.mm:id/f2s"):
  74. break
  75. elif self.driver.find_element(By.ID, "com.android.systemui:id/dismiss_view"):
  76. self.driver.find_element(By.ID, "com.android.system:id/dismiss_view").click()
  77. else:
  78. pass
  79. size = self.driver.get_window_size()
  80. self.driver.swipe(
  81. int(size["width"] * 0.5),
  82. int(size["height"] * 0.2),
  83. int(size["width"] * 0.5),
  84. int(size["height"] * 0.8),
  85. 200,
  86. )
  87. self.driver.find_elements(By.XPATH, '//*[@text="{}"]'.format(self.platform))[-1].click()
  88. def open_chat_box(self):
  89. self.driver.implicitly_wait(10)
  90. print("start open chatbox")
  91. box_list = self.driver.find_elements(By.ID, "com.tencent.mm:id/hg4")
  92. print(box_list)
  93. if box_list:
  94. box_list[0].click()
  95. print("finish open chatbox")
  96. def click_ad(self):
  97. minigram = self.driver.find_elements(By.ID, "com.tencent.mm:id/b2o")
  98. if minigram:
  99. minigram[0].click()
  100. print("成功打开小程序")
  101. return
  102. if __name__ == "__main__":
  103. Pv = PQuanTvDev(rule_dict={})
  104. print("成功切换到webview")
  105. Pv.open_chat_box()
  106. time.sleep(10)
  107. Pv.click_ad()