import psutil
def get_all_process():
list_process = set()
for proc in psutil.process_iter(['pid', 'name']):
list_process.add(proc.info["name"])
return list_process
def hwork_start(path):
all_process = get_all_process()
if "Hwork.exe" in all_process:
return True
else:
try:
from pywinauto.application import Application
Application(backend='uia').start(path)
time.sleep(15)
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']):
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