提交 7607bced authored 作者: 陈泽健's avatar 陈泽健

根据展厅预定系统的巡检流程输出脚本程序。进一步调试会控界面部分元素定位失败的问题以及议题文件上传失败的问题。调试appium移动端脚本,控制手机进入腾讯会议查看会控界面是否正常

上级 d2728fdf
from appium.options.android import UiAutomator2Options
import logging
from selenium import webdriver
def app_setup_driver(platformName, platformVersion, deviceName, appPackage, appActivity):
desired_caps = {
'platformName': platformName, # 被测手机是安卓
'platformVersion': platformVersion, # 手机安卓版本,如果是鸿蒙系统,依次尝试 12、11、10 这些版本号
'deviceName': deviceName, # 设备名,安卓手机可以随意填写
'appPackage': appPackage, # 启动APP Package名称
'appActivity': appActivity, # 启动Activity名称
'unicodeKeyboard': True, # 自动化需要输入中文时填True
'resetKeyboard': True, # 执行完程序恢复原来输入法
'noReset': True, # 不要重置App
'newCommandTimeout': 6000,
'automationName': 'UiAutomator2',
'skipUnlock': True,
'autoGrantPermissions': True
}
logging.info(f"desired_caps参数:{desired_caps}")
try:
logging.info("正在初始化 Appium 驱动程序...")
driver = webdriver.Remote('http://localhost:4723/wd/hub',
options=UiAutomator2Options().load_capabilities(desired_caps))
logging.info("Appium 驱动程序初始化成功。")
return driver
except Exception as e:
logging.error(f"初始化驱动程序失败: {e}")
raise
\ No newline at end of file
......@@ -16,13 +16,14 @@ from selenium.webdriver.chrome.service import Service as ChromeService
from hytest import *
from selenium import webdriver
from selenium.common import TimeoutException, NoSuchElementException, ElementNotInteractableException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from urllib.parse import urlencode
from datetime import datetime
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -214,6 +215,7 @@ def issue_send_and_upload(wd , issue_num, issue_name, issue_file_name):
"//div[@class='topicsHandleButton uploadFile']"),
wd)
sleep(2)
INFO("点击【选择文件】按钮")
upload_button = WebDriverWait(wd, 60).until(
EC.element_to_be_clickable((By.XPATH, "//label[@id='global-uploader-btn']")))
INFO("选择议题文件上传")
......@@ -649,4 +651,33 @@ def get_reportfile_send_dingding(report_title, report_url_prefix):
logging.info("自动化测试完成。")
# if __name__ == '__main__':
# get_reportfile_send_dingding("测试","http://192.168.1.166")
\ No newline at end of file
# get_reportfile_send_dingding("测试","http://192.168.1.166")
def double_click_and_drag(source_element_locator, target_element_locator, wd):
"""
实现元素从source_element双击后拖拽到target_element的功能
:param wd: WebDriver实例
:param source_element_locator: 拖拽起始元素的定位器
:param target_element_locator: 拖拽目标元素的定位器
"""
try:
# 找到源元素和目标元素
source_element = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(source_element_locator))
target_element = WebDriverWait(wd, 60).until(EC.visibility_of_element_located(target_element_locator))
# 使用ActionChains执行双击操作
actions = ActionChains(wd)
actions.double_click(source_element).perform()
# 等待双击操作生效
WebDriverWait(wd, 10).until(EC.staleness_of(source_element))
# 使用ActionChains执行拖拽操作
actions.drag_and_drop(source_element, target_element).perform()
except TimeoutException as e:
logging.error(f"元素查找超时: {e}")
except NoSuchElementException as e:
logging.error(f"元素未找到: {e}")
except Exception as e:
logging.error(f"发生未知错误: {e}")
\ No newline at end of file
......@@ -88,4 +88,6 @@
- 调整admin_login函数为传参形式。
- 补充展厅巡检流程,预定SMC视讯会议,并进行安卓信息截屏。后续补充会控操作功能流程进行调试。
26. 2024-12-10
- 调整browser_init函数改为传参方式传入登录页面URL,调整相关脚本的函数调用。
\ No newline at end of file
- 调整browser_init函数改为传参方式传入登录页面URL,调整相关脚本的函数调用。
- 根据展厅预定系统的巡检流程输出脚本程序。进一步调试会控界面部分元素定位失败的问题以及议题文件上传失败的问题。
- 调试appium移动端脚本,控制手机进入腾讯会议查看会控界面是否正常
\ No newline at end of file
from 预定系统.Base.app_base import *
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import logging
# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def app_txcent_test():
app_drive = None
try:
app_drive = app_setup_driver("Android", "12", "RedmiK30Pro", "com.tencent.wemeet.app", ".StartupActivity")
app_drive.implicitly_wait(20) # 设置缺省等待时间
# 使用显式等待来等待元素出现
logging.info("等待登录页加载...")
WebDriverWait(app_drive, 60).until(EC.element_to_be_clickable((By.ID, "f7"))).click()
sleep(2)
WebDriverWait(app_drive, 60).until(EC.element_to_be_clickable((By.ID, "kr"))).click()
sleep(2)
WebDriverWait(app_drive, 60).until(EC.element_to_be_clickable((By.ID, "kr"))).send_keys("562483854")
sleep(5)
WebDriverWait(app_drive, 60).until(EC.element_to_be_clickable((By.ID, "y0"))).click()
except Exception as e:
logging.error(f"发生错误: {e}")
finally:
if app_drive: # 修改这里为 app_drive 而不是 driver
input('**** 按任意键退出..')
app_drive.quit()
logging.info("驱动程序已退出。")
if __name__ == '__main__':
app_txcent_test()
\ No newline at end of file
### Appium一些相关参数获取:
1. 如何获取手机某一程序的应用包名
使用adb命令进行获取,手机打开应用,adb命令行输入adb shell dumpsys activity recents | find "intent={" 找到第一行的cmp的key值appPackage/appActivity
![img.png](img.png)
### 运行Appium时遇到的问题总结:
1. 问题:运行Appium报错:
Failed to initialize driver: Message: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command ''C:\\Program Files\\androidsdk\\platform-tools\\adb.exe' -P 5037 -s f0b5fab1 shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Exception occurred while executing 'delete':
解决方法:可能是权限不足导致,在adb命令行窗口输入adb root赋予权限。再执行程序
\ No newline at end of file
......@@ -4,4 +4,4 @@ tunnels:
nat1:
remote_port: 31133
proto:
tcp: "192.168.1.166:80"
\ No newline at end of file
tcp: "192.168.1.109:80"
\ No newline at end of file
name,conference_name,message_name,message_type,book_type,repetitive_cycle,host_name,message_content,issue_name,book_start_time,book_end_time,inside_participant_name,outside_participant_name,outside_participant_phone,save_template,template_name,message_notification,notification_method,check_text
展厅巡检_001,产研中心会议室,展厅巡检测试,SMC3.0,普通会议,每天,陈泽键,这是会议内容哈哈,议题1,20:15,20:30,admin@CZJ,陈泽坚,17319004674,否,这是模板,开会前一天提醒,短信,预定成功
\ No newline at end of file
name,conference_name,message_name,book_type,issue_name,book_start_time,book_end_time,inside_participant_name,message_notification,notification_method,check_text
展厅巡检_001,展厅会议室,展厅巡检测试,普通会议,议题1,12:00,12:15,CZJ,开会前一天提醒,短信,预定成功
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论