diff --git a/tests/uitests/test_addhardware.py b/tests/uitests/test_addhardware.py index 817c43b5..0abdf9fc 100644 --- a/tests/uitests/test_addhardware.py +++ b/tests/uitests/test_addhardware.py @@ -152,9 +152,7 @@ class AddHardware(uiutils.UITestCase): volcell = browse.find(newname, "table cell") self.assertTrue(volcell.selected) browse.find("vol-delete", "push button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("permanently delete the volume", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("permanently delete the volume", "Yes") uiutils.check_in_loop(lambda: volcell.dead) # Test browse local @@ -181,9 +179,7 @@ class AddHardware(uiutils.UITestCase): browse.find("Choose Volume", "push button").click() self.assertTrue("/diskvol1" in tab.find("storage-entry").text) finish.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("already in use by", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("already in use by", "Yes") uiutils.check_in_loop(lambda: details.active) @@ -248,9 +244,7 @@ class AddHardware(uiutils.UITestCase): finish.click() # Check MAC validation error - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("00:11:22:33:44:55", "label") - alert.find("Close", "push button").click() + self._click_alert_button("00:11:22:33:44:55", "Close") # Fix MAC tab.find("mac-address-enable", "check box").click() @@ -286,9 +280,7 @@ class AddHardware(uiutils.UITestCase): finish.click() # Catch a port error - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Port must be above 5900", "label") - alert.find("Close", "push button").click() + self._click_alert_button("Port must be above 5900", "Close") tab.find("graphics-port", "spin button").text = "5920" finish.click() uiutils.check_in_loop(lambda: details.active) @@ -329,9 +321,7 @@ class AddHardware(uiutils.UITestCase): tab = self._select_hw(addhw, "USB Host Device", "host-tab") tab.find_fuzzy("HP Dup USB 1", "table cell").click() finish.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("device is already in use by", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("device is already in use by", "Yes") uiutils.check_in_loop(lambda: details.active) # Add USB device dup2 @@ -339,9 +329,7 @@ class AddHardware(uiutils.UITestCase): tab = self._select_hw(addhw, "USB Host Device", "host-tab") tab.find_fuzzy("HP Dup USB 2", "table cell").click() finish.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("device is already in use by", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("device is already in use by", "Yes") uiutils.check_in_loop(lambda: details.active) # Add another USB device @@ -356,9 +344,7 @@ class AddHardware(uiutils.UITestCase): tab = self._select_hw(addhw, "PCI Host Device", "host-tab") tab.find_fuzzy("(Interface eth0)", "table cell").click() finish.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("device is already in use by", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("device is already in use by", "Yes") uiutils.check_in_loop(lambda: details.active) @@ -587,9 +573,7 @@ class AddHardware(uiutils.UITestCase): newpath = "/FOO/XMLEDIT/test1.img" xmleditor.text = xmleditor.text.replace(origpath, newpath) finish.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("non-existent path") - alert.find("Close", "push button").click() + self._click_alert_button("non-existent path", "Close") # Undo the bad change, change bus/target xmleditor.text = xmleditor.text.replace(newpath, origpath) diff --git a/tests/uitests/test_cli.py b/tests/uitests/test_cli.py index bd96465c..42ce7af6 100644 --- a/tests/uitests/test_cli.py +++ b/tests/uitests/test_cli.py @@ -75,8 +75,7 @@ class VMMCLI(uiutils.UITestCase): delete = self.app.topwin delete.find_fuzzy("Delete", "button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Yes", "push button").click() + self._click_alert_button("Are you sure", "Yes") # Ensure app exits uiutils.check_in_loop(lambda: not self.app.is_running()) @@ -99,13 +98,11 @@ class VMMCLI(uiutils.UITestCase): def testShowCLIError(self): self.app.open(extra_opts=["--idontexist"]) - alert = self.app.root.find("vmm dialog") - alert.find_fuzzy("Unhandled command line") + self._click_alert_button("Unhandled command line", "Close") + uiutils.check_in_loop(lambda: not self.app.is_running()) def testShowConnectBadURI(self): baduri = "fribfrobfroo" self.app = uiutils.VMMDogtailApp(baduri) - alert = self.app.root.find("vmm dialog") - alert.find_fuzzy(baduri) - alert.find_fuzzy("Close", "push button").click() + self._click_alert_button(baduri, "Close") uiutils.check_in_loop(lambda: not self.app.is_running()) diff --git a/tests/uitests/test_connect.py b/tests/uitests/test_connect.py index 62db144b..91282e1a 100644 --- a/tests/uitests/test_connect.py +++ b/tests/uitests/test_connect.py @@ -22,9 +22,7 @@ class VMMConnect(uiutils.UITestCase): uiutils.check_in_loop(lambda: "Not Connected" in c.text) c.click(button=3) self.app.root.find("conn-delete", "menu item").click() - err = self.app.root.find("vmm dialog", "alert") - err.find_fuzzy("will remove the connection", "label") - err.find_fuzzy("Yes", "push button").click() + self._click_alert_button("will remove the connection", "Yes") uiutils.check_in_loop(lambda: c.dead) # Launch the dialog, grab some UI pointers @@ -61,8 +59,7 @@ class VMMConnect(uiutils.UITestCase): c = self.app.root.find_fuzzy(fakehost, "table cell") uiutils.check_in_loop(lambda: "Connecting..." not in c.text, timeout=10) - err = self.app.root.find_fuzzy("vmm dialog", "alert") - err.find_fuzzy("No", "push button").click() + self._click_alert_button("Unable to connect", "No") # Ensure dialog shows old contents for editing uiutils.check_in_loop(lambda: win.showing) @@ -74,8 +71,7 @@ class VMMConnect(uiutils.UITestCase): c = self.app.root.find_fuzzy(fakehost, "table cell") uiutils.check_in_loop(lambda: "Connecting..." not in c.text, timeout=10) - err = self.app.root.find_fuzzy("vmm dialog", "alert") - err.find_fuzzy("Yes", "push button").click() + self._click_alert_button("Unable to connect", "Yes") c = self.app.root.find_fuzzy(fakehost, "table cell") # Test with custom test:///default connection diff --git a/tests/uitests/test_createnet.py b/tests/uitests/test_createnet.py index fcf204b4..a47d8d23 100644 --- a/tests/uitests/test_createnet.py +++ b/tests/uitests/test_createnet.py @@ -50,9 +50,7 @@ class CreateNet(uiutils.UITestCase): # Delete it delete.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("permanently delete the network", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("permanently delete the network", "Yes") # Ensure it's gone uiutils.check_in_loop(lambda: cell.dead) diff --git a/tests/uitests/test_createpool.py b/tests/uitests/test_createpool.py index 2a713d54..64010215 100644 --- a/tests/uitests/test_createpool.py +++ b/tests/uitests/test_createpool.py @@ -61,9 +61,7 @@ class CreatePool(uiutils.UITestCase): # Delete it delete.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("permanently delete the pool", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("permanently delete the pool", "Yes") # Ensure it's gone uiutils.check_in_loop(lambda: cell.dead) @@ -91,9 +89,7 @@ class CreatePool(uiutils.UITestCase): _browse_local_path("Choose target directory", "by-path") finish.click() # Catch example error - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("source host name", "label") - alert.find("Close", "push button").click() + self._click_alert_button("source host name", "Close") win.find("Host Name:", "text").text = "example.com" win.find("pool-source-path-text").text = "foo-iqn" win.find_fuzzy("Initiator IQN:", "check").click() diff --git a/tests/uitests/test_createvol.py b/tests/uitests/test_createvol.py index 1f10bfb7..48cc77ba 100644 --- a/tests/uitests/test_createvol.py +++ b/tests/uitests/test_createvol.py @@ -42,9 +42,7 @@ class CreateVol(uiutils.UITestCase): volcell.click() hostwin.find("vol-refresh", "push button").click() hostwin.find("vol-delete", "push button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("permanently delete the volume", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("permanently delete the volume", "Yes") uiutils.check_in_loop(lambda: volcell.dead) diff --git a/tests/uitests/test_details.py b/tests/uitests/test_details.py index 47a05525..2dd02624 100644 --- a/tests/uitests/test_details.py +++ b/tests/uitests/test_details.py @@ -252,9 +252,7 @@ class Details(uiutils.UITestCase): tab.find("Device name:", "text").text = "" appl.click() # Check validation error - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Error changing VM configuration", "label") - alert.find("Close", "push button").click() + self._click_alert_button("Error changing VM configuration", "Close") tab.find("Device name:", "text").text = "zbr0" appl.click() uiutils.check_in_loop(lambda: not appl.sensitive) @@ -383,9 +381,7 @@ class Details(uiutils.UITestCase): delete.find_fuzzy("Delete", "button").click() # Will be fixed eventually - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Device could not be removed", "label") - alert.find("OK", "push button").click() + self._click_alert_button("Device could not be removed", "OK") c = hwlist.find(disklabel, "table cell") self._stop_vm(win) @@ -410,9 +406,7 @@ class Details(uiutils.UITestCase): share = tab.find("Shareable:", "check box") share.click() hwlist.find("CPUs", "table cell").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("There are unapplied changes", "label") - alert.find("No", "push button").click() + self._click_alert_button("There are unapplied changes", "No") tab = self._select_hw(win, "IDE Disk 1", "disk-tab") self.assertFalse(share.checked) @@ -439,9 +433,7 @@ class Details(uiutils.UITestCase): # Now apply changes to running VM, ensure they show up on shutdown win.find("config-apply").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("changes will take effect", "label") - alert.find("OK", "push button").click() + self._click_alert_button("changes will take effect", "OK") self.assertTrue(share.checked) self._stop_vm(win) self.assertTrue(not share.checked) @@ -450,17 +442,13 @@ class Details(uiutils.UITestCase): tab = self._select_hw(win, "Overview", "overview-tab") tab.find("Description:", "text").text = "hey new description" win.find("XML", "page tab").click() - alert = self.app.root.find("vmm dialog") - alert.find_fuzzy("changes will be lost") - # Select 'No', meaning don't abandon changes - alert.find("No", "push button").click() + self._click_alert_button("changes will be lost", "No") uiutils.check_in_loop(lambda: tab.showing) # Try unapplied changes again, this time abandon our changes win.find("XML", "page tab").click() - alert = self.app.root.find("vmm dialog") - alert.find("Yes", "push button").click() + self._click_alert_button("changes will be lost", "Yes") uiutils.check_in_loop(lambda: not tab.showing) def testDetailsXMLEdit(self): diff --git a/tests/uitests/test_livetests.py b/tests/uitests/test_livetests.py index b3e1d0e8..da1c83ea 100644 --- a/tests/uitests/test_livetests.py +++ b/tests/uitests/test_livetests.py @@ -122,9 +122,7 @@ class Console(uiutils.UITestCase): # Check wrong password handling passwd.typeText("xx") win.find("Login", "push button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Viewer authentication error", "label") - alert.find("OK", "push button").click() + self._click_alert_button("Viewer authentication error", "OK") # Check proper password passwd.typeText("goodp") @@ -185,9 +183,8 @@ class Console(uiutils.UITestCase): addhw.find("Finish", "push button").click() # Verify permission dialog pops up, ask to change - alert = self.app.root.find("vmm dialog", "alert") - alert.find("The emulator may not have search permissions") - alert.find("Yes", "push button").click() + self._click_alert_button( + "The emulator may not have search permissions", "Yes") # Verify no errors uiutils.check_in_loop(lambda: not addhw.showing) diff --git a/tests/uitests/test_manager.py b/tests/uitests/test_manager.py index 84f2e81a..2356b0fb 100644 --- a/tests/uitests/test_manager.py +++ b/tests/uitests/test_manager.py @@ -30,9 +30,7 @@ class Manager(uiutils.UITestCase): c.click() smenu.click() force.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find("Are you sure you want", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("Are you sure you want", "Yes") uiutils.check_in_loop(lambda: run.sensitive, timeout=5) run.click() @@ -158,9 +156,7 @@ class Manager(uiutils.UITestCase): c = manager.find_fuzzy("testdriver.xml", "table cell") c.click(button=3) self.app.root.find("conn-delete", "menu item").click() - err = self.app.root.find("vmm dialog", "alert") - err.find_fuzzy("will remove the connection", "label") - err.find_fuzzy("Yes", "push button").click() + self._click_alert_button("will remove the connection", "Yes") uiutils.check_in_loop(lambda: not host.showing) def testManagerDefaultStartup(self): diff --git a/tests/uitests/test_mediachange.py b/tests/uitests/test_mediachange.py index 8b6991c6..f10048ec 100644 --- a/tests/uitests/test_mediachange.py +++ b/tests/uitests/test_mediachange.py @@ -66,9 +66,7 @@ class MediaChange(uiutils.UITestCase): browsewin.find("Choose Volume", "push button").click() appl.click() # Check 'already in use' dialog - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("already in use by", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("already in use by", "Yes") uiutils.check_in_loop(lambda: not appl.sensitive) self.assertTrue("backing" in entry.text) entry.text = "" @@ -91,9 +89,7 @@ class MediaChange(uiutils.UITestCase): self.assertTrue(not entry.text) entry.text = "/dev/sr0" appl.click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("changes will take effect", "label") - alert.find("OK", "push button").click() + self._click_alert_button("changes will take effect", "OK") uiutils.check_in_loop(lambda: not appl.sensitive) self.assertTrue(not entry.text) diff --git a/tests/uitests/test_migrate.py b/tests/uitests/test_migrate.py index d15ab20c..b16e803a 100644 --- a/tests/uitests/test_migrate.py +++ b/tests/uitests/test_migrate.py @@ -31,8 +31,7 @@ class VMMMigrate(uiutils.UITestCase): mig = self.app.root.find("Migrate the virtual machine", "frame") mig.find("Advanced", "toggle button").click_expander() mig.find("Migrate", "push button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("the.connection.driver:.virDomainMigrate") - alert.find("Close", "push button").click() + self._click_alert_button( + "the.connection.driver:.virDomainMigrate", "Close") mig.find("Cancel", "push button").click() uiutils.check_in_loop(lambda: not mig.showing) diff --git a/tests/uitests/test_newvm.py b/tests/uitests/test_newvm.py index 632751a7..1d72fa0a 100644 --- a/tests/uitests/test_newvm.py +++ b/tests/uitests/test_newvm.py @@ -92,9 +92,7 @@ class NewVM(uiutils.UITestCase): # Make sure we throw an error if no OS selected self.forward(newvm, check=False) - alert = self.app.root.find("vmm dialog", "alert") - alert.find("You must select", "label") - alert.find("OK", "push button").click() + self._click_alert_button("You must select", "OK") # Test activating the osentry to grab the popover selection osentry.click() @@ -130,8 +128,7 @@ class NewVM(uiutils.UITestCase): delete = self.app.root.find_fuzzy("Delete", "frame") delete.find_fuzzy("Delete", "button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Yes", "push button").click() + self._click_alert_button("Are you sure", "Yes") # Verify delete dialog and VM dialog are now gone uiutils.check_in_loop(lambda: vmwindow.showing is False) @@ -370,8 +367,7 @@ class NewVM(uiutils.UITestCase): self.forward(newvm, check=False) # Disk collision box pops up, hit ok - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Yes", "push button").click() + self._click_alert_button("in use", "Yes") self.forward(newvm) newvm.find_fuzzy("Finish", "button").click() @@ -522,9 +518,7 @@ class NewVM(uiutils.UITestCase): # '/' in name will trigger libvirt error _newvm.find_fuzzy("Name", "text").text = "test/bad" _newvm.find_fuzzy("Finish", "button").click() - alert = self.app.root.find("vmm dialog", "alert") - alert.find_fuzzy("Unable to complete install") - alert.find_fuzzy("Close", "button").click() + self._click_alert_button("Unable to complete install", "Close") return _newvm newvm = dofail() diff --git a/tests/uitests/test_snapshot.py b/tests/uitests/test_snapshot.py index 9594a1e5..a9dd994a 100644 --- a/tests/uitests/test_snapshot.py +++ b/tests/uitests/test_snapshot.py @@ -48,20 +48,18 @@ class Snapshots(uiutils.UITestCase): snapname = "offline-root" win.find(snapname, "table cell").click() snaprun.click() - alert = self.app.root.find_fuzzy("vmm dialog", "alert") - alert.find_fuzzy( - "sure you want to run the snapshot '%s'" % snapname, "label") - alert.find("Yes", "push button").click() + self._click_alert_button( + "sure you want to run the snapshot '%s'" % snapname, + "Yes") uiutils.check_in_loop(lambda: vmrun.sensitive) # Start paused snapshot snapname = "snap-paused" win.find(snapname, "table cell").click() snaprun.click() - alert = self.app.root.find_fuzzy("vmm dialog", "alert") - alert.find_fuzzy( - "sure you want to run the snapshot '%s'" % snapname, "label") - alert.find("Yes", "push button").click() + self._click_alert_button( + "sure you want to run the snapshot '%s'" % snapname, + "Yes") uiutils.check_in_loop(lambda: vmpause.checked) # Edit snapshot @@ -84,9 +82,7 @@ class Snapshots(uiutils.UITestCase): # Delete it win.find("snapshot-delete", "push button").click() - alert = self.app.root.find_fuzzy("vmm dialog", "alert") - alert.find_fuzzy("permanently delete", "label") - alert.find("Yes", "push button").click() + self._click_alert_button("permanently delete", "Yes") uiutils.check_in_loop(lambda: newc.dead) # Switch out of window diff --git a/tests/uitests/utils.py b/tests/uitests/utils.py index 551d5538..fd43382a 100644 --- a/tests/uitests/utils.py +++ b/tests/uitests/utils.py @@ -97,6 +97,12 @@ class UITestCase(unittest.TestCase): check_in_loop(lambda: run.sensitive) return win + def _click_alert_button(self, label_text, button_text): + alert = self.app.root.find("vmm dialog", "alert") + alert.find_fuzzy(label_text, "label") + alert.find(button_text, "push button").click() + check_in_loop(lambda: not alert.active) + def _walkUIList(self, win, lst, error_cb, reverse=False): """ Toggle down through a UI list like addhardware, net/storage/iface @@ -148,23 +154,17 @@ class UITestCase(unittest.TestCase): # Trying to click away should warn that there's unapplied changes win.find("Details", "page tab").click() - alert = self.app.root.find("vmm dialog") - alert.find_fuzzy("changes will be lost") - # Select 'No', meaning don't abandon changes - alert.find("No", "push button").click() + self._click_alert_button("changes will be lost", "No") check_in_loop(lambda: xmleditor.showing) # Click the finish button, but our bogus change should trigger error finish.click() - alert = self.app.root.find("vmm dialog") - alert.find_fuzzy("(xmlParseDoc|tag.mismatch)") - alert.find("Close", "push button").click() + self._click_alert_button("(xmlParseDoc|tag.mismatch)", "Close") # Try unapplied changes again, this time abandon our changes win.find("Details", "page tab").click() - alert = self.app.root.find("vmm dialog") - alert.find("Yes", "push button").click() + self._click_alert_button("changes will be lost", "Yes") check_in_loop(lambda: not xmleditor.showing)