From 9788db2dac13853dd1abdffb69adf39f4cf26c80 Mon Sep 17 00:00:00 2001 From: yanchunhuo Date: Thu, 4 Feb 2021 19:42:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98=E6=B7=B7=E5=90=88=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/read_app_ui_devices_info.py | 2 ++ common/appium/appOperator.py | 7 +------ config/app_ui_devices_info_template.conf | 6 ++++++ .../app_ui_android_devices_info_demoProject.conf | 6 ++++++ pojo/app_ui_devices_info.py | 13 +++++++++++++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/base/read_app_ui_devices_info.py b/base/read_app_ui_devices_info.py index c975764..bf34af9 100644 --- a/base/read_app_ui_devices_info.py +++ b/base/read_app_ui_devices_info.py @@ -39,6 +39,8 @@ class Read_APP_UI_Devices_Info(object): devices_info.deviceNames = get_lambda(config.get('devices_info', 'deviceNames', fallback='')) devices_info.chromeDriverPorts = get_lambda(config.get('devices_info', 'chromeDriverPorts', fallback='')) devices_info.chromeDriverPaths = get_lambda(config.get('devices_info', 'chromeDriverPaths', fallback='')) + devices_info.recreateChromeDriverSessions = get_lambda(config.get('devices_info', 'recreateChromeDriverSessions', fallback='')) + devices_info.nativeWebScreenshots = get_lambda(config.get('devices_info', 'nativeWebScreenshots', fallback='')) devices_info.systemports=get_lambda(config.get('devices_info','systemports', fallback='')) devices_info.wdaLocalPorts = get_lambda(config.get('devices_info', 'wdaLocalPorts', fallback='')) devices_info.wdaLocalPorts = get_lambda(config.get('devices_info', 'wdaLocalPorts', fallback='')) diff --git a/common/appium/appOperator.py b/common/appium/appOperator.py index 86a2f84..9aca9be 100644 --- a/common/appium/appOperator.py +++ b/common/appium/appOperator.py @@ -239,14 +239,9 @@ class AppOperator: alert=self._driver.switch_to.alert return alert.text - def get_screenshot(self,fileName,native_context='NATIVE_APP'): - current_context=self.get_current_context() - if not current_context==native_context: - self.switch_context(native_context) + def get_screenshot(self,fileName): fileName=DateTimeTool.getNowTime('%Y%m%d%H%M%S%f_')+fileName allure.attach(name=fileName,body=self._driver.get_screenshot_as_png(),attachment_type=allure.attachment_type.PNG) - if not current_context==native_context: - self.switch_context(current_context) def refresh(self): self._driver.refresh() diff --git a/config/app_ui_devices_info_template.conf b/config/app_ui_devices_info_template.conf index a3fdd62..afee9c5 100644 --- a/config/app_ui_devices_info_template.conf +++ b/config/app_ui_devices_info_template.conf @@ -41,6 +41,12 @@ chromeDriverPorts = 5200 || # 混合应用chromeDriver绝对路径,确保驱动版本与手机应用浏览器内核保持匹配,无需则放空 chromeDriverPaths = C:\Users\yanch\Desktop\tmp\chromedriver\chromedriver.exe || +# 当上下文切到原生,即不在web context时,关闭ChromeDriverSession,混合应用建议设置为true +recreateChromeDriverSessions = true || + +# 在web context时,是否使用原生进行截图,混合应用建议设置为true +nativeWebScreenshots = true + # systemport,如果使用UiAutomator2;端口范围为8200~8299,使用espresso,端口范围为8300~8399;并行设备都在同一个appium server上时确保每个设备唯一 systemports = 8200 || diff --git a/config/demoProject/app_ui_android_devices_info_demoProject.conf b/config/demoProject/app_ui_android_devices_info_demoProject.conf index 40d6d69..f8308be 100644 --- a/config/demoProject/app_ui_android_devices_info_demoProject.conf +++ b/config/demoProject/app_ui_android_devices_info_demoProject.conf @@ -39,6 +39,12 @@ chromeDriverPorts = 5200 || # 混合应用chromeDriver绝对路径,确保驱动版本与手机应用浏览器内核保持匹配,无需则放空 chromeDriverPaths = C:\Users\yanch\Desktop\tmp\chromedriver\chromedriver.exe || +# 当上下文切到原生,即不在web context时,关闭ChromeDriverSession,混合应用建议设置为true +recreateChromeDriverSessions = true || + +# 在web context时,是否使用原生进行截图,混合应用建议设置为true +nativeWebScreenshots = true + # systemport,如果使用UiAutomator2;端口范围为8200~8299,使用espresso,端口范围为8300~8399;并行设备都在同一个appium server上时确保每个设备唯一 systemports = 8200 || diff --git a/pojo/app_ui_devices_info.py b/pojo/app_ui_devices_info.py index 0f5b3f5..f3a76ad 100644 --- a/pojo/app_ui_devices_info.py +++ b/pojo/app_ui_devices_info.py @@ -1,5 +1,6 @@ # 作者 yanchunhuo # 创建时间 2019/12/26 9:17 +# github https://github.com/yanchunhuo from base.read_httpserver_config import Read_Http_Server_Config import os @@ -17,6 +18,8 @@ class APP_UI_Devices_Info: self.deviceNames = [] self.chromeDriverPorts = [] self.chromeDriverPaths = [] + self.recreateChromeDriverSessions = [] + self.nativeWebScreenshots = [] self.systemports = [] self.wdaLocalPorts = [] self.appPackages = [] @@ -76,6 +79,16 @@ class APP_UI_Devices_Info: desired_capabilities.update({'chromedriverPort': self.chromeDriverPorts[i].strip()}) if len(self.chromeDriverPaths): desired_capabilities.update({'chromedriverExecutable':self.chromeDriverPaths[i].strip()}) + if len(self.recreateChromeDriverSessions): + recreateChromeDriverSessions_value=False + if 'true' == self.recreateChromeDriverSessions[i].strip().lower(): + recreateChromeDriverSessions_value=True + desired_capabilities.update({'recreateChromeDriverSessions':recreateChromeDriverSessions_value}) + if len(self.nativeWebScreenshots): + nativeWebScreenshot=False + if 'true' == self.nativeWebScreenshots[i].strip().lower(): + nativeWebScreenshot=True + desired_capabilities.update({'nativeWebScreenshot':nativeWebScreenshot}) desired_capabilities.update({'systemport': self.systemports[i].strip()}) if len(self.wdaLocalPorts): desired_capabilities.update({'wdaLocalPort': self.wdaLocalPorts[i].strip()})