01无纸化同屏测试.py 5.9 KB
from 预定系统.Base.app_base import *
import logging

# 配置日志记录

class same_screen_share_001:
    """
        执行指令:
            1.cd 预定系统
            2.hytest --report_title 会议预约测试报告 --report_url_prefix http://nat.ubainsyun.com:31133 --tag 无纸化同屏
    """
    tags = ['无纸化同屏']

    def teststeps(self):
        wd = GSTORE['wd']
        app_drive1 = None
        app_drive2 = None

        try:
            # 初始化第一个设备
            app_drive1 = app_setup_driver("Android", "7.1.2", "展厅无纸化设备1.0", "com.ubains.system.develop.mqtt", "com.ubains.system.activity.RouterActivity","192.168.5.156:5555")
            app_drive1.implicitly_wait(20)  # 设置缺省等待时间

            # 初始化第二个设备
            app_drive2 = app_setup_driver("Android", "7.1.2", "展厅无纸化设备1.0", "com.ubains.system.develop.mqtt", "com.ubains.system.activity.RouterActivity","192.168.5.157:5555")
            app_drive2.implicitly_wait(20)  # 设置缺省等待时间
            # 使用显式等待来等待元素出现
            logging.info(f"等待登录页加载.")
            sleep(10)

            # 进入后台设置界面
            logging.info(f"尝试进入后台设置")
            back_setting_button = app_drive1.find_element(AppiumBy.XPATH,
                                                         '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.RelativeLayout[3]/android.widget.TextView')
            back_setting_button.click()
            sleep(5)
            setting_button = app_drive1.find_element(AppiumBy.XPATH,
                                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[2]')
            setting_button.click()
            sleep(5)

            # 输入管理员密码点击【确定】按钮
            logging.info(f"尝试输入管理员密码点击【确定】")
            admin_pwd_input = app_drive1.find_element(AppiumBy.XPATH,
                                                     '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/androidx.appcompat.widget.LinearLayoutCompat/android.widget.EditText')
            admin_pwd_input.send_keys("000000")
            sleep(3)

            # 点击确定按钮
            confirm_button = app_drive1.find_element(AppiumBy.XPATH,
                                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.Button[2]')
            confirm_button.click()
            sleep(5)

            # 先截取另一台设备的界面做参照物
            INFO(f"这是设备B的界面")
            SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "No_PaperLess", "同屏前-无纸化设备B界面截屏")
            app_drive2.get_screenshot_as_file(
                r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\同屏前-无纸化设备B界面截屏.png")

            # 进入【同屏和视频服务】界面
            logging.info(f"进入【同屏和视频服务】")
            same_screen_module = app_drive1.find_element(AppiumBy.XPATH,
                                                        '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[5]/android.widget.TextView')
            same_screen_module.click()
            sleep(2)

            # 点击右上角【开始】按钮
            same_screen_button = app_drive1.find_element(AppiumBy.XPATH,
                                                        '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.widget.Button[1]')
            same_screen_button.click()
            sleep(3)

            # 截取设备A和设备B的同屏画面截屏
            INFO(f"这是设备A开启同屏共享的界面")
            SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "No_PaperLess", "同屏后-无纸化设备A界面截屏")
            app_drive1.get_screenshot_as_file(
                r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\同屏后-无纸化设备A界面截屏.png")

            INFO(f"这是设备B开启同屏共享的界面")
            SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "No_PaperLess", "同屏后-无纸化设备B界面截屏")
            app_drive2.get_screenshot_as_file(
                r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\No_PaperLess\同屏后-无纸化设备B界面截屏.png")

            # 调用图片对比函数判断相似度
            match_text = compare_images_feature_matching(
                r"/预定系统/reports/imgs/Exhibit_Inspect/No_PaperLess/DeviceA-ShareScreen.png",
                r"/预定系统/reports/imgs/Exhibit_Inspect/No_PaperLess/DeviceB-ShareScreen.png")
            INFO(f"图片相似度:{match_text}")
            # CHECK_POINT("校验同屏功能是否成功", match_text == True)

        except Exception as e:
            logging.error(f"发生错误: {e}", exc_info=True)