def testShoppingListGenerationFromCard (self): # Test multiplication + no multiplication self.focus_nth_recipe() dp.keyCombo('<Ctrl>o') # open recipe card dp.focus.frame('') dp.click('Actions') dp.click('Shop') # using shop button dp.focus.frame('Shopping List') screenshot('add-to-shopping-list-from-card-w-button.png') dp.keyCombo('<Ctrl>w') dp.focus.frame('') dp.click('Recipe') dp.click("Add to Shopping List") # from menu dp.focus.frame('Shopping List') screenshot('add-to-shopping-list-from-card-w-menu.png') screenshot('Adding Shopping List from Card') dp.keyCombo('<Ctrl>w') dp.focus.frame('') dp.keyCombo('<Alt>y') dp.focus.text() dp.type('12') # double... dp.keyCombo('<Ctrl>l') # from keyboard dp.keyCombo('<Return>') screenshot('add-to-shopping-list-from-card-w-keyboard-multiplied-by-2.png') dp.keyCombo('<Ctrl>w')
def mainProgram(self): """ In this function things are hardcoded a bit.Also dogtail modules are imported inside. """ #####types##### # observer : object of class Observer # children_of_gnometerm : list of objects of class Accessibility.Accessible *i think # index_of_frame : integer # frameName : string from observer import Observer from dogtail.procedural import FocusApplication, click, keyCombo, type import dogtail.rawinput observer = Observer() observer.openWindowFromMenu(['Applications', 'Accessories', 'Terminal']) if(not observer.isFocussed('gnome-terminal')): raise Error("Could not focus gnome-termnal") children_of_gnometerm = FocusApplication.node.children index_of_frame = len(children_of_gnometerm)-1 #index of last created frame frameName = children_of_gnometerm[index_of_frame].name if(not observer.frameFocussed(frameName)): raise Error("Could not focus frame " + frameName) type("sudo apt-get install ")
def test_typing_on_widget(self): self.runDemo('Dialog and Message Boxes') focus.window('Dialogs') focus.widget(roleName='text') type("hello world") from time import sleep sleep(0.1) self.assertEquals(focus.widget.node.text, 'hello world')
def search_and_open (self, txt): dp.focus.frame("Gourmet Recipe Manager") dp.keyCombo('<Alt>S') # Focus search dp.focus.text() dp.type(txt) # Search for our recipe dp.keyCombo('<Alt>L') # Focus recipe list dp.keyCombo('Return') # Open recipe time.sleep(1)
def testDeselect(self): type('Icon View') click('Icon View') type('+') self.runDemo('Icon View Basics') focus.window('GtkIconView demo') focus.widget(roleName='icon') select() deselect() self.assertFalse(focus.widget.isSelected)
def save_as(self, filename: Path): """ Save as""" d = filename.parent d.resolve() assert filename.suffix == ".img" path = str(d / filename.stem) self.menu("Slideshow", "Save As") filechooser = self.imagination.child(roleName="file chooser") button = filechooser.childNamed("Save") type(str(path)) button.click()
def test_deselect(self): type('Icon View') click('Icon View') type('+') sleep(0.5) self.runDemo('Icon View Basics') focus.window('GtkIconView demo') focus.widget(roleName='icon') select() deselect() self.assertFalse(focus.widget.isSelected)
def test_typing_on_widget(self): try: self.runDemo('Dialog and Message Boxes', retry=False) focus.window('Dialogs') except SearchError: self.runDemo('Dialogs and Message Boxes', retry=False) focus.window('Dialogs and Message Boxes') focus.widget(roleName='text') type("hello world") from time import sleep sleep(0.1) self.assertEqual(focus.widget.node.text, 'hello world')
def test_deselect(self): type('Icon View') click('Icon View') type('+') sleep(0.5) self.runDemo('Icon View Basics') try: wnd = self.app.child('GtkIconView demo', roleName='frame', recursive=False, retry=False) except SearchError: wnd = self.app.child('Icon View Basics', roleName='frame', recursive=False, retry=False) focus.window(wnd.name) focus.widget(roleName='icon') select() deselect() self.assertFalse(focus.widget.isSelected)
def do_testFileImport (self, fn): shortname = os.path.split(fn)[1] dp.focus.application(APPNAME) dp.focus.frame('Gourmet Recipe Manager') dp.click("File") dp.click("Import file") dp.focus.dialog('Open recipe...') dp.keyCombo("<Alt>l") dp.type(fn) screenshot('import_dialog-%s-.png'%shortname) dp.keyCombo("Return") time.sleep(5) # wait for import to complete... print 'DONE SLEEPING -- IMPORT SHOULD BE DONE!' screenshot('import_done-%s.png'%shortname) dp.keyCombo("<Alt>C") # close dialog dp.focus.frame('Gourmet Recipe Manager') screenshot('with_imported_recs-%s.png'%shortname)
def do_testWebImport (self, url): shortname = url.split('/')[-1] dp.focus.application(APPNAME) dp.focus.frame('Gourmet Recipe Manager') dp.click("File") dp.click('Import webpage') time.sleep(2) dp.focus.frame('Enter website address') print 'TYPING URL!' dp.type(url) dp.keyCombo("Return") time.sleep(1) screenshot('manual_web_import-%s.png'%shortname) dp.click('OK') screenshot('manual_web_import_done-%s.png'%shortname) dp.focus.dialog('Gourmet Import/Export') dp.click('Close')
def do_testWebImport (self, url): shortname = url.split('/')[-1] dp.focus.application(APPNAME) dp.focus.frame('Gourmet Recipe Manager') dp.click("File") dp.click('Import webpage') time.sleep(2) dp.focus.frame('Enter website address') print('TYPING URL!') dp.type(url) dp.keyCombo("Return") time.sleep(1) screenshot('manual_web_import-%s.png'%shortname) dp.click('OK') screenshot('manual_web_import_done-%s.png'%shortname) dp.focus.dialog('Gourmet Import/Export') dp.click('Close')
def do_testFileImport (self, fn): shortname = os.path.split(fn)[1] dp.focus.application(APPNAME) dp.focus.frame('Gourmet Recipe Manager') dp.click("File") dp.click("Import file") dp.focus.dialog('Open recipe...') dp.keyCombo("<Alt>l") dp.type(fn) screenshot('import_dialog-%s-.png'%shortname) dp.keyCombo("Return") time.sleep(5) # wait for import to complete... print('DONE SLEEPING -- IMPORT SHOULD BE DONE!') screenshot('import_done-%s.png'%shortname) dp.keyCombo("<Alt>C") # close dialog dp.focus.frame('Gourmet Recipe Manager') screenshot('with_imported_recs-%s.png'%shortname)
def testShoppingListGenerationFromIndex (self): self.focus_nth_recipe(0) dp.click('Actions') dp.click('Add to Shopping List') screenshot('generate_shopping_list_from_index.png') dp.focus.dialog('') dp.click('OK') screenshot('generated_shopping_list_from_index.png') dp.focus.frame('Shopping List') dp.keyCombo('<Ctrl>w') # Add a second recipe to the list... self.focus_nth_recipe(1) dp.keyCombo('<Ctrl>l') # Add with keycombo... dp.focus.dialog('') dp.focus.text() dp.type('12') dp.keyCombo('<Return>') screenshot('shopping list With two recipes+mult.png') dp.keyCombo('<Ctrl>w')
def test_unit_converter(): """Dogtail integration test: Unit converter plugin behaves as intended.""" cmd = "gourmet" pid = run(cmd, timeout=3) gourmet = None for app in tree.root.applications(): if app.get_process_id() == pid: gourmet = app break assert gourmet is not None, "Could not find Gourmet instance!" # Open the unit converter plugin procedural.keyCombo("<Alt>T") procedural.keyCombo("U") procedural.focus.window("Unit Converter") # Enter source amount and unit (5 liters) procedural.keyCombo("<Alt>A") procedural.type("5") procedural.keyCombo("<Alt>U") procedural.keyCombo("<Enter>") procedural.click("liter (l)") # Enter target unit (ml) procedural.keyCombo("<Alt>U") procedural.keyCombo("<Enter>") procedural.keyCombo("Right") for _ in range(7): procedural.keyCombo("Down") procedural.keyCombo("<Enter>") # Check that the result is shown correctly assert procedural.focus.widget(name="5 l = 5000 ml", roleName="label") # There are now two windows, the unit converter, and main window # Close them successively to quit the application procedural.keyCombo("<Alt><F4>") procedural.keyCombo("<Alt><F4>")
def export(self) -> Path: """ Export the slideshow to a file whose path is returned """ out = self.temp / "export.vob" self.menu("Slideshow", "Export") self.imagination.child("Export Settings").child( roleName="text").click() type(str(out)) self.imagination.child(roleName="dialog").button("OK").click() pause = self.imagination.child("Exporting the slideshow").child( "Pause") while pause.showing: sleep(0.3) status = (self.imagination.child("Exporting the slideshow").child( description="Status of export").text) self.imagination.child("Exporting the slideshow").button( "Close").click() if "failed" in status.lower(): raise ExportFailed(status) out.resolve() return out
def testEditingNewCard (self): dp.focus.application(APPNAME) dp.focus.frame('Gourmet Recipe Manager') #dp.keyCombo('<Ctrl>n') dp.click('File') dp.click('New') dp.focus.frame('New Recipe (Edit)') dp.keyCombo('<Alt>l') dp.focus.widget('Title Entry') time.sleep(1) dp.type('Testing!') dp.focus.widget('Preparation Time Entry') time.sleep(1) dp.type('30 minutes') dp.focus.widget('Rating Entry') time.sleep(1) dp.type('4') screenshot('Edited_recipe.png') #dp.keyCombo('<Ctrl>w') dp.click("Recipe") dp.click("Close") screenshot('save_changes_to_edited_rec.png') dp.focus.dialog('Question') #dp.keyCombo('<Alt>C') dp.click("Cancel") #self.assertEqual(hasattr(rc,'recipe_editor'),True,'Cancelling save-changes did not work') dp.focus.frame('New Recipe (Edit)') time.sleep(3) dp.keyCombo('<Ctrl>w') time.sleep(3) dp.focus.dialog('Question') dp.keyCombo('<Alt>s') screenshot('new_rec_saved.png')
def testEditingNewCard (self): dp.focus.application(APPNAME) dp.focus.frame('Gourmet Recipe Manager') #dp.keyCombo('<Ctrl>n') dp.click('File') dp.click('New') dp.focus.frame(u'New Recipe (Edit)') dp.keyCombo('<Alt>l') dp.focus.widget('Title Entry') time.sleep(1) dp.type('Testing!') dp.focus.widget('Preparation Time Entry') time.sleep(1) dp.type('30 minutes') dp.focus.widget('Rating Entry') time.sleep(1) dp.type('4') screenshot('Edited_recipe.png') #dp.keyCombo('<Ctrl>w') dp.click("Recipe") dp.click("Close") screenshot('save_changes_to_edited_rec.png') dp.focus.dialog('Question') #dp.keyCombo('<Alt>C') dp.click("Cancel") #self.assertEqual(hasattr(rc,'recipe_editor'),True,'Cancelling save-changes did not work') dp.focus.frame(u'New Recipe (Edit)') time.sleep(3) dp.keyCombo('<Ctrl>w') time.sleep(3) dp.focus.dialog('Question') dp.keyCombo('<Alt>s') screenshot('new_rec_saved.png')
t = tempfile.NamedTemporaryFile() t.write(""" 2015-10-05 * beer Assets:Cash -30 CHF Expenses:Drinking 30 CHF """) t.flush() t.seek(0, 0) run('addtrans --file %s' % pipes.quote(t.name)) addtrans = tree.root.application('addtrans') mainwin = addtrans.window('Add transaction') try: type("wine") pressKey("Tab") type("30") pressKey("Tab") type("Expenses:Drinking") pressKey("Tab") pressKey("Tab") type("Assets:Cash") pressKey("Tab") expected = """ 2016-11-09 wine Expenses:Drinking 30 CHF Assets:Cash """
def testTyping(self): self.runDemo('Dialog and Message Boxes') focus.window('Dialogs') focus.widget(roleName='text') type("hello world") self.assertEquals(focus.widget.node.text, 'hello world')