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)
class RemoteMemoryBlockTests(unittest.TestCase): "Unit tests for RemoteMemoryBlock" 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() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.ctrl = self.dlg.TreeView.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() def testGuardSignatureCorruption(self): mem = RemoteMemoryBlock(self.ctrl, 16) buf = ctypes.create_string_buffer(24) self.assertRaises(Exception, mem.Write, buf) mem.size = 24 # test hack self.assertRaises(Exception, mem.Write, buf)
class UnicodeEditTestCases(unittest.TestCase): """Unit tests for the EditWrapper class using Unicode strings""" 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().Start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.dlg.TabControl.Select("CAnimateCtrl") self.ctrl = self.dlg.AnimationFileEdit.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() def testSetEditTextWithUnicode(self): "Test setting Unicode text by the SetEditText method of the edit control" self.ctrl.Select() self.ctrl.SetEditText(579) self.assertEquals("\n".join(self.ctrl.Texts()[1:]), "579") self.ctrl.SetEditText(333, pos_start=1, pos_end=2) self.assertEquals("\n".join(self.ctrl.Texts()[1:]), "53339")
class SendKeysModifiersTests(unittest.TestCase): "Unit tests for the Sendkeys module (modifiers)" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app = Application().start(os.path.join(mfc_samples_folder, u"CtrlTest.exe")) self.dlg = self.app.Control_Test_App def tearDown(self): "Close the application after tests" try: self.dlg.Close(0.5) except Exception: pass finally: self.app.kill_() def testModifiersForFewChars(self): "Make sure that repeated action works" SendKeys("%(SC)", pause = .3) dlg = self.app.Window_(title='Using C++ Derived Class') dlg.Wait('ready') dlg.Done.CloseClick() dlg.WaitNot('visible') SendKeys("%(H{LEFT}{UP}{ENTER})", pause = .3) dlg = self.app.Window_(title='Sample Dialog with spin controls') dlg.Wait('ready') dlg.Done.CloseClick() dlg.WaitNot('visible')
class ButtonOwnerdrawTestCases(unittest.TestCase): """Unit tests for the ButtonWrapper(ownerdraw button)""" def setUp(self): """Start the sample application. Open a tab with ownerdraw button.""" # start the application self.app = Application().Start(os.path.join(mfc_samples_folder, u"CmnCtrl3.exe")) # open the needed tab self.app.active_().TabControl.Select(1) def tearDown(self): """Close the application after tests""" self.app.kill_() def test_NeedsImageProp(self): """test whether an image needs to be saved with the properties""" active_window = self.app.active_() self.assertEquals(active_window.Button2._NeedsImageProp, True) self.assertIn('Image', active_window.Button2.GetProperties())
class StaticTestCases(unittest.TestCase): """Unit tests for the StaticWrapper class""" def setUp(self): """Start the sample application. Open a tab with ownerdraw button.""" # start the application self.app = Application().Start(os.path.join(mfc_samples_folder, u"RebarTest.exe")) # open the Help dailog self.app.active_().TypeKeys('%h{ENTER}') def tearDown(self): """Close the application after tests""" self.app.kill_() def test_NeedsImageProp(self): """test a regular static has no the image property""" active_window = self.app.active_() self.assertEquals(active_window.Static2._NeedsImageProp, False) self.assertNotIn('Image', active_window.Static2.GetProperties()) def test_NeedsImageProp_ownerdraw(self): """test whether an image needs to be saved with the properties""" active_window = self.app.active_() self.assertEquals(active_window.Static._NeedsImageProp, True) self.assertIn('Image', active_window.Static.GetProperties())
class ControlStateTests(unittest.TestCase): """Unit tests for control states""" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app = Application() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.dlg.TabControl.Select(4) self.ctrl = self.dlg.EditBox.WrapperObject() def tearDown(self): """Close the application after tests""" self.app.kill_() def test_VerifyEnabled(self): """test for verify_enabled""" self.assertRaises(ElementNotEnabled, self.ctrl.verify_enabled) def test_VerifyVisible(self): """test for verify_visible""" self.dlg.TabControl.Select(3) self.assertRaises(ElementNotVisible, self.ctrl.verify_visible)
class NotepadRegressionTests(unittest.TestCase): "Regression unit tests for Notepad" 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() self.app.start(_notepad_exe()) 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") self.app2 = Application().start(_notepad_exe()) def tearDown(self): "Close the application after tests" # close the application try: self.dlg.Close(0.5) if self.app.Notepad["Do&n't Save"].Exists(): self.app.Notepad["Do&n't Save"].Click() self.app.Notepad["Do&n't Save"].WaitNot('visible') except Exception: # TimeoutError: pass finally: self.app.kill_() self.app2.kill_() def testMenuSelectNotepad_bug(self): "In notepad - MenuSelect Edit->Paste did not work" text = b'Here are some unicode characters \xef\xfc\r\n' self.app2.UntitledNotepad.Edit.Wait('enabled') time.sleep(0.3) self.app2.UntitledNotepad.Edit.SetEditText(text) time.sleep(0.3) self.assertEquals(self.app2.UntitledNotepad.Edit.TextBlock().encode(locale.getpreferredencoding()), text) Timings.after_menu_wait = .7 self.app2.UntitledNotepad.MenuSelect("Edit->Select All") time.sleep(0.3) self.app2.UntitledNotepad.MenuSelect("Edit->Copy") time.sleep(0.3) self.assertEquals(clipboard.GetData().encode(locale.getpreferredencoding()), text) self.dlg.SetFocus() self.dlg.MenuSelect("Edit->Select All") self.dlg.MenuSelect("Edit->Paste") self.dlg.MenuSelect("Edit->Paste") self.dlg.MenuSelect("Edit->Paste") self.app2.UntitledNotepad.MenuSelect("File->Exit") self.app2.Window_(title='Notepad', class_name='#32770')["Don't save"].Click() self.assertEquals(self.dlg.Edit.TextBlock().encode(locale.getpreferredencoding()), text*3)
class GetDialogPropsFromHandleTest(unittest.TestCase): """Unit tests for mouse actions of the HwndWrapper class""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.fast() self.app = Application() self.app.start(_notepad_exe()) self.dlg = self.app.UntitledNotepad self.ctrl = HwndWrapper(self.dlg.Edit.handle) def tearDown(self): """Close the application after tests""" # close the application #self.dlg.type_keys("%{F4}") self.dlg.Close(0.5) self.app.kill_() def test_GetDialogPropsFromHandle(self): """Test some small stuff regarding GetDialogPropsFromHandle""" props_from_handle = GetDialogPropsFromHandle(self.dlg.handle) props_from_dialog = GetDialogPropsFromHandle(self.dlg) #unused var: props_from_ctrl = GetDialogPropsFromHandle(self.ctrl) self.assertEquals(props_from_handle, props_from_dialog)
class ControlStateTests(unittest.TestCase): """Unit tests for control states""" def setUp(self): """Start the application set some data and ensure the application is in the state we want it. """ self.app = Application() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.dlg.TabControl.Select(4) self.ctrl = self.dlg.EditBox.WrapperObject() def tearDown(self): """Close the application after tests""" self.app.kill_() def test_VerifyEnabled(self): """Test for verify_enabled""" self.assertRaises(ElementNotEnabled, self.ctrl.verify_enabled) def test_VerifyVisible(self): """Test for verify_visible""" self.dlg.TabControl.Select(3) self.assertRaises(ElementNotVisible, self.ctrl.verify_visible)
class WindowWithoutMessageLoopFocusTests(unittest.TestCase): """ Regression unit tests for setting focus when window does not have a message loop. """ def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Fast() self.app1 = Application().start(u"cmd.exe", create_new_console=True, wait_for_idle=False) self.app2 = Application().start( os.path.join(mfc_samples_folder, u"CmnCtrl2.exe")) def tearDown(self): """Close the application after tests""" self.app1.kill_() self.app2.kill_() def test_issue_270(self): """ Set focus to a window without a message loop, then switch to a window with one and type in it. """ self.app1.window().set_focus() # pywintypes.error: # (87, 'AttachThreadInput', 'The parameter is incorrect.') self.app2.window().edit.type_keys("1") # cmd.exe into python.exe; pywintypes.error: # (87, 'AttachThreadInput', 'The parameter is incorrect.') # python.exe on its own; pywintypes.error: # (0, 'SetForegroundWindow', 'No error message is available') self.assertTrue(self.app2.window().is_active())
class ClipboardTestCases(unittest.TestCase): "Unit tests for the clipboard" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" EmptyClipboard() self.app1 = Application().start("notepad.exe") self.app2 = Application().start("notepad.exe") self.app1.UntitledNotepad.MoveWindow(RECT(0, 0, 200, 200)) self.app2.UntitledNotepad.MoveWindow(RECT(0, 200, 200, 400)) def tearDown(self): "Close the application after tests" # close the application self.app1.UntitledNotepad.MenuSelect('File -> Exit') if self.app1.Notepad["Do&n't Save"].Exists(): self.app1.Notepad["Do&n't Save"].Click() self.app1.kill_() self.app2.UntitledNotepad.MenuSelect('File -> Exit') if self.app2.Notepad["Do&n't Save"].Exists(): self.app2.Notepad["Do&n't Save"].Click() self.app2.kill_() def testGetClipBoardFormats(self): typetext(self.app1, "here we are") copytext(self.app1) self.assertEquals(GetClipboardFormats(), [13, 16, 1, 7]) def testGetFormatName(self): typetext(self.app1, "here we are") copytext(self.app1) self.assertEquals( [GetFormatName(f) for f in GetClipboardFormats()], ['CF_UNICODETEXT', 'CF_LOCALE', 'CF_TEXT', 'CF_OEMTEXT'] ) def testBug1452832(self): """Failing test for sourceforge bug 1452832 Where GetData was not closing the clipboard. FIXED. """ self.app1.UntitledNotepad.MenuSelect("Edit->Select All Ctrl+A") typetext(self.app1, "some text") copytext(self.app1) # was not closing the clipboard! data = GetData() self.assertEquals(data, "some text") self.assertEquals(gettext(self.app2), "") pastetext(self.app2) self.assertEquals(gettext(self.app2), "some text")
class ButtonOwnerdrawTestCases(unittest.TestCase): """Unit tests for the ButtonWrapper(ownerdraw button)""" def setUp(self): """Start the sample application. Open a tab with ownerdraw button.""" _set_timings_fast() self.app = Application().Start(os.path.join(mfc_samples_folder, u"CmnCtrl3.exe")) # open the needed tab self.app.active_().TabControl.Select(1) def tearDown(self): """Close the application after tests""" self.app.kill_() def test_NeedsImageProp(self): """test whether an image needs to be saved with the properties""" active_window = self.app.active_() self.assertEquals(active_window.Button2._needs_image_prop, True) self.assertEquals('image' in active_window.Button2.GetProperties(), True)
class GetDialogPropsFromHandleTest(unittest.TestCase): """Unit tests for mouse actions of the HwndWrapper class""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Fast() self.app = Application() self.app.start(_notepad_exe()) self.dlg = self.app.UntitledNotepad self.ctrl = HwndWrapper(self.dlg.Edit.handle) def tearDown(self): """Close the application after tests""" # close the application #self.dlg.type_keys("%{F4}") self.dlg.Close(0.5) self.app.kill_() def test_GetDialogPropsFromHandle(self): """Test some small stuff regarding GetDialogPropsFromHandle""" props_from_handle = GetDialogPropsFromHandle(self.dlg.handle) props_from_dialog = GetDialogPropsFromHandle(self.dlg) #unused var: props_from_ctrl = GetDialogPropsFromHandle(self.ctrl) self.assertEquals(props_from_handle, props_from_dialog)
class WindowWithoutMessageLoopFocusTests(unittest.TestCase): """ Regression unit tests for setting focus when window does not have a message loop. """ def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Fast() self.app1 = Application().start("cmd.exe", create_new_console=True, wait_for_idle=False) self.app2 = Application().start(os.path.join(mfc_samples_folder, "CmnCtrl2.exe")) def tearDown(self): """Close the application after tests""" self.app1.kill_() self.app2.kill_() def test_issue_270(self): """ Set focus to a window without a message loop, then switch to a window with one and type in it. """ self.app1.window().set_focus() # pywintypes.error: # (87, 'AttachThreadInput', 'The parameter is incorrect.') self.app2.window().edit.type_keys("1") # cmd.exe into python.exe; pywintypes.error: # (87, 'AttachThreadInput', 'The parameter is incorrect.') # python.exe on its own; pywintypes.error: # (0, 'SetForegroundWindow', 'No error message is available') self.assertTrue(self.app2.window().is_active())
class NonActiveWindowFocusTests(unittest.TestCase): """Regression unit tests for setting focus""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Fast() self.app = Application() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl3.exe")) self.app2 = Application().start(_notepad_exe()) def tearDown(self): """Close the application after tests""" self.app.kill_() self.app2.kill_() def test_issue_240(self): """Check HwndWrapper.set_focus for a desktop without a focused window""" ws = self.app.Common_Controls_Sample ws.TabControl.Select('CButton (Command Link)') dlg1 = ws.wrapper_object() dlg2 = self.app2.Notepad.wrapper_object() dlg2.click(coords=(2, 2)) dlg2.minimize() # here is the trick: the window is restored but it isn't activated dlg2.restore() dlg1.set_focus() self.assertEqual(ws.GetFocus(), ws.Edit.wrapper_object())
class GetDialogPropsFromHandleTest(unittest.TestCase): "Unit tests for mouse actions of the HwndWrapper class" 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 tearDown(self): "Close the application after tests" # close the application #self.dlg.TypeKeys("%{F4}") self.dlg.Close(0.5) self.app.kill_() def test_GetDialogPropsFromHandle(self): "Test some small stuff regarding GetDialogPropsFromHandle" props_from_handle = GetDialogPropsFromHandle(self.dlg.handle) props_from_dialog = GetDialogPropsFromHandle(self.dlg) #unused var: props_from_ctrl = GetDialogPropsFromHandle(self.ctrl) self.assertEquals(props_from_handle, props_from_dialog)
class SendKeysModifiersTests(unittest.TestCase): """Unit tests for the Sendkeys module (modifiers)""" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app = Application().start( os.path.join(mfc_samples(), u"CtrlTest.exe")) self.dlg = self.app.Control_Test_App def tearDown(self): """Close the application after tests""" try: self.dlg.Close(0.5) except Exception: pass finally: self.app.kill_() def testModifiersForFewChars(self): """Make sure that repeated action works""" SendKeys("%(SC)", pause=.3) dlg = self.app.Window_(title='Using C++ Derived Class') dlg.Wait('ready') dlg.Done.CloseClick() dlg.WaitNot('visible') SendKeys("%(H{LEFT}{UP}{ENTER})", pause=.3) dlg = self.app.Window_(title='Sample Dialog with spin controls') dlg.Wait('ready') dlg.Done.CloseClick() dlg.WaitNot('visible')
class UnicodeEditTestCases(unittest.TestCase): """Unit tests for the EditWrapper class using Unicode strings""" def setUp(self): """Set some data and ensure the application is in the state we want""" _set_timings_fast() self.app = Application().Start( os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.dlg.TabControl.Select("CAnimateCtrl") self.ctrl = self.dlg.AnimationFileEdit.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() def testSetEditTextWithUnicode(self): "Test setting Unicode text by the SetEditText method of the edit control" self.ctrl.Select() self.ctrl.SetEditText(579) self.assertEquals("\n".join(self.ctrl.texts()[1:]), "579") self.ctrl.SetEditText(333, pos_start=1, pos_end=2) self.assertEquals("\n".join(self.ctrl.texts()[1:]), "53339")
class StaticTestCases(unittest.TestCase): """Unit tests for the StaticWrapper class""" def setUp(self): """Start the sample application. Open a tab with ownerdraw button.""" Timings.defaults() self.app = Application().Start( os.path.join(mfc_samples_folder, u"RebarTest.exe")) # open the Help dailog self.app.active_().type_keys('%h{ENTER}') def tearDown(self): """Close the application after tests""" self.app.kill_() def test_NeedsImageProp(self): """test a regular static has no the image property""" active_window = self.app.active_() self.assertEquals(active_window.Static2._needs_image_prop, False) self.assertEquals('image' in active_window.Static2.GetProperties(), False) #self.assertNotIn('image', active_window.Static2.GetProperties()) # assertIn and assertNotIn are not supported in Python 2.6 def test_NeedsImageProp_ownerdraw(self): """test whether an image needs to be saved with the properties""" active_window = self.app.active_() self.assertEquals(active_window.Static._needs_image_prop, True) self.assertEquals('image' in active_window.Static.GetProperties(), True)
class NotepadRegressionTests(unittest.TestCase): "Regression unit tests for Notepad" 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() self.app.start_(_notepad_exe()) 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") self.app2 = Application.start(_notepad_exe()) def tearDown(self): "Close the application after tests" # close the application try: self.dlg.Close(0.5) if self.app.Notepad["Do&n't Save"].Exists(): self.app.Notepad["Do&n't Save"].Click() self.app.Notepad["Do&n't Save"].WaitNot('visible') except Exception: # TimeoutError: pass finally: self.app.kill_() self.app2.kill_() def testMenuSelectNotepad_bug(self): "In notepad - MenuSelect Edit->Paste did not work" text = b'Here are some unicode characters \xef\xfc\r\n' self.app2.UntitledNotepad.Edit.Wait('enabled') time.sleep(0.3) self.app2.UntitledNotepad.Edit.SetEditText(text) time.sleep(0.3) self.assertEquals(self.app2.UntitledNotepad.Edit.TextBlock().encode(locale.getpreferredencoding()), text) Timings.after_menu_wait = .7 self.app2.UntitledNotepad.MenuSelect("Edit->Select All") time.sleep(0.3) self.app2.UntitledNotepad.MenuSelect("Edit->Copy") time.sleep(0.3) self.assertEquals(clipboard.GetData().encode(locale.getpreferredencoding()), text) self.dlg.SetFocus() self.dlg.MenuSelect("Edit->Select All") self.dlg.MenuSelect("Edit->Paste") self.dlg.MenuSelect("Edit->Paste") self.dlg.MenuSelect("Edit->Paste") self.app2.UntitledNotepad.MenuSelect("File->Exit") self.app2.Window_(title='Notepad', class_name='#32770')["Don't save"].Click() self.assertEquals(self.dlg.Edit.TextBlock().encode(locale.getpreferredencoding()), text*3)
class GetDialogPropsFromHandleTest(unittest.TestCase): "Unit tests for mouse actions of the HwndWrapper class" 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 tearDown(self): "Close the application after tests" # close the application #self.dlg.TypeKeys("%{F4}") self.dlg.Close(0.5) self.app.kill_() def test_GetDialogPropsFromHandle(self): "Test some small stuff regarding GetDialogPropsFromHandle" props_from_handle = GetDialogPropsFromHandle(self.dlg.handle) props_from_dialog = GetDialogPropsFromHandle(self.dlg) props_from_ctrl = GetDialogPropsFromHandle(self.ctrl) self.assertEquals(props_from_handle, props_from_dialog)
class NonActiveWindowFocusTests(unittest.TestCase): """Regression unit tests for setting focus""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.fast() self.app = Application() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl3.exe")) self.app2 = Application().start(_notepad_exe()) def tearDown(self): """Close the application after tests""" self.app.kill_() self.app2.kill_() def test_issue_240(self): """Check HwndWrapper.set_focus for a desktop without a focused window""" ws = self.app.Common_Controls_Sample ws.TabControl.Select('CButton (Command Link)') dlg1 = ws.wrapper_object() dlg2 = self.app2.Notepad.wrapper_object() dlg2.click(coords=(2, 2)) dlg2.minimize() # here is the trick: the window is restored but it isn't activated dlg2.restore() dlg1.set_focus() self.assertEqual(ws.GetFocus(), ws.Edit.wrapper_object())
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)
class ClipboardTestCases(unittest.TestCase): "Unit tests for the clipboard" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" EmptyClipboard() self.app1 = Application().start("notepad.exe") self.app2 = Application().start("notepad.exe") self.app1.UntitledNotepad.MoveWindow(RECT(0, 0, 200, 200)) self.app2.UntitledNotepad.MoveWindow(RECT(0, 200, 200, 400)) def tearDown(self): "Close the application after tests" # close the application self.app1.UntitledNotepad.MenuSelect('File -> Exit') if self.app1.Notepad["Do&n't Save"].Exists(): self.app1.Notepad["Do&n't Save"].Click() self.app1.kill_() self.app2.UntitledNotepad.MenuSelect('File -> Exit') if self.app2.Notepad["Do&n't Save"].Exists(): self.app2.Notepad["Do&n't Save"].Click() self.app2.kill_() def testGetClipBoardFormats(self): typetext(self.app1, "here we are") copytext(self.app1) self.assertEquals(GetClipboardFormats(), [13, 16, 1, 7]) def testGetFormatName(self): typetext(self.app1, "here we are") copytext(self.app1) self.assertEquals( [GetFormatName(f) for f in GetClipboardFormats()], ['CF_UNICODETEXT', 'CF_LOCALE', 'CF_TEXT', 'CF_OEMTEXT']) def testBug1452832(self): """Failing test for sourceforge bug 1452832 Where GetData was not closing the clipboard. FIXED. """ self.app1.UntitledNotepad.MenuSelect("Edit->Select All Ctrl+A") typetext(self.app1, "some text") copytext(self.app1) # was not closing the clipboard! data = GetData() self.assertEquals(data, "some text") self.assertEquals(gettext(self.app2), "") pastetext(self.app2) self.assertEquals(gettext(self.app2), "some text")
class CheckBoxTests(unittest.TestCase): """Unit tests for the CheckBox specific methods of the ButtonWrapper class""" def setUp(self): """Set some data and ensure the application is in the state we want""" _set_timings_fast() self.app = Application() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.tree = self.dlg.TreeView.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() def testCheckUncheckByClick(self): "test for CheckByClick and UncheckByClick" self.dlg.TVS_HASLINES.CheckByClick() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), True) self.dlg.TVS_HASLINES.CheckByClick() # make sure it doesn't uncheck the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.dlg.TVS_HASLINES.UncheckByClick() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), False) self.dlg.TVS_HASLINES.UncheckByClick() # make sure it doesn't check the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) def testCheckUncheckByClickInput(self): "test for CheckByClickInput and UncheckByClickInput" self.dlg.TVS_HASLINES.CheckByClickInput() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), True) self.dlg.TVS_HASLINES.CheckByClickInput() # make sure it doesn't uncheck the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.dlg.TVS_HASLINES.UncheckByClickInput() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), False) self.dlg.TVS_HASLINES.UncheckByClickInput() # make sure it doesn't check the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) def testSetCheckIndeterminate(self): "test for SetCheckIndeterminate" self.dlg.TVS_HASLINES.SetCheckIndeterminate() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED)
class CheckBoxTests(unittest.TestCase): "Unit tests for the CheckBox specific methods of the ButtonWrapper class" 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() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.tree = self.dlg.TreeView.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() def testCheckUncheckByClick(self): "test for CheckByClick and UncheckByClick" self.dlg.TVS_HASLINES.CheckByClick() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), True) self.dlg.TVS_HASLINES.CheckByClick() # make sure it doesn't uncheck the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.dlg.TVS_HASLINES.UncheckByClick() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), False) self.dlg.TVS_HASLINES.UncheckByClick() # make sure it doesn't check the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) def testCheckUncheckByClickInput(self): "test for CheckByClickInput and UncheckByClickInput" self.dlg.TVS_HASLINES.CheckByClickInput() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), True) self.dlg.TVS_HASLINES.CheckByClickInput() # make sure it doesn't uncheck the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED) self.dlg.TVS_HASLINES.UncheckByClickInput() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) self.assertEquals(self.tree.HasStyle(win32defines.TVS_HASLINES), False) self.dlg.TVS_HASLINES.UncheckByClickInput() # make sure it doesn't check the box unexpectedly self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_UNCHECKED) def testSetCheckIndeterminate(self): "test for SetCheckIndeterminate" self.dlg.TVS_HASLINES.SetCheckIndeterminate() self.assertEquals(self.dlg.TVS_HASLINES.GetCheckState(), win32defines.BST_CHECKED)
class FindWindowsTestCases(unittest.TestCase): """Unit tests for findwindows.py module""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Defaults() # start the application self.app = Application(backend='win32') self.app = self.app.Start(mfc_app_1) self.dlg = self.app.CommonControlsSample def tearDown(self): """Close the application after tests""" self.app.kill_() def test_find_window(self): """Test if function find_window() works as expected including raising the exceptions""" ctrl = self.dlg.OK.WrapperObject() handle = find_window(process=self.app.process, best_match='OK', top_level_only=False) self.assertEqual(handle, ctrl.handle) self.assertRaises(WindowNotFoundError, find_window, process=self.app.process, class_name='OK') self.assertRaises(WindowAmbiguousError, find_window, process=self.app.process, class_name='Button', top_level_only=False) def test_find_windows(self): """Test if function find_windows() works as expected including raising the exceptions""" ctrl_hwnds = [ elem.handle for elem in self.dlg.children() if elem.class_name() == 'Edit' ] handles = find_windows(process=self.app.process, class_name='Edit', top_level_only=False) self.assertEqual(set(handles), set(ctrl_hwnds)) self.assertRaises(WindowNotFoundError, find_windows, process=self.app.process, class_name='FakeClassName', found_index=1)
def testStartWarning3264(self): if not is_x64_OS(): self.defaultTestResult() return warnings.filterwarnings('always', category=UserWarning, append=True) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") app = Application().start(self.sample_exe_inverted_bitness) app.kill_() assert len(w) >= 1 assert issubclass(w[-1].category, UserWarning) assert "64-bit" in str(w[-1].message)
def testDeprecatedConnectWarning(self): warn_text = "connect_()/Connect_() methods are deprecated," deprecated_connect_methods = ('connect_', 'Connect_') # warnings.filterwarnings('always', category=PendingDeprecationWarning, # append=True) with warnings.catch_warnings(record=True) as warns: app = Application().start(self.sample_exe) for deprecated_method in deprecated_connect_methods: app2 = getattr(Application(), deprecated_method)(path=self.sample_exe) app.kill_() self.assertEquals(len(deprecated_connect_methods), len(warns)) self.assertEquals(warns[-1].category, PendingDeprecationWarning) self.assertEquals(warn_text in str(warns[-1].message), True)
def test_kill_(self): """test killing the application""" app = Application() app.start(_notepad_exe()) app.UntitledNotepad.Edit.type_keys("hello") app.UntitledNotepad.MenuSelect("File->Print...") #app.Print.FindPrinter.Click() # Vasily: (Win7 x64) "Find Printer" dialog is from splwow64.exe process #app.FindPrinters.Stop.Click() app.kill_() self.assertRaises(AttributeError, app.UntitledNotepad.Edit)
def create_Subs2srs_Deck(subs2srs_Path, subtitle_Path, video_Path, directory_Path, deck_Name, subs_Time_Shift): subs2srs_App = Application().start(subs2srs_Path) subs2srs = subs2srs_App.subs2srs subs2srs.set_focus() subs2srs['&Subs1...Edit'].set_text(subtitle_Path + "\\*.srt") subs2srs['&Video...Edit'].set_text(video_Path + "\\*.mp4") subs2srs['&Output...Edit'].set_text(directory_Path) subs2srs['Name of deck:Edit'].set_text(deck_Name) subs2srs['Time Shift:Button'].click_input() subs2srs['Subs1:Edit'].set_text(subs_Time_Shift) subs2srs_App.subs2srs.Button0.click() while (True): if (subs2srs_App.subs2srs.is_active() == True): subs2srs_App.kill_() break
class SendKeystrokesAltComboTests(unittest.TestCase): """Unit test for Alt- combos sent via send_keystrokes""" def setUp(self): Timings.defaults() self.app = Application().start( os.path.join(mfc_samples_folder, u'CtrlTest.exe')) self.dlg = self.app.Control_Test_App def tearDown(self): self.app.kill_() def test_send_keystrokes_alt_combo(self): self.dlg.send_keystrokes('%(sc)') self.assertTrue(self.app['Using C++ Derived Class'].Exists())
def tearDown(self): """Close the application after tests""" self.dlg.SendMessage(win32defines.WM_CLOSE) self.dlg.WaitNot('ready') # cleanup additional unclosed sampleapps l = pywinauto.actionlogger.ActionLogger() try: for i in range(2): l.log("Look for unclosed sample apps") app = Application() app.connect(path="TrayMenu.exe") l.log("Forse closing a leftover app: {0}".format(app)) app.kill_() except (ProcessNotFoundError): l.log("No more leftovers. All good.")
def testConnectWarning3264(self): if not is_x64_OS(): self.defaultTestResult() return app = Application().start(self.sample_exe_inverted_bitness) # Appveyor misteries... self.assertEqual(app.is_process_running(), True) with mock.patch("warnings.warn") as mockWarn: Application().connect(process=app.process) app.kill_() args, kw = mockWarn.call_args assert len(args) == 2 assert "64-bit" in args[0] assert args[1].__name__ == 'UserWarning'
def testkill_(self): "test killing the application" app = Application() app.start(_notepad_exe()) app.UntitledNotepad.Edit.TypeKeys("hello") app.UntitledNotepad.MenuSelect("File->Print...") #app.Print.FindPrinter.Click() # vvryabov: (Win7 x64) "Find Printers" dialog is from splwow64.exe process #app.FindPrinters.Stop.Click() # so cannot handle it in 32-bit Python app.kill_() self.assertRaises(AttributeError, app.UntitledNotepad.Edit)
def tearDown(self): """Close the application after tests""" self.dlg.SendMessage(win32defines.WM_CLOSE) self.dlg.WaitNot('ready') # cleanup additional unclosed sampleapps l = pywinauto.actionlogger.ActionLogger() try: for i in range(2): l.log("Look for unclosed sample apps") app = Application() app.connect(path="TrayMenu.exe") l.log("Forse closing a leftover app: {0}".format(app)) app.kill_() except(ProcessNotFoundError): l.log("No more leftovers. All good.")
class FindWindowsTestCases(unittest.TestCase): """Unit tests for findwindows.py module""" 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(backend='native') self.app = self.app.Start(mfc_app_1) self.dlg = self.app.CommonControlsSample def tearDown(self): """Close the application after tests""" self.app.kill_() def testFindWindow(self): """ Test if function find_window() works as expected including raising the exceptions """ ctrl = self.dlg.OK.WrapperObject() handle = find_window(process=self.app.process, best_match='OK', top_level_only=False) self.assertEqual(handle, ctrl.handle) self.assertRaises(WindowNotFoundError, find_window, process=self.app.process, class_name='OK') self.assertRaises(WindowAmbiguousError, find_window, process=self.app.process, class_name='Button', top_level_only=False) def testFindWindows(self): """ Test if function find_window() works as expected including raising the exceptions """ ctrl_hwnds = [elem.handle for elem in self.dlg.children() if elem.class_name() == 'Edit'] handles = find_windows(process=self.app.process, class_name='Edit', top_level_only=False) self.assertEqual(set(handles), set(ctrl_hwnds)) self.assertRaises(WindowNotFoundError, find_windows, process=self.app.process, class_name='FakeClassName', found_index=1)
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_()
class OwnerDrawnMenuTests(unittest.TestCase): "Unit tests for the OWNERDRAW menu items" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" self.app = Application().Start(os.path.join(mfc_samples_folder, u"BCDialogMenu.exe")) self.dlg = self.app.BCDialogMenu def tearDown(self): "Close the application after tests" self.app.kill_() def testCorrectText(self): self.assertEquals(u'&New', self.dlg.Menu().GetMenuPath('&File->#0')[-1].Text()[:4]) self.assertEquals(u'&Open...', self.dlg.Menu().GetMenuPath('&File->#1')[-1].Text()[:8])
class OwnerDrawnMenuTests(unittest.TestCase): """Unit tests for the OWNERDRAW menu items""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Defaults() self.app = Application().Start(os.path.join(mfc_samples_folder, u"BCDialogMenu.exe")) self.dlg = self.app.BCDialogMenu def tearDown(self): """Close the application after tests""" self.app.kill_() def testCorrectText(self): self.assertEqual(u'&New', self.dlg.Menu().GetMenuPath('&File->#0')[-1].Text()[:4]) self.assertEqual(u'&Open...', self.dlg.Menu().GetMenuPath('&File->#1')[-1].Text()[:8])
class DragAndDropTests(unittest.TestCase): "Unit tests for mouse actions like drag-n-drop" 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() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.ctrl = self.dlg.TreeView.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() ''' def testDragMouse(self): "DragMouse works! But CmnCtrl1.exe crashes in infinite recursion." birds = self.ctrl.GetItem(r'\Birds') dogs = self.ctrl.GetItem(r'\Dogs') self.ctrl.DragMouse("left", birds.Rectangle().mid_point(), dogs.Rectangle().mid_point()) dogs = self.ctrl.GetItem(r'\Dogs') self.assertEquals([child.Text() for child in dogs.Children()], [u'Birds', u'Dalmatian', u'German Shepherd', u'Great Dane']) ''' def testDragMouseInput(self): "test for DragMouseInput" birds = self.ctrl.GetItem(r'\Birds') dogs = self.ctrl.GetItem(r'\Dogs') #birds.Select() birds.ClickInput() time.sleep(5) # enough pause to prevent double click detection self.ctrl.DragMouseInput("left", birds.Rectangle().mid_point(), dogs.Rectangle().mid_point()) dogs = self.ctrl.GetItem(r'\Dogs') self.assertEquals( [child.Text() for child in dogs.Children()], [u'Birds', u'Dalmatian', u'German Shepherd', u'Great Dane'])
class PopupMenuTestCases(unittest.TestCase): """Unit tests for the PopupMenuWrapper class""" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application self.app = Application() self.app.start_("notepad.exe") self.app.Notepad.Edit.RightClick() self.popup = self.app.PopupMenu.WrapperObject() def tearDown(self): "Close the application after tests" self.popup.TypeKeys("{ESC}") self.app.kill_() #.Notepad.TypeKeys("%{F4}") def testGetProperties(self): "Test getting the properties for the PopupMenu" props = self.popup.GetProperties() self.assertEquals( "PopupMenu", props['FriendlyClassName']) self.assertEquals(self.popup.Texts(), props['Texts']) for prop_name in props: self.assertEquals( getattr(self.popup, prop_name)(), props[prop_name]) def testIsDialog(self): "Ensure that IsDialog works correctly" self.assertEquals(True, self.popup.IsDialog()) def test_menu_handle(self): "Ensure that the menu handle is returned" handle = self.popup._menu_handle() self.assertNotEquals(0, handle)
class PopupMenuTestCases(unittest.TestCase): """Unit tests for the PopupMenuWrapper class""" def setUp(self): """Start the application set some data and ensure the application is in the state we want it.""" # start the application from pywinauto.application import Application self.app = Application() self.app.start("notepad.exe") self.app.Notepad.Edit.RightClick() self.popup = self.app.PopupMenu.WrapperObject() def tearDown(self): "Close the application after tests" self.popup.TypeKeys("{ESC}") self.app.kill_() #.Notepad.TypeKeys("%{F4}") def testGetProperties(self): "Test getting the properties for the PopupMenu" props = self.popup.GetProperties() self.assertEquals( "PopupMenu", props['FriendlyClassName']) self.assertEquals(self.popup.Texts(), props['Texts']) for prop_name in props: self.assertEquals( getattr(self.popup, prop_name)(), props[prop_name]) def testIsDialog(self): "Ensure that IsDialog works correctly" self.assertEquals(True, self.popup.IsDialog()) def test_menu_handle(self): "Ensure that the menu handle is returned" handle = self.popup._menu_handle() self.assertNotEquals(0, handle)
class UIAElementInfoTests(unittest.TestCase): """Unit tests for the UIElementInfo class""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Slow() self.app = Application(backend="uia") self.app = self.app.start(wpf_app_1) self.dlg = self.app.WPFSampleApplication self.handle = self.dlg.handle self.ctrl = UIAElementInfo(self.handle) def tearDown(self): """Close the application after tests""" self.app.kill_() def testProcessId(self): """Test process_id equals""" self.assertEqual(self.ctrl.process_id, processid(self.handle)) def testName(self): """Test application name equals""" self.assertEqual(self.ctrl.name, "WPF Sample Application") def testHandle(self): """Test application handle equals""" self.assertEqual(self.ctrl.handle, self.handle) def testEnabled(self): """Test whether the element is enabled""" self.assertEqual(self.ctrl.enabled, True) def testVisible(self): """Test whether the element is visible""" self.assertEqual(self.ctrl.visible, True) def testChildren(self): """Test whether a list of only immediate children of the element is equal""" self.assertEqual(len(self.ctrl.children()), 5)
class UIAWrapperMouseTests(unittest.TestCase): """Unit tests for mouse actions of the UIAWrapper class""" def setUp(self): """ Start the application set some data and ensure the application is in the state we want it. """ self.app = Application(backend='uia') self.app = self.app.Start(wpf_app_1) self.dlg = self.app.WPFSampleApplication self.button = self.dlg.OK.WrapperObject() self.label = self.dlg.TestLabel.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() #def testClick(self): # pass def testClickInput(self): time.sleep(0.5) self.button.click_input() self.assertEqual(self.label.window_text(), "LeftClick") #def testDoubleClick(self): # pass def testDoubleClickInput(self): self.button.double_click_input() self.assertEqual(self.label.window_text(), "DoubleClick") #def testRightClick(self): # pass def testRightClickInput(self): time.sleep(0.5) self.button.right_click_input() self.assertEqual(self.label.window_text(), "RightClick")
class SendEnterKeyTest(unittest.TestCase): def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.fast() self.app = Application() self.app.start(_notepad_exe()) self.dlg = self.app.UntitledNotepad self.ctrl = HwndWrapper(self.dlg.Edit.handle) def tearDown(self): self.dlg.MenuSelect('File -> Exit') if self.dlg["Do&n't Save"].Exists(): self.dlg["Do&n't Save"].Click() self.app.kill_() def test_sendEnterChar(self): self.ctrl.send_chars('Hello{ENTER}World') self.assertEquals(['Hello\r\nWorld'], self.dlg.Edit.Texts())
class MenuWrapperTests(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.""" # start the application self.app = Application() self.app.start_("Notepad.exe") self.dlg = self.app.Notepad def tearDown(self): "Close the application after tests" # close the application #self.dlg.TypeKeys("%{F4}") self.app.kill_() def testInvalidHandle(self): "Test that an exception is raised with an invalid menu handle" #self.assertRaises(InvalidWindowHandle, HwndWrapper, -1) pass def testItemCount(self): self.assertEquals(5, self.dlg.Menu().ItemCount()) def testItem(self): pass def testItems(self): pass def testGetProperties(self): pass def testGetMenuPath(self): pass def test__repr__(self): pass
class DragAndDropTests(unittest.TestCase): """Unit tests for mouse actions like drag-n-drop""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Defaults() self.app = Application() self.app.start(os.path.join(mfc_samples_folder, "CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.ctrl = self.dlg.TreeView.WrapperObject() def tearDown(self): """Close the application after tests""" self.app.kill_() # def testDragMouse(self): # """DragMouse works! But CmnCtrl1.exe crashes in infinite recursion.""" # birds = self.ctrl.GetItem(r'\Birds') # dogs = self.ctrl.GetItem(r'\Dogs') # self.ctrl.DragMouse("left", birds.rectangle().mid_point(), dogs.rectangle().mid_point()) # dogs = self.ctrl.GetItem(r'\Dogs') # self.assertEquals([child.Text() for child in dogs.children()], [u'Birds', u'Dalmatian', u'German Shepherd', u'Great Dane']) def testDragMouseInput(self): """test for drag_mouse_input""" birds = self.ctrl.GetItem(r"\Birds") dogs = self.ctrl.GetItem(r"\Dogs") # birds.Select() birds.click_input() time.sleep(5) # enough pause to prevent double click detection self.ctrl.drag_mouse_input( dst=dogs.client_rect().mid_point(), src=birds.client_rect().mid_point(), absolute=False ) dogs = self.ctrl.GetItem(r"\Dogs") self.assertEquals( [child.Text() for child in dogs.children()], ["Birds", "Dalmatian", "German Shepherd", "Great Dane"] )
class PopupMenuTestCases(unittest.TestCase): """Unit tests for the PopupMenuWrapper class""" def setUp(self): """Set some data and ensure the application is in the state we want""" _set_timings_fast() self.app = Application() self.app.start("notepad.exe") self.app.Notepad.Edit.RightClick() self.popup = self.app.PopupMenu.WrapperObject() def tearDown(self): "Close the application after tests" self.popup.type_keys("{ESC}") self.app.kill_() #.Notepad.type_keys("%{F4}") def testGetProperties(self): "Test getting the properties for the PopupMenu" props = self.popup.GetProperties() self.assertEquals( "PopupMenu", props['friendly_class_name']) self.assertEquals(self.popup.texts(), props['texts']) for prop_name in props: self.assertEquals( getattr(self.popup, prop_name)(), props[prop_name]) def testIsDialog(self): "Ensure that is_dialog works correctly" self.assertEquals(True, self.popup.is_dialog()) def test_menu_handle(self): "Ensure that the menu handle is returned" handle = self.popup._menu_handle() self.assertNotEquals(0, handle)
class UIAElementInfoTests(unittest.TestCase): "Unit tests for the UIElementInfo class" 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 tearDown(self): "Close the application after tests" self.app.kill_() def testProcessId(self): self.assertEqual(self.ctrl.process_id, processid(self.handle)) def testName(self): self.assertEqual(self.ctrl.name, "Calculator") def testHandle(self): self.assertEqual(self.ctrl.handle, self.handle) def testEnabled(self): self.assertEqual(self.ctrl.enabled, True) def testVisible(self): self.assertEqual(self.ctrl.visible, True) def testChildren(self): self.assertEqual(len(self.ctrl.children()), 3)
class ActionloggerTestCases(unittest.TestCase): """Unit tests for the actionlogger""" def setUp(self): """Set some data and ensure the application is in the state we want""" Timings.Fast() actionlogger.enable() self.app = Application().start(_notepad_exe()) self.logger = logging.getLogger('pywinauto') self.out = self.logger.parent.handlers[0].stream self.logger.parent.handlers[0].stream = open('test_logging.txt', 'w') def tearDown(self): """Close the application after tests""" self.logger.parent.handlers[0].stream = self.out self.app.kill_() def __lineCount(self): """hack to get line count from current logger stream""" self.logger = logging.getLogger('pywinauto') self.logger.parent.handlers[0].stream.flush(); os.fsync(self.logger.parent.handlers[0].stream.fileno()) with open(self.logger.parent.handlers[0].stream.name, 'r') as f: return len(f.readlines()) def testEnableDisable(self): actionlogger.enable() prev_line_count = self.__lineCount() self.app.UntitledNotepad.type_keys('Test pywinauto logging', with_spaces=True) self.assertEquals(self.__lineCount(), prev_line_count+1) actionlogger.disable() self.app.UntitledNotepad.MenuSelect('Help->About Notepad') self.assertEquals(self.__lineCount(), prev_line_count+1) actionlogger.enable() self.app.window(title='About Notepad').OK.Click() self.assertEquals(self.__lineCount(), prev_line_count+2)
class DragAndDropTests(unittest.TestCase): "Unit tests for mouse actions like drag-n-drop" 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() self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe")) self.dlg = self.app.Common_Controls_Sample self.ctrl = self.dlg.TreeView.WrapperObject() def tearDown(self): "Close the application after tests" self.app.kill_() ''' def testDragMouse(self): "DragMouse works! But CmnCtrl1.exe crashes in infinite recursion." birds = self.ctrl.GetItem(r'\Birds') dogs = self.ctrl.GetItem(r'\Dogs') self.ctrl.DragMouse("left", birds.Rectangle().mid_point(), dogs.Rectangle().mid_point()) dogs = self.ctrl.GetItem(r'\Dogs') self.assertEquals([child.Text() for child in dogs.Children()], [u'Birds', u'Dalmatian', u'German Shepherd', u'Great Dane']) ''' def testDragMouseInput(self): "test for DragMouseInput" birds = self.ctrl.GetItem(r'\Birds') dogs = self.ctrl.GetItem(r'\Dogs') #birds.Select() birds.ClickInput() time.sleep(5) # enough pause to prevent double click detection self.ctrl.DragMouseInput("left", birds.Rectangle().mid_point(), dogs.Rectangle().mid_point()) dogs = self.ctrl.GetItem(r'\Dogs') self.assertEquals([child.Text() for child in dogs.Children()], [u'Birds', u'Dalmatian', u'German Shepherd', u'Great Dane'])