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