def _toggle_notification_area_icons(show_all=True, debug_img=None): """ A helper function to change 'Show All Icons' settings. On a succesful execution the function returns an original state of 'Show All Icons' checkbox. The helper works only for an "English" version of Windows, on non-english versions of Windows the 'Notification Area Icons' window should be accessed with a localized title" """ app = Application() starter = app.start_(r'explorer.exe') class_name = 'CabinetWClass' def _cabinetwclass_exist(): "Verify if at least one active 'CabinetWClass' window is created" l = findwindows.find_windows(active_only=True, class_name=class_name) return (len(l) > 0) WaitUntil(30, 0.5, _cabinetwclass_exist) handle = findwindows.find_windows(active_only=True, class_name=class_name)[-1] window = WindowSpecification({ 'handle': handle, }) explorer = Application().Connect(process=window.ProcessID()) cur_state = None try: # Go to "Control Panel -> Notification Area Icons" window.AddressBandRoot.ClickInput() window.TypeKeys( r'control /name Microsoft.NotificationAreaIcons{ENTER}', with_spaces=True, set_foreground=False) explorer.WaitCPUUsageLower(threshold=5, timeout=40) # Get the new opened applet notif_area = explorer.Window_(title="Notification Area Icons", class_name=class_name) cur_state = notif_area.CheckBox.GetCheckState() # toggle the checkbox if it differs and close the applet if bool(cur_state) != show_all: notif_area.CheckBox.ClickInput() notif_area.Ok.ClickInput() explorer.WaitCPUUsageLower(threshold=5, timeout=40) except Exception as e: if debug_img: ImageGrab.grab().save("%s.jpg" % (debug_img), "JPEG") l = pywinauto.actionlogger.ActionLogger() l.log("RuntimeError in _toggle_notification_area_icons") raise e finally: # close the explorer window window.Close() return cur_state
class NotepadRegressionTests(unittest.TestCase): """Regression unit tests for Notepad""" 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.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""" 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.set_focus() 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)
def zapytania_sprawaKMS(self): dane1_edit = { 'Nazwa1': 'Kowalski', 'Nazwa2': 'Jan', 'Opis': '-brak-', 'Ulica': 'Zielona', 'Nr. ulicy': '22', 'Miejscowość': 'Kraków', 'Kod pocztowy': '30-092', 'Poczta': 'Dębniki', 'Gmina': 'Kraków', 'Powiat': 'Kraków', 'Województwo': 'Małopolskie', 'Kraj': 'Polska' } dane1_combobox = { 'Osoba': '<BRAK>', 'Typ': 'fizyczna', 'Adres': 'ul.', 'Sąd odwoławczy': 2, 'Status': 0 } dane2_edit = { 'Guid': 'c9a61d68-2647-4a6f-b1ea-4cc5231ad903', 'Imię ojca': 'Janusz', 'Imię matki': 'Ewa', 'Miejsce urodzenia': 'Nowy Targ', 'Nip1': '79', 'Nip2': '20240462', 'Pesel': '96090402194', 'Nr. świad.': '12345', 'Regon': '493317166', } dane1_asercja = [u'Nazwa1:Edit', u'Nazwa2:Edit', u'Opis dod.:Edit', u'&Ulica:Edit', u'Num&er:Edit', u'* &Miejscowość:Edit', u'* &Kod:Edit', u'* &Miejscowość:Edit2', u'* &Gmina:Edit', u'* Powiat:Edit', u'* Woj.:Edit', u'Kraj:Edit', u'U&lica:Edit', u'Numer:Edit', u'Miejscowość:Edit', u'Kod:Edit', u'Poczta:Edit', u'Gmina:Edit', u'Powiat:Edit', u'Woj.:Edit', u'Kraj:Edit2'] dane2_asercja = [u'GUID MPE:Edit', u'Imię ojca:Edit', u'Imię matki.:Edit', u'Msc. ur.:Edit', u'NIP:Edit1', u'&NIP:Edit2', u'Pesel:Edit', u'Inne(nr świad):Edit', u'Regon:Edit2'] dane3_edit = { 'Nazwa1': 'Białek', 'Nazwa2': 'Michał', 'Opis': '-brak-', 'Ulica': 'Malownicza', 'Nr. ulicy': '43', 'Miejscowość': 'Warszawa', 'Kod pocztowy': '00-015', 'Poczta': 'Śródmieście', 'Gmina': 'Warszawa', 'Powiat': 'Warszawa', 'Województwo': 'Mazowieckie', 'Kraj': 'Polska' } dane3_combobox = { 'Osoba': '<BRAK>', 'Typ': 'fizyczna', 'Adres': 'ul.', 'Adres dod.': 'ul.', 'Sąd odwoławczy': 3, 'Status': 0 } dane3_asercja = [u'Nazwa1:Edit', u'Nazwa2:Edit', u'Opis dod.:Edit', u'&Ulica:Edit', u'Num&er:Edit', u'* &Miejscowość:Edit', u'* &Kod:Edit', u'* &Miejscowość:Edit2', u'* &Gmina:Edit', u'* Powiat:Edit', u'* Woj.:Edit', u'Kraj:Edit', u'U&lica:Edit', u'Numer:Edit', u'Miejscowość:Edit', u'Kod:Edit', u'Poczta:Edit', u'Gmina:Edit', u'Powiat:Edit', u'Woj.:Edit', u'Kraj:Edit2'] dane4_edit = { 'Guid': 'fc0037b9-b37b-4861-a20b-51754f9a5b11', 'Imię ojca': 'Rafał', 'Imię matki': 'Bożena', 'Miejsce urodzenia': 'Nowy Sącz', 'Nip1': '', 'Nip2': '2850987181', 'Pesel': '96090402194', 'Nr. świad.': '12345', 'Regon': '493317166' } dane4_asercja = [u'GUID MPE:Edit', u'Imię ojca:Edit', u'Imię matki.:Edit', u'Msc. ur.:Edit', u'NIP:Edit1', u'NIP:Edit2', u'Pesel:Edit', u'Inne(nr świad):Edit', u'Regon:Edit2'] sleep(1.5) self.app[kkvat].TreeView.GetItem([u'Tytuły Wykonawcze']).Click() self.app[kkvat].type_keys('{ENTER}') self.app[kkvat].type_keys('{INSERT}') self.app.Dialog.Combobox.Select(u'Postanowienie') self.app.Dialog.Edit2.type_keys('Kms2') self.app.Dialog.Zapisz.Click() logging.info('TYTUŁY WYKONAWCZE - ASERCJA') dlugosc_tytuly = len(self.app[kkvat].ListView2.texts()) assert 'Tytuły wykonawcze' in self.app[kkvat].Static1.Texts()[0], 'Tytuły wykonawcze - nazwa okna.' zmiana_drzewa(self, '\\Wierzyciele', 'WIERZYCIELE') self.app.Dialog.Anuluj.Click() # *** 1 Zakładka "Dane podst" *** dialog_wprowadzanie_danych(self, dane1_edit, dane1_asercja, 'WIERZYCIELE - DANE PODSTAWOWE') dialog_wybór_combobox(self, dane1_combobox, 'WIERZYCIELE - DANE PODSTAWOWE') # *** 3 Zakładka "Dane uzupełniające" *** zmiana_zakładki(self, 1, 'WIERZYCIELE - DANE UZUPEŁNIAJĄCE') logging.info('WIERZYCIELE - DANE UZUPEŁNIAJĄCE - Combobox - Typ dokumentu') self.app.Dialog.ComboBox.Select(0) dialog_wprowadzanie_danych(self, dane2_edit, dane2_asercja, 'WIERZYCIELE - DANE UZUPEŁNIAJĄCE') self.app.Dialog.print_control_identifiers() # *** Zapis utworzonego Wierzyciela *** self.app.Dialog.Wait('ready') logging.info('WIERZYCIELE - DANE DODATKOWE - Button - Zapisz') self.app.Dialog.Zapisz.Click() # *** Asercja wprowadzonych danych *** logging.info('') logging.info('WIERZYCIELE - ASERCJA - START') assert 'Wierzyciele' in self.app[kkvat].Static1.Texts()[0], 'Wierzyciele - nazwa okna.' # Wierzyciel rachunki zmiana_drzewa(self, '\\Wierzyciele\\Rachunki bankowe', 'RACHUNKI BANKOWE') self.app.Dialog.Wait('ready') logging.info('RACHUNKI BANKOWE - Edit - Rachunek') self.app.Dialog.Edit1.type_keys('70200001') self.app.Dialog.Button1.Click() logging.info('RACHUNKI BANKOWE - Button - 1 (Automatyczne wypełnianie danych)') logging.info('RACHUNKI BANKOWE - Button - OK') self.app.Dialog.Button.Click() self.app.Dialog.OK.Click() zmiana_drzewa(self, '\\Dłużnik', 'Dłużnik') self.app.Dialog.Anuluj.Click() dialog_wprowadzanie_danych(self, dane3_edit, dane3_asercja, 'DŁUŻNICY - DANE PODSTAWOWE') dialog_wybór_combobox(self, dane3_combobox, 'DŁUŻNICY - DANE PODSTAWOWE') zmiana_zakładki(self, 1, 'DŁUŻNICY - DANE UZUPEŁNIAJĄCE') self.app.Dialog.ComboBox.Select(0) dialog_wprowadzanie_danych(self, dane4_edit, dane4_asercja, 'DŁUŻNICY - DANE UZUPEŁNIAJĄCE') self.app.Dialog.Zapisz.Click() self.app.Dialog.Wait('ready') self.app.Dialog.Button2.Click() self.app[kkvat].type_keys('^s^c') self.app[kkvat].ListView2.DoubleClick() self.app.Dialog.Button10.Click() # *** Dodawanie pojedynczych bankow ***# self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 2}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 3}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 4}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 5}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 6}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 7}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 8}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 9}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Button.Click() self.app.Dialog.type_keys('{DOWN 10}') self.app.Dialog.type_keys('{ENTER}') self.app.Dialog.Zapisz.Click() self.app.Dialog.Zapisz.Click() zapis(self) menu_glowne(self, menu_button='Biurowość', submenu_1='Ognivo2', submenu_2='e-Zapytania (wysłane/odebrane)') self.app[kkvat].type_keys('{DOWN 9}') self.app[kkvat].type_keys('{RIGHT}') self.app[kkvat].type_keys('{ENTER}') self.app[kkvat].Button3.Click() self.app[kkvat].ListView2.Click() self.app[kkvat].type_keys('^a^c') self.app[kkvat].Button2.Click() sleep(5) forma = Application().connect(title_re=".*certyfikatu.*") forma.Window_(title='Wybór certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').Wait('visible') forma.Window_(title='Wybór certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').SetFocus() forma.Window_(title='Wybór certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').Button5.Click() #forma.Window_(title='Wybór certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').type_keys('{ENTER}') forma.Window_(title='Wybór certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').Button4.Click() forma.Window_(title='Podaj PIN do certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').Edit2.ClickInput() forma.Window_(title='Podaj PIN do certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').Edit2.type_keys('1111') forma.Window_(title='Podaj PIN do certyfikatu KWALIFIKOWANEGO (podpis elektroniczny)').OK.Click() forma.Window_(title='Wybór certyfikatu NIEKWALIFIKOWANEGO (logowanie)').type_keys('{ENTER}')
class HwndWrapperMenuTests(unittest.TestCase): """Unit tests for menu actions of the HwndWrapper class""" 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"RowList.exe")) self.dlg = self.app.RowListSampleApplication self.ctrl = self.app.RowListSampleApplication.ListView.WrapperObject() def tearDown(self): """Close the application after tests""" self.dlg.SendMessage(win32defines.WM_CLOSE) def testMenuItems(self): self.assertEqual(self.ctrl.MenuItems(), []) self.assertEqual(self.dlg.MenuItems()[1]['text'], '&View') def testMenuSelect(self): "Test selecting a menu item" if self.dlg.MenuItem("View -> Toolbar").IsChecked(): self.dlg.MenuSelect("View -> Toolbar") self.assertEquals( self.dlg.MenuItem("View -> Toolbar").IsChecked(), False) self.dlg.MenuSelect("View -> Toolbar") self.assertEquals( self.dlg.MenuItem("View -> Toolbar").IsChecked(), True) def testClose(self): "Test the Close() method of windows" # open about dialog self.dlg.MenuSelect('Help->About RowList...') # make sure it is open and visible self.app.AboutRowList.Wait("visible", 20) self.assertTrue( self.app.Window_(title='About RowList').is_visible(), True) # close it self.app.Window_(title='About RowList', class_name='#32770').Close(1) # make sure that it is not visible try: #self.assertRaises(ElementNotFoundError, self.app.Window_(title='About RowList', class_name='#32770').WrapperObject()) # vvryabov: TimeoutError is caught by assertRaises, so the second raise is not caught correctly self.app.Window_(title='About RowList', class_name='#32770').WrapperObject() except ElementNotFoundError: print('ElementNotFoundError exception is raised as expected. OK.') # make sure the main RowList dialog is still open self.assertEquals(self.dlg.is_visible(), True) def testCloseClick_bug(self): self.dlg.MenuSelect('Help->About RowList...') self.app.AboutRowList.Wait("visible", 10) self.assertEqual(self.app.AboutRowList.Exists(), True) self.app.AboutRowList.CloseButton.CloseClick() self.assertEqual(self.app.AboutRowList.Exists(), False) #Timings.closeclick_dialog_close_wait = .7 #try: # self.app.AboutRowList.CloseButton.CloseClick() #except TimeoutError: # pass #self.app.AboutRowList.Close() def testCloseAltF4(self): self.dlg.MenuSelect('Help->About RowList...') AboutRowList = self.app.Window_(title='About RowList', active_only=True, class_name='#32770') AboutWrapper = AboutRowList.Wait("enabled") AboutRowList.CloseAltF4() AboutRowList.WaitNot('visible') self.assertNotEqual(AboutWrapper.is_visible(), True)
def _toggle_notification_area_icons(show_all=True, debug_img=None): """ A helper function to change 'Show All Icons' settings. On a succesful execution the function returns an original state of 'Show All Icons' checkbox. The helper works only for an "English" version of Windows, on non-english versions of Windows the 'Notification Area Icons' window should be accessed with a localized title" """ Application().start(r'explorer.exe') class_name = 'CabinetWClass' def _cabinetwclass_exist(): "Verify if at least one active 'CabinetWClass' window is created" l = findwindows.find_elements(active_only=True, class_name=class_name) return (len(l) > 0) WaitUntil(_ready_timeout, _retry_interval, _cabinetwclass_exist) handle = findwindows.find_elements(active_only=True, class_name=class_name)[-1].handle window = WindowSpecification({ 'handle': handle, 'backend': 'win32', }) explorer = Application().Connect(process=window.process_id()) cur_state = None try: # Go to "Control Panel -> Notification Area Icons" cmd_str = r'control /name Microsoft.NotificationAreaIcons' for _ in range(3): window.Wait("ready", timeout=_ready_timeout) window.AddressBandRoot.click_input() explorer.WaitCPUUsageLower(threshold=2, timeout=_ready_timeout) window.type_keys(cmd_str, with_spaces=True, set_foreground=True) # verfiy the text in the address combobox after type_keys finished if window.AddressBandRoot.ComboBoxEx.texts()[0] == cmd_str: break else: l = pywinauto.actionlogger.ActionLogger() l.log(window.AddressBandRoot.ComboBoxEx.texts()) # Send ESCs to remove the invalid text window.type_keys("{ESC}" * 3) # Send 'ENTER' separately, this is to make sure # the window focus hasn't accidentally been lost window.type_keys('{ENTER}', with_spaces=True, set_foreground=True) explorer.WaitCPUUsageLower(threshold=5, timeout=_ready_timeout) # Get the new opened applet notif_area = explorer.Window_(title="Notification Area Icons", class_name=class_name) notif_area.Wait("ready", timeout=_ready_timeout) cur_state = notif_area.CheckBox.GetCheckState() # toggle the checkbox if it differs and close the applet if bool(cur_state) != show_all: notif_area.CheckBox.click_input() notif_area.Ok.click_input() explorer.WaitCPUUsageLower(threshold=5, timeout=_ready_timeout) except Exception as e: if debug_img: from PIL import ImageGrab ImageGrab.grab().save("%s.jpg" % (debug_img), "JPEG") l = pywinauto.actionlogger.ActionLogger() l.log("RuntimeError in _toggle_notification_area_icons") raise e finally: # close the explorer window window.Close() return cur_state