|
@@ -48,57 +48,60 @@ class Recommend:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def start_wechat(cls, log_type, env):
|
|
def start_wechat(cls, log_type, env):
|
|
- Common.logger(log_type).info('启动微信')
|
|
+ try:
|
|
- caps = {
|
|
+ Common.logger(log_type).info('启动微信')
|
|
- "platformName": "Android",
|
|
+ caps = {
|
|
- "deviceName": "a0a65126",
|
|
+ "platformName": "Android",
|
|
- "platforVersion": "11",
|
|
+ "deviceName": "a0a65126",
|
|
- "appPackage": "com.tencent.mm",
|
|
+ "platforVersion": "11",
|
|
- "appActivity": ".ui.LauncherUI",
|
|
+ "appPackage": "com.tencent.mm",
|
|
- "autoGrantPermissions": "true",
|
|
+ "appActivity": ".ui.LauncherUI",
|
|
-
|
|
+ "autoGrantPermissions": "true",
|
|
- "unicodekeyboard": True,
|
|
+
|
|
- "resetkeyboard": True,
|
|
+ "unicodekeyboard": True,
|
|
- "noReset": True,
|
|
+ "resetkeyboard": True,
|
|
- "printPageSourceOnFailure": True,
|
|
+ "noReset": True,
|
|
- "newCommandTimeout": 6000,
|
|
+ "printPageSourceOnFailure": True,
|
|
- "automationName": "UiAutomator2",
|
|
+ "newCommandTimeout": 6000,
|
|
-
|
|
+ "automationName": "UiAutomator2",
|
|
- "showChromedriverLog": True,
|
|
+
|
|
- 'enableWebviewDetailsCollection': True,
|
|
+ "showChromedriverLog": True,
|
|
- 'setWebContentsDebuggingEnabled': True,
|
|
+ 'enableWebviewDetailsCollection': True,
|
|
- 'recreateChromeDriverSessions': True,
|
|
+ 'setWebContentsDebuggingEnabled': True,
|
|
-
|
|
+ 'recreateChromeDriverSessions': True,
|
|
- 'chromedriverExecutable': '/Users/lieyunye/Downloads/chromedriver_v86/chromedriver',
|
|
+
|
|
- "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
|
|
+ 'chromedriverExecutable': '/Users/lieyunye/Downloads/chromedriver_v86/chromedriver',
|
|
- 'browserName': ''
|
|
+ "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
|
|
- }
|
|
+ 'browserName': ''
|
|
- driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
|
|
+ }
|
|
- driver.implicitly_wait(20)
|
|
+ driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
|
|
-
|
|
+ driver.implicitly_wait(20)
|
|
- for i in range(120):
|
|
+
|
|
- try:
|
|
+ for i in range(120):
|
|
-
|
|
+ try:
|
|
- if driver.find_elements(By.ID, 'com.tencent.mm:id/f2s'):
|
|
+
|
|
- break
|
|
+ if driver.find_elements(By.ID, 'com.tencent.mm:id/f2s'):
|
|
-
|
|
+ break
|
|
- elif driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view'):
|
|
+
|
|
- Common.logger(log_type).info('发现并关闭系统下拉菜单栏')
|
|
+ elif driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view'):
|
|
- driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view').click()
|
|
+ Common.logger(log_type).info('发现并关闭系统下拉菜单栏')
|
|
- else:
|
|
+ driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view').click()
|
|
- pass
|
|
+ else:
|
|
- except NoSuchElementException:
|
|
+ pass
|
|
- time.sleep(1)
|
|
+ except NoSuchElementException:
|
|
- Common.logger(log_type).info('下滑,展示小程序选择面板')
|
|
+ time.sleep(1)
|
|
- size = driver.get_window_size()
|
|
+ Common.logger(log_type).info('下滑,展示小程序选择面板')
|
|
- driver.swipe(int(size['width'] * 0.5), int(size['height'] * 0.2),
|
|
+ size = driver.get_window_size()
|
|
- int(size['width'] * 0.5), int(size['height'] * 0.8), 200)
|
|
+ driver.swipe(int(size['width'] * 0.5), int(size['height'] * 0.2),
|
|
-
|
|
+ int(size['width'] * 0.5), int(size['height'] * 0.8), 200)
|
|
- time.sleep(3)
|
|
+
|
|
- Common.logger(log_type).info('打开小程序"看到就是福气"')
|
|
+ time.sleep(3)
|
|
- driver.find_elements(By.XPATH, '//*[@text="看到就是福气"]')[-1].click()
|
|
+ Common.logger(log_type).info('打开小程序"看到就是福气"')
|
|
- cls.get_recommend(log_type, driver, env)
|
|
+ driver.find_elements(By.XPATH, '//*[@text="看到就是福气"]')[-1].click()
|
|
- cls.quit(log_type, driver)
|
|
+ cls.get_recommend(log_type, driver, env)
|
|
|
|
+ cls.quit(log_type, driver)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ Common.logger(log_type).error(f'start_wechat异常:{e}\n')
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def quit(cls, log_type, driver: WebDriver):
|
|
def quit(cls, log_type, driver: WebDriver):
|