0
点赞
收藏
分享

微信扫一扫

Redis主从&哨兵模式

雅典娜的棒槌 2024-08-20 阅读 9
import psutil

# 获取当前windows , 所有进程信息名称, 并去重
def get_all_process():
    list_process = set()
    # 获取当前windows , 所有进程信息
    for proc in psutil.process_iter(['pid', 'name']):
        list_process.add(proc.info["name"])
    return list_process
# 后台是否有Hwork.exe , 如果没有就需要 启动Hwork,会比较耗时, 如果有就不需要
def hwork_start(path):
    all_process = get_all_process()
    if "Hwork.exe" in all_process:
        return True
    else:
        try:
            # 需要启动Hwork
            from pywinauto.application import Application
            # 启动
            Application(backend='uia').start(path)
            time.sleep(15)
            # 发送Alt+F4快捷键, 关闭窗口,关闭前台
            pyautogui.hotkey('alt', 'f4')

            return True
        except :
            return False
@pytest.fixture(scope="function", autouse=True)
def pc_start():
    # 添加启动参数
    desired_caps = {}
    desired_caps['app'] = r"D:\Users\duxiaowei\AppData\Local\Programs\Hwork\Hwork.exe"
    #
    if hwork_start(desired_caps['app']):
        # 客户端连接 Server,启动 Session 会话
        driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=desired_caps)
        # 默认全局隐式等待设置
        driver.implicitly_wait(20)
        # 设置启动检查等待,等待搜索
        errors = [NoSuchElementException, ElementNotInteractableException, ElementNotVisibleException]
        wait = WebDriverWait(driver, timeout=100, poll_frequency=2, ignored_exceptions=errors)
        wait.until(EC.visibility_of(driver.find_element(by=By.NAME, value="搜索")))
        # 强制等待
        time.sleep(2)
    else:
        print("请检查-Hwork程序是否启动成功!")

    return driver
举报

相关推荐

0 条评论