from appium.webdriver.common.appiumby import AppiumBy
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
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", "12", "RedmiK30Pro", "com.tencent.wemeet.app", ".StartupActivity")
        app_drive.implicitly_wait(20)  # 设置缺省等待时间

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

        # 定位【加入会议】按钮元素，并点击按钮
        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.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.LinearLayout[1]/android.widget.ImageView")
        logging.info("定位【加入会议】按钮成功")
        # 点击【加入会议】按钮
        join_meeting_button.click()
        logging.info("点击【加入会议】按钮成功")

    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()
    # match()
