from time import sleep
from appium.webdriver.common.appiumby import AppiumBy
from hytest import SELENIUM_LOG_SCREEN

from 预定系统.Base.app_base import *
import logging

# 配置日志记录
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

def app_txcent_test():
    app_drive = None
    try:
        # 腾讯："com.tencent.wemeet.app"   ".StartupActivity"
        app_drive = app_setup_driver("Android", "7.1.2", "127.0.0.1:62001", "com.tencent.wemeet.app", ".StartupActivity")
        app_drive.implicitly_wait(20)  # 设置缺省等待时间

        # 使用显式等待来等待元素出现
        logging.info("等待登录页加载...")

        # 定位第一场会议按钮元素，并点击按钮
        logging.info("尝试定位【会议名称】按钮元素，并点击按钮")
        meeting_button = app_drive.find_element(AppiumBy.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.widget.LinearLayout[1]/android.view.ViewGroup/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[4]/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat[1]/android.view.ViewGroup/android.widget.TextView")
        logging.info("定位会议成功")
        # 点击【加入会议】按钮
        meeting_button.click()
        logging.info("点击【会议】按钮成功")
        sleep(2)

        # 点击【加入会议】按钮
        logging.info("尝试定位【加入会议】按钮元素，并点击按钮")
        join_meeting_button = app_drive.find_element(AppiumBy.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat/androidx.appcompat.widget.LinearLayoutCompat/android.widget.TextView")
        logging.info("定位【加入会议】按钮成功")
        join_meeting_button.click()
        logging.info("点击【加入会议】按钮成功")
        sleep(8)
        app_drive.get_screenshot_as_file(
            r"D:\GithubData\自动化测试\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Tx_meeting\会场控制截屏.png")

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

    finally:
        if app_drive:
            input('**** 按任意键退出..')
            app_drive.quit()
            logging.info("驱动程序已退出。")

if __name__ == '__main__':
    app_txcent_test()
