def test_load_session(self): app = Application().start("FestEngine.exe") time.sleep(1) app['Welcome to Fest Engine'].OK.click() time.sleep(0.5) settings = app.Settings settings['Current Fest:Edit'].set_text( os.path.abspath(sample_fest_path)) time.sleep(0.5) settings.Load.click() time.sleep(1) app['Restart Required'].Button2.click() time.sleep(0.5) app.wxWindowNR.menu_select("Main -> Exit") app.wait_for_process_exit(1) app = Application().start("FestEngine.exe") main_window = app.wxWindowNR self.assertTrue(main_window.GridWindow.exists()) self.assertTrue('Loaded %d items' % items_number in main_window.StatusBar.texts()) main_window.menu_select("Main -> Show Log") time.sleep(1) log_text = app["FestEngine Log"].Edit.text_block() self.assertTrue(log_text.strip() == "Init", "Errors in log:") main_window.close()
def test_should_return_not_running_if_not_started(self): """Tests that works on new instance is_process_running/wait_for_process_exit can be called on not started/disconnected instance """ app = Application() app.wait_for_process_exit(timeout=10, retry_interval=1) self.assertFalse(app.is_process_running())
def test_process_is_running(self): """Tests process is running and wait for exit function""" app = Application() app.start(_notepad_exe()) app.UntitledNotepad.wait("ready") self.assertTrue(app.is_process_running()) self.assertRaises(TimeoutError, lambda: app.wait_for_process_exit(timeout=5, retry_interval=1)) app.kill() app.wait_for_process_exit() self.assertFalse(app.is_process_running())
def test_should_return_not_running_if_failed_to_open_process( self, func_open_process): """Tests error handling wehn OpenProcess return 0 handle Checks is_process_running and wait_for_process_exit works even if OpenProcess returns 0 handle without exception """ func_open_process.return_value = pywintypes.HANDLE(0) app = Application() app.start(_notepad_exe()) app.wait_for_process_exit(timeout=10, retry_interval=1) self.assertFalse(app.is_process_running()) app.kill()
def convert_coh3_to_edf( executable_path: str, eeg_path: str, edf_path: str = None, overwrite: bool = False, depth: int = 3, ): """ Convert Coherence 3 (.eeg) to EDF file format. Args: executable_path: path to the converter executable. eeg_path: path to the eeg file to convert. edf_path: path to the converted EDF file. """ if edf_path is None: edf_path = eeg_path[:-4] + '.EDF' overwrite_edf = os.path.isfile(edf_path) if not overwrite and overwrite_edf: return char_at_424 = b'' with open(eeg_path, 'rb') as file_: file_.seek(424) char_at_424 = file_.read(1) # Open the executable path = '' try: app = Application(backend='uia').start(executable_path) app = Application().connect(title='Source (C:\\EEG2)') # Select file in folder if char_at_424 != b'\x00': if hasattr(sys, 'frozen'): tmpdir = os.path.dirname(os.path.abspath(sys.executable)) else: tmpdir = os.path.dirname(os.path.abspath(__file__)) path = os.path.realpath( os.path.join(tmpdir, 'temp', os.path.basename(eeg_path)), ) ensure_path(os.path.dirname(path)) src = r'\\?\{0}'.format(eeg_path) dst = r'\\?\{0}'.format(path) try: shutil.copyfile(src, dst) except OSError: shutil.copyfile(eeg_path, path) eeg_path = path with open(eeg_path, 'rb+') as file_: file_.seek(424) file_.write(b'\x00') app.Dialog.child_window(class_name='ComboBoxEx32').child_window( class_name="Edit", ).set_text(eeg_path) # Click on Open app.Dialog.Button.click() # Start conversion app.TEDFForm.child_window( title="UTF-8", class_name="TGroupButton", ).click() app.TEDFForm.child_window( title="EDF+", class_name="TGroupButton", ).click() app.TEDFForm.child_window(title="OK", class_name="TBitBtn").click() # Saving path app.Destination.wait('exists ready') app.Destination['ComboBox2'].child_window( class_name='Edit', ).set_text(edf_path) # Indicate where to save the file app.Destination['Button1'].click() # If the file already exist overwrite it. if overwrite_edf: app['Dialog0'].wait('exists') if app['Dialog0'].texts()[0].startswith('Confirm'): app['Dialog0'].Button.click() # Wait for the process to complete app.wait_for_process_exit(timeout=300) # If multiple instances are runing, kill them all except ( pywinauto.findwindows.ElementAmbiguousError, pywinauto.findbestmatch.MatchError, ): traceback.print_exc() # Only use one instance at a time os.system( 'taskkill /f /im {0}'.format( os.path.basename(executable_path), ), ) if depth: convert_coh3_to_edf( executable_path, eeg_path, edf_path, overwrite, depth - 1, ) # If the windows if not found, relaunch the program except pywinauto.findwindows.ElementNotFoundError: traceback.print_exc() if depth: convert_coh3_to_edf( executable_path, eeg_path, edf_path, overwrite, depth - 1, ) finally: # Remove temp file and dir if it exits if os.path.dirname(path) != '': if os.path.exists(os.path.dirname(path)): shutil.rmtree(os.path.dirname(path))
from pywinauto.application import Application from ElementInfoWrapper import ElementInfoWrapper import time app = Application(backend="uia").connect( path="C:\Program Files (x86)\XunjiePDFConverter\pdfconverter.exe") #app = Application(backend="uia").start("notepad.exe") app.wait_for_process_exit() print("process: %i" % app.process) appWrapper = ElementInfoWrapper(app) #Menu # menuWrapper = appWrapper.filterTop(class_name="Qt5QWindowIcon",control_type="Pane")\ # .filterDecendent(control_type="Custom",contain_point=(625,30)) # PDF_change = menuWrapper.filterDecendent(control_type="Button",contain_point=(240,30)).getObject() # PDF_operate = menuWrapper.filterDecendent(control_type="Button",contain_point=(330,30)).getObject() # WPS_change = menuWrapper.filterDecendent(control_type="Button",contain_point=(420,30)).getObject() # WORD_change = menuWrapper.filterDecendent(control_type="Button",contain_point=(520,30)).getObject() # CAD_change = menuWrapper.filterDecendent(control_type="Button",contain_point=(620,30)).getObject() # SPECIAL_change = menuWrapper.filterDecendent(control_type="Button",contain_point=(710,30)).getObject() # # PDF_change.draw_outline() # PDF_operate.draw_outline() # WPS_change.draw_outline() # WORD_change.draw_outline() # CAD_change.draw_outline() # SPECIAL_change.draw_outline()