123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- # -*- coding: utf-8 -*-
- # @Author: luojunhui
- # @Time: 2023/12/14
- import time
- from appium import webdriver
- from appium.webdriver.extensions.android.nativekey import AndroidKey
- from selenium.webdriver.common.by import By
- class PQuanTv(object):
- def __init__(self):
- self.platform = "票圈|3亿人喜欢的视频平台"
- self.caps = {
- "platformName": "Android",
- "deviceName": "Android",
- "appPackage": "com.tencent.mm",
- "appActivity": ".ui.LauncherUI",
- "autoGrantPermissions": True,
- "unicodekeyboard": True,
- "resetkeyboard": True,
- "noReset": True,
- "recreateChromeDriverSessions": True,
- "printPageSourceOnFailure": True,
- "newCommandTimeout": 6000,
- "automationName": "UiAutomator2",
- "showChromedriverLog": True,
- "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
- "enableWebviewDetailsCollection": True,
- "setWebContentsDebuggingEnabled": True,
- "chromedriverExecutable": "/usr/bin/chromedriver",
- }
- self.driver = webdriver.Remote("http://localhost:4750/wd/hub", self.caps)
- class PQuanTvDev(object):
- """
- __init__: 初始化类, 初始化driver;
- open_minigram: 下拉,通过搜索小程序名字打开小程序
- open_chat_box: 进入微信之后打开聊天框
- click_ad: 点击消息,打开小程序之后,点击广告, 退出
- """
- def __init__(self, rule_dict):
- self.platform = "票圈|3亿人喜欢的视频平台"
- self.rule_dict = rule_dict
- self.caps = {
- "platformName": "Android",
- "deviceName": "Android",
- "appPackage": "com.tencent.mm",
- "appActivity": ".ui.LauncherUI",
- "autoGrantPermissions": True,
- "unicodekeyboard": True,
- "resetkeyboard": True,
- "noReset": True,
- "recreateChromeDriverSessions": True,
- "printPageSourceOnFailure": True,
- "newCommandTimeout": 6000,
- "automationName": "UiAutomator2",
- "showChromedriverLog": True,
- "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
- "enableWebviewDetailsCollection": True,
- "setWebContentsDebuggingEnabled": True,
- "chromedriverExecutable": "/usr/bin/chromedriver",
- }
- self.driver = webdriver.Remote("http://localhost:4750/wd/hub", self.caps)
- def open_minigram(self):
- self.driver.implicitly_wait(5)
- for i in range(10):
- if self.driver.find_elements(By.ID, "com.tencent.mm:id/f2s"):
- break
- elif self.driver.find_element(By.ID, "com.android.systemui:id/dismiss_view"):
- self.driver.find_element(By.ID, "com.android.system:id/dismiss_view").click()
- else:
- pass
- size = self.driver.get_window_size()
- self.driver.swipe(
- int(size["width"] * 0.5),
- int(size["height"] * 0.2),
- int(size["width"] * 0.5),
- int(size["height"] * 0.8),
- 200,
- )
- self.driver.find_elements(By.XPATH, '//*[@text="{}"]'.format(self.platform))[-1].click()
- def open_chat_box(self):
- self.driver.implicitly_wait(10)
- print("start open chatbox")
- box_list = self.driver.find_elements(By.ID, "com.tencent.mm:id/hg4")
- print(box_list)
- if box_list:
- box_list[0].click()
- print("finish open chatbox")
- def click_ad(self):
- minigram = self.driver.find_elements(By.ID, "com.tencent.mm:id/b2o")
- if minigram:
- minigram[0].click()
- print("成功打开小程序")
- self.driver.press_keycode(AndroidKey.BACK)
- else:
- return
- if __name__ == "__main__":
- Pv = PQuanTvDev(rule_dict={})
- print("成功切换到webview")
- Pv.open_chat_box()
- time.sleep(10)
- Pv.click_ad()
|