def testWaitCPUUsageLower(self): if is_x64_Python() != is_x64_OS(): return None app = Application().Start(r'explorer.exe') WaitUntil(30, 0.5, lambda: len(findwindows.find_windows(active_only=True, class_name='CabinetWClass')) > 0) handle = findwindows.find_windows(active_only=True, class_name='CabinetWClass')[-1] window = WindowSpecification({'handle': handle, }) explorer = Application().Connect(process=window.ProcessID()) try: window.AddressBandRoot.ClickInput(double=True) window.Edit.SetEditText(r'Control Panel\Programs\Programs and Features') window.TypeKeys(r'{ENTER 2}', set_foreground=False) WaitUntil(30, 0.5, lambda: len(findwindows.find_windows(active_only=True, title='Programs and Features', class_name='CabinetWClass')) > 0) explorer.WaitCPUUsageLower(threshold=2.5, timeout=40, usage_interval=2) installed_programs = window.FolderView.Texts()[1:] programs_list = ','.join(installed_programs) if ('Microsoft' not in programs_list) and ('Python' not in programs_list): HwndWrapper.ImageGrab.grab().save(r'explorer_screenshot.jpg') HwndWrapper.ActionLogger().log('\ninstalled_programs:\n') for prog in installed_programs: HwndWrapper.ActionLogger().log(prog) self.assertEqual(('Microsoft' in programs_list) or ('Python' in programs_list), True) finally: window.Close(2.0)
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start_(r"C:\Windows\System32\notepad.exe") else: self.app.start_(r"C:\Windows\SysWOW64\notepad.exe") # Get the old font self.app.UntitledNotepad.Wait('ready', 50) self.app.UntitledNotepad.MenuSelect("Format->Font...") self.app.Font.Wait("visible", 50) self.old_font = self.app.Font.FontComboBox.SelectedIndex() self.old_font_style = self.app.Font.FontStyleCombo.SelectedIndex() # ensure we have the correct settings for this test self.app.Font.FontStyleCombo.Select(0) self.app.Font.FontComboBox.Select("Lucida Console") self.app.Font.OK.Click() self.dlg = self.app.Window_(title='Untitled - Notepad', class_name='Notepad') self.ctrl = HwndWrapper(self.dlg.Edit.handle) self.dlg.edit.SetEditText("Here is some text\r\n and some more")
def test_is64bitprocess(self): "Make sure a 64-bit process detection returns correct results" if is_x64_OS(): # Test a 32-bit app running on x64 expected_is64bit = False if is_x64_Python(): exe32bit = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples\RowList.exe") app = Application().start_(exe32bit, timeout=20) pid = app.RowListSampleApplication.ProcessID() res_is64bit = is64bitprocess(pid) try: self.assertEquals(expected_is64bit, res_is64bit) finally: # make sure to close an additional app we have opened app.kill_() # setup expected for a 64-bit app on x64 expected_is64bit = True else: # setup expected for a 32-bit app on x86 expected_is64bit = False # test native Notepad app res_is64bit = is64bitprocess(self.app.UntitledNotepad.ProcessID()) self.assertEquals(expected_is64bit, res_is64bit)
def testClickVisibleIcon(self): """ Test minimizing a sample app into the visible area of the tray and restoring the app back """ if is_x64_Python() != is_x64_OS(): # We don't run this test for mixed cases: # a 32-bit Python process can't interact with # a 64-bit explorer process (taskbar) and vice versa return # Make sure that the hidden icons area is disabled orig_hid_state = _toggle_notification_area_icons( show_all=True, debug_img="%s_01.jpg" % (self.id())) self.dlg.Minimize() self.dlg.WaitNot('active') # click in the visible area taskbar.explorer_app.WaitCPUUsageLower(threshold=5, timeout=40) taskbar.ClickSystemTrayIcon('MFCTrayDemo', double=True) self.dlg.Wait('active', timeout=40) # Restore Notification Area settings _toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02.jpg" % (self.id()))
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start_(r"C:\Windows\System32\notepad.exe") else: self.app.start_(r"C:\Windows\SysWOW64\notepad.exe") # Get the old font self.app.UntitledNotepad.MenuSelect("Format->Font") self.old_font = self.app.Font.FontComboBox.SelectedIndex() self.old_font_style = self.app.Font.FontStyleCombo.SelectedIndex() # ensure we have the correct settings for this test self.app.Font.FontStyleCombo.Select(0) self.app.Font.FontComboBox.Select("Lucida Console") self.app.Font.OK.Click() self.dlg = self.app.Window_(title='Untitled - Notepad', class_name='Notepad') self.ctrl = HwndWrapper(self.dlg.Edit.handle) self.dlg.edit.SetEditText("Here is some text\r\n and some more")
def test_is64bitprocess(self): """Make sure a 64-bit process detection returns correct results""" if is_x64_OS(): # Test a 32-bit app running on x64 expected_is64bit = False if is_x64_Python(): exe32bit = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples\RowList.exe") app = Application().start(exe32bit, timeout=20) pid = app.RowListSampleApplication.process_id() res_is64bit = is64bitprocess(pid) try: self.assertEquals(expected_is64bit, res_is64bit) finally: # make sure to close an additional app we have opened app.kill_() # setup expected for a 64-bit app on x64 expected_is64bit = True else: # setup expected for a 32-bit app on x86 expected_is64bit = False # test native Notepad app res_is64bit = is64bitprocess(self.app.UntitledNotepad.process_id()) self.assertEquals(expected_is64bit, res_is64bit)
def testClickVisibleIcon(self): """ Test minimizing a sample app into the visible area of the tray and restoring the app back """ if is_x64_Python() != is_x64_OS(): # We don't run this test for mixed cases: # a 32-bit Python process can't interact with # a 64-bit explorer process (taskbar) and vice versa return # Make sure that the hidden icons area is disabled orig_hid_state = _toggle_notification_area_icons( show_all=True, debug_img="%s_01" % (self.id()) ) self.dlg.Minimize() _wait_minimized(self.dlg) # click in the visible area taskbar.explorer_app.WaitCPUUsageLower(threshold=5, timeout=self.tm) taskbar.ClickSystemTrayIcon('MFCTrayDemo', double=True) self.dlg.Wait('active', timeout=self.tm) # Restore Notification Area settings _toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02" % (self.id()))
def setUp(self): """Set some data and ensure the application is in the state we want it.""" mfc_samples_folder = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): self.sample_exe = os.path.join(mfc_samples_folder, "CmnCtrl1.exe") else: self.sample_exe = os.path.join(mfc_samples_folder, 'x64', "CmnCtrl1.exe")
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.prev_warn = warnings.showwarning def no_warnings(*args, **kwargs): pass warnings.showwarning = no_warnings if is_x64_Python() or not is_x64_OS(): self.notepad_subpath = r"system32\notepad.exe" else: self.notepad_subpath = r"SysWOW64\notepad.exe"
def _get_safe_point_to_click(self): """Run notepad.exe to have a safe area for mouse clicks""" mfc_samples_folder = os.path.join( os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): mfc_samples_folder = os.path.join(mfc_samples_folder, 'x64') sample_exe = os.path.join(mfc_samples_folder, "CmnCtrl1.exe") self.app = Application() self.app.start(sample_exe) self.app.CommonControlsSample.wait("ready") return self.app.CommonControlsSample.rectangle().mid_point()
def _get_safe_point_to_click(self): """Run notepad.exe to have a safe area for mouse clicks""" mfc_samples_folder = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): mfc_samples_folder = os.path.join(mfc_samples_folder, 'x64') sample_exe = os.path.join(mfc_samples_folder, "CmnCtrl1.exe") self.app = Application() self.app.start(sample_exe) self.app.CommonControlsSample.wait("ready") return self.app.CommonControlsSample.rectangle().mid_point()
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start(r"C:\Windows\System32\calc.exe") else: self.app.start(r"C:\Windows\SysWOW64\calc.exe") self.calc = self.app.Calculator self.calc.MenuSelect("View->Scientific")
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start(r"C:\Windows\System32\notepad.exe") else: self.app.start(r"C:\Windows\SysWOW64\notepad.exe") self.dlg = self.app.UntitledNotepad self.ctrl = HwndWrapper(self.dlg.Edit.handle)
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start_(r"C:\Windows\System32\notepad.exe") else: self.app.start_(r"C:\Windows\SysWOW64\notepad.exe") self.dlg = self.app.UntitledNotepad self.ctrl = HwndWrapper(self.dlg.Edit.handle)
def test_wait_cpu_usage_lower(self): """Test that wait_cpu_usage_lower() works correctly""" if is_x64_Python() != is_x64_OS(): return None Application().Start(r'explorer.exe') def _cabinetwclass_exist(): "Verify if at least one active 'CabinetWClass' window is created" l = findwindows.find_elements(active_only=True, class_name='CabinetWClass') return (len(l) > 0) WaitUntil(40, 0.5, _cabinetwclass_exist) handle = findwindows.find_elements( active_only=True, class_name='CabinetWClass')[-1].handle window = WindowSpecification({ 'handle': handle, 'backend': 'win32', }) explorer = Application().Connect(process=window.process_id()) try: explorer.WaitCPUUsageLower(threshold=1.5, timeout=60, usage_interval=2) window.AddressBandRoot.ClickInput() window.TypeKeys(r'Control Panel\Programs\Programs and Features', with_spaces=True, set_foreground=True) window.TypeKeys(r'{ENTER}', set_foreground=False) WaitUntil( 40, 0.5, lambda: len( findwindows.find_elements(active_only=True, title='Programs and Features', class_name='CabinetWClass')) > 0) explorer.WaitCPUUsageLower(threshold=1.5, timeout=60, usage_interval=2) installed_programs = window.FolderView.texts()[1:] programs_list = ','.join(installed_programs) if ('Microsoft' not in programs_list) and ('Python' not in programs_list): hwndwrapper.ImageGrab.grab().save(r'explorer_screenshot.jpg') hwndwrapper.ActionLogger().log('\ninstalled_programs:\n') for prog in installed_programs: hwndwrapper.ActionLogger().log(prog) self.assertEqual(('Microsoft' in programs_list) or ('Python' in programs_list), True) finally: window.Close(2.0)
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start_(r"C:\Windows\System32\calc.exe") else: self.app.start_(r"C:\Windows\SysWOW64\calc.exe") self.dlg = self.app.Calculator self.dlg.MenuSelect('View->Scientific\tAlt+2') self.ctrl = HwndWrapper(self.dlg.Button2.handle) # Backspace
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start(r"C:\Windows\System32\calc.exe") else: self.app.start(r"C:\Windows\SysWOW64\calc.exe") self.calc = self.app.CalcFrame # write out the XML so that we can read it in later self.app.Calculator.WriteToXML("ref_controls.xml")
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application self.app = Application() if is_x64_Python() or not is_x64_OS(): self.app.start(r"C:\Windows\System32\calc.exe") else: self.app.start(r"C:\Windows\SysWOW64\calc.exe") self.dlg = self.app.Calculator self.dlg.MenuSelect('View->Scientific\tAlt+2') self.ctrl = HwndWrapper(self.dlg.Button2.handle) # Backspace
def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # TODO: re-write the whole test self.app = Application(backend="native") if is_x64_Python() or not is_x64_OS(): self.app.start(r"C:\Windows\System32\calc.exe") else: self.app.start(r"C:\Windows\SysWOW64\calc.exe") self.dlg = self.app.Calculator self.handle = self.dlg.handle self.dlg.MenuSelect('View->Scientific\tAlt+2') self.ctrl = UIAElementInfo(self.dlg.handle)
def __init__(self, pid, backend_name, dll_name, is_unicode=False): """Constructor inject dll (one application - one class instanse)""" self.is_unicode = is_unicode self.pid = pid if not sysinfo.is_x64_Python() == is64bitprocess(self.pid): raise RuntimeError( "Application and Python must be both 32-bit or both 64-bit") self.h_process = self._get_process_handle(self.pid) self.dll_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'backends', backend_name, 'bin', 'x{}'.format("64" if is64bitprocess(self.pid) else "86"), '{}.dll'.format(dll_name)).encode( 'utf-16' if self.is_unicode else locale.getpreferredencoding()) self._inject_dll_to_process()
def test_app(filename): mfc_samples_folder = os.path.join(os.path.dirname(__file__), SAMPLE_APPS_PATH) if is_x64_Python(): sample_exe = os.path.join(mfc_samples_folder, "x64", filename) else: sample_exe = os.path.join(mfc_samples_folder, filename) app = Application().start(sample_exe, timeout=3) app_path = os.path.normpath(sample_exe).encode('unicode-escape') try: yield app, app_path except: # Re-raise AssertionError and others raise finally: app.kill_()
def testConnect_path(self): "Test that connect_() works with a path" app1 = Application() app1.start(_notepad_exe()) app_conn = Application() app_conn.connect(path=self.notepad_subpath) self.assertEqual(app1.process, app_conn.process) app_conn = Application() if is_x64_Python() or not is_x64_OS(): app_conn.connect(path=r"c:\windows\system32\notepad.exe") else: app_conn.connect(path=r"c:\windows\syswow64\notepad.exe") self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def testConnect_path(self): "Test that connect_() works with a path" app1 = Application() app1.start_(_notepad_exe()) app_conn = Application() app_conn.connect_(path = self.notepad_subpath) self.assertEqual(app1.process, app_conn.process) app_conn = Application() if is_x64_Python() or not is_x64_OS(): app_conn.connect_(path = r"c:\windows\system32\notepad.exe") else: app_conn.connect_(path = r"c:\windows\syswow64\notepad.exe") self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def setUp(self): """Set some data and ensure the application is in the state we want""" # Force Display User and Deprecation warnings every time # Python 3.3+nose/unittest trys really hard to suppress them for warning in (UserWarning, PendingDeprecationWarning): warnings.simplefilter('always', warning) mfc_samples_folder = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): self.sample_exe = os.path.join(mfc_samples_folder, "x64", "CmnCtrl1.exe") self.sample_exe_inverted_bitness = os.path.join( mfc_samples_folder, "CmnCtrl1.exe") else: self.sample_exe = os.path.join(mfc_samples_folder, "CmnCtrl1.exe") self.sample_exe_inverted_bitness = os.path.join( mfc_samples_folder, "x64", "CmnCtrl1.exe")
def testClickVisibleIcon(self): """ Test minimizing a sample app into the visible area of the tray and restoring the app back """ if is_x64_Python() != is_x64_OS(): # We don't run this test for mixed cases: # a 32-bit Python process can't interact with # a 64-bit explorer process (taskbar) and vice versa return # Make sure that the hidden icons area is disabled orig_hid_state = _toggle_notification_area_icons( show_all=True, debug_img="%s_01" % (self.id()) ) self.dlg.minimize() _wait_minimized(self.dlg) menu_window = [None] # Click in the visible area and wait for a popup menu def _show_popup_menu(): taskbar.explorer_app.wait_cpu_usage_lower(threshold=5, timeout=self.tm) taskbar.RightClickSystemTrayIcon('MFCTrayDemo') menu = self.app.top_window().children()[0] res = isinstance(menu, ToolbarWrapper) and menu.is_visible() menu_window[0] = menu return res wait_until(self.tm, _retry_interval, _show_popup_menu) menu_window[0].menu_bar_click_input("#2", self.app) popup_window = self.app.top_window() hdl = self.dlg.popup_window() self.assertEqual(popup_window.handle, hdl) taskbar.ClickSystemTrayIcon('MFCTrayDemo', double=True) self.dlg.wait('active', timeout=self.tm) # Restore Notification Area settings _toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02" % (self.id()))
def setUp(self): """Set some data and ensure the application is in the state we want""" # Force Display User and Deprecation warnings every time # Python 3.3+nose/unittest trys really hard to suppress them for warning in (UserWarning, PendingDeprecationWarning): warnings.simplefilter('always', warning) mfc_samples_folder = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): self.sample_exe = os.path.join(mfc_samples_folder, "x64", "CmnCtrl1.exe") self.sample_exe_inverted_bitness = os.path.join(mfc_samples_folder, "CmnCtrl1.exe") else: self.sample_exe = os.path.join(mfc_samples_folder, "CmnCtrl1.exe") self.sample_exe_inverted_bitness = os.path.join(mfc_samples_folder, "x64", "CmnCtrl1.exe")
def __init__(self, app, is_unicode=False): """Constructor inject dll, set socket and hook (one application - one class instanse)""" self.app = app self.is_unicode = is_unicode self.pid = processid(self.app.handle) if not sysinfo.is_x64_Python() == is64bitprocess(self.pid): raise RuntimeError( "Application and Python must be both 32-bit or both 64-bit") self.h_process = self._get_process_handle(self.pid) self.dll_path = os.path.abspath("{0}pywinmsg{1}{2}.dll".format( dll_path, "64" if is64bitprocess(self.pid) else "32", "u" if self.is_unicode else "")) self._inject_dll_to_process() self.sock = socket(AF_INET, SOCK_DGRAM) self.sock.bind(('', 0)) port = self.sock.getsockname()[1] self._remote_call_int_param_func("InitSocket", port) self._remote_call_void_func("SetMsgHook")
def testClickHiddenIcon(self): """ Test minimizing a sample app into the hidden area of the tray and restoring the app back """ if is_x64_Python() != is_x64_OS(): # We don't run this test for mixed cases: # a 32-bit Python process can't interact with # a 64-bit explorer process (taskbar) and vice versa return # Make sure that the hidden icons area is enabled orig_hid_state = _toggle_notification_area_icons( show_all=False, debug_img="%s_01" % (self.id()) ) self.dlg.Minimize() _wait_minimized(self.dlg) # Run one more instance of the sample app # hopefully one of the icons moves into the hidden area self.app2 = Application() self.app2.start(os.path.join(mfc_samples_folder, u"TrayMenu.exe")) dlg2 = self.app2.TrayMenu dlg2.Wait('visible', timeout=self.tm) dlg2.Minimize() _wait_minimized(dlg2) # Click in the hidden area taskbar.explorer_app.WaitCPUUsageLower(threshold=5, timeout=40) taskbar.ClickHiddenSystemTrayIcon('MFCTrayDemo', double=True) self.dlg.Wait('visible', timeout=self.tm) # Restore Notification Area settings _toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02" % (self.id())) dlg2.SendMessage(win32defines.WM_CLOSE) self.app2 = None
def test_connect_path(self): """Test that connect_() works with a path""" app1 = Application() app1.start(_notepad_exe()) app_conn = Application() app_conn.connect(path=self.notepad_subpath) self.assertEqual(app1.process, app_conn.process) app_conn = Application() if is_x64_Python() or not is_x64_OS(): app_conn.connect(path=r"c:\windows\system32\notepad.exe") else: app_conn.connect(path=r"c:\windows\syswow64\notepad.exe") self.assertEqual(app1.process, app_conn.process) accessible_modules = process_get_modules() accessible_process_names = [os.path.basename(name.lower()) for process, name, cmdline in accessible_modules] self.assertEquals('notepad.exe' in accessible_process_names, True) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def testClickHiddenIcon(self): """ Test minimizing a sample app into the hidden area of the tray and restoring the app back """ if is_x64_Python() != is_x64_OS(): # We don't run this test for mixed cases: # a 32-bit Python process can't interact with # a 64-bit explorer process (taskbar) and vice versa return # Make sure that the hidden icons area is enabled orig_hid_state = _toggle_notification_area_icons( show_all=False, debug_img="%s_01" % (self.id()) ) self.dlg.Minimize() _wait_minimized(self.dlg) # Run one more instance of the sample app # hopefully one of the icons moves into the hidden area app2 = Application() app2.start(os.path.join(mfc_samples_folder, u"TrayMenu.exe")) dlg2 = app2.top_window_() dlg2.Wait('visible', timeout=self.tm) dlg2.Minimize() _wait_minimized(dlg2) # Click in the hidden area taskbar.explorer_app.WaitCPUUsageLower(threshold=5, timeout=40) taskbar.ClickHiddenSystemTrayIcon('MFCTrayDemo', double=True) self.dlg.Wait('visible', timeout=self.tm) # Restore Notification Area settings _toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02" % (self.id())) dlg2.SendMessage(win32defines.WM_CLOSE)
def testClickVisibleIcon(self): """ Test minimizing a sample app into the visible area of the tray and restoring the app back """ if is_x64_Python() != is_x64_OS(): # We don't run this test for mixed cases: # a 32-bit Python process can't interact with # a 64-bit explorer process (taskbar) and vice versa return # Make sure that the hidden icons area is disabled orig_hid_state = _toggle_notification_area_icons( show_all=True, debug_img="%s_01" % (self.id()) ) self.dlg.Minimize() _wait_minimized(self.dlg) # click in the visible area taskbar.explorer_app.WaitCPUUsageLower(threshold=5, timeout=self.tm) taskbar.RightClickSystemTrayIcon('MFCTrayDemo') # verify PopupWindow method menu_window = self.app.top_window_().Children()[0] WaitUntil(self.tm, _retry_interval, menu_window.IsVisible) menu_window.MenuBarClickInput("#2", self.app) popup_window = self.app.top_window_() hdl = self.dlg.PopupWindow() self.assertEquals(popup_window.handle, hdl) taskbar.ClickSystemTrayIcon('MFCTrayDemo', double=True) self.dlg.Wait('active', timeout=self.tm) # Restore Notification Area settings _toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02" % (self.id()))
def test_wait_cpu_usage_lower(self): """Test that wait_cpu_usage_lower() works correctly""" if is_x64_Python() != is_x64_OS(): return None app = Application().Start(r'explorer.exe') def _cabinetwclass_exist(): "Verify if at least one active 'CabinetWClass' window is created" l = findwindows.find_elements(active_only = True, class_name = 'CabinetWClass') return (len(l) > 0) WaitUntil(40, 0.5, _cabinetwclass_exist) handle = findwindows.find_elements(active_only = True, class_name = 'CabinetWClass')[-1].handle window = WindowSpecification({'handle': handle, 'backend': 'native', }) explorer = Application().Connect(process = window.process_id()) try: explorer.WaitCPUUsageLower(threshold = 1.5, timeout = 60, usage_interval = 2) window.AddressBandRoot.ClickInput() window.TypeKeys(r'Control Panel\Programs\Programs and Features', with_spaces=True, set_foreground=True) window.TypeKeys(r'{ENTER}', set_foreground = False) WaitUntil(40, 0.5, lambda: len(findwindows.find_elements(active_only = True, title = 'Programs and Features', class_name='CabinetWClass')) > 0) explorer.WaitCPUUsageLower(threshold = 1.5, timeout = 60, usage_interval = 2) installed_programs = window.FolderView.texts()[1:] programs_list = ','.join(installed_programs) if ('Microsoft' not in programs_list) and ('Python' not in programs_list): HwndWrapper.ImageGrab.grab().save(r'explorer_screenshot.jpg') HwndWrapper.ActionLogger().log('\ninstalled_programs:\n') for prog in installed_programs: HwndWrapper.ActionLogger().log(prog) self.assertEqual(('Microsoft' in programs_list) or ('Python' in programs_list), True) finally: window.Close(2.0)
def _notepad_exe(): if is_x64_Python() or not is_x64_OS(): return r"C:\Windows\System32\notepad.exe" else: return r"C:\Windows\SysWOW64\notepad.exe"
from pywinauto.application import Application from pywinauto.controls.HwndWrapper import HwndWrapper, \ InvalidWindowHandle, GetDialogPropsFromHandle from pywinauto import win32structures, win32defines from pywinauto.findwindows import WindowNotFoundError from pywinauto.sysinfo import is_x64_Python, is_x64_OS from pywinauto.RemoteMemoryBlock import RemoteMemoryBlock from pywinauto.timings import Timings, TimeoutError from pywinauto import clipboard import unittest mfc_samples_folder = os.path.join( os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): mfc_samples_folder = os.path.join(mfc_samples_folder, 'x64') def _notepad_exe(): if is_x64_Python() or not is_x64_OS(): return r"C:\Windows\System32\notepad.exe" else: return r"C:\Windows\SysWOW64\notepad.exe" class HwndWrapperTests(unittest.TestCase): "Unit tests for the TreeViewWrapper class" def setUp(self): """Start the application set some data and ensure the application is in the state we want it."""
# About dialog may take some time to load # so make sure that we wait for it. Timings.window_find_timeout = 5 def _notepad_exe(): if is_x64_Python() or not is_x64_OS(): return r"C:\Windows\System32\notepad.exe" else: return r"C:\Windows\SysWOW64\notepad.exe" mfc_samples_folder_32 = mfc_samples_folder = os.path.join( os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): mfc_samples_folder = os.path.join(mfc_samples_folder, 'x64') class ApplicationWarningTestCases(unittest.TestCase): """Unit tests for warnings in the application.Application class""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Defaults() # Force Display User and Deprecation warnings every time # Python 3.3+nose/unittest trys really hard to suppress them for warning in (UserWarning, PendingDeprecationWarning): warnings.simplefilter('always', warning) mfc_samples_folder = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples")
def mfc_samples(): mfc_samples_folder = os.path.join(os.path.dirname(__file__), r"..\..\apps\MFC_samples") if is_x64_Python(): mfc_samples_folder = os.path.join(mfc_samples_folder, 'x64') return mfc_samples_folder