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

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

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

def app_nopaper_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.ubains.local.gviewer", "com.ubains.ub.gview.SplashActivity")
        app_drive.implicitly_wait(20)  # 设置缺省等待时间

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

        # 定位【会议签到】按钮元素，并点击按钮
        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.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[1]/android.widget.Button[2]")
        logging.info("定位【会议签到】成功")
        # 点击【会议签到】按钮
        meeting_button.click()
        logging.info("点击【会议签到】按钮成功")
        sleep(2)

        logging.info("定位【会议议题】按钮")
        meeting_issue_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.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.Button[2]")
        logging.info("定位【会议议题】按钮成功")
        meeting_issue_button.click()
        logging.info("点击【会议议题】按钮成功")
        sleep(2)

        logging.info("定位【议题文件1】元素")
        issue_file_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.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.TextView")
        logging.info("定位【议题文件1】元素成功")
        issue_file_button.click()
        logging.info("点击【议题文件1】元素成功")
        sleep(5)

        logging.info("定位【查看】按钮元素")
        issue_file = 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.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.Button")
        logging.info("定位【查看】按钮元素成功")
        issue_file.click()
        logging.info("点击【查看】按钮元素成功")
        sleep(8)
        app_drive.get_screenshot_as_file(
            r"D:\GithubData\自动化测试\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\noPaperless\议题文件查看截屏.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_nopaper_test()
