mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
uitests: Drop sleeps from newvm tests
Adds a few new uiutils options to facilitate watching for the expected result, rather than depending on hardcoded sleeps
This commit is contained in:
parent
4fbffc4086
commit
0c615497b1
@ -13,8 +13,9 @@ class CloneVM(uiutils.UITestCase):
|
||||
|
||||
def _open_window(self, vmname):
|
||||
# Launch wizard via right click menu
|
||||
uiutils.find_fuzzy(
|
||||
self.app.root, vmname, "table cell").click(button=3)
|
||||
c = uiutils.find_fuzzy(self.app.root, vmname, "table cell",
|
||||
wait_for_focus=True)
|
||||
c.click(button=3)
|
||||
uiutils.find_pattern(self.app.root, "Clone...", "menu item").click()
|
||||
return uiutils.find_pattern(
|
||||
self.app.root, "Clone Virtual Machine", "frame")
|
||||
|
@ -16,8 +16,9 @@ class Details(uiutils.UITestCase):
|
||||
###################
|
||||
|
||||
def _open_details_window(self, vmname="test-many-devices"):
|
||||
uiutils.find_fuzzy(
|
||||
self.app.root, vmname, "table cell").doubleClick()
|
||||
c = uiutils.find_fuzzy(self.app.root, vmname, "table cell",
|
||||
wait_for_focus=True)
|
||||
c.doubleClick()
|
||||
win = uiutils.find_pattern(self.app.root, "%s on" % vmname, "frame")
|
||||
uiutils.find_pattern(win, "Details", "radio button").click()
|
||||
return win
|
||||
@ -111,8 +112,11 @@ class Details(uiutils.UITestCase):
|
||||
"""
|
||||
origname = "test-many-devices"
|
||||
# Shutdown the VM
|
||||
uiutils.find_fuzzy(self.app.root, origname, "table cell").click()
|
||||
uiutils.find_pattern(self.app.root, "Shut Down", "push button").click()
|
||||
uiutils.find_fuzzy(self.app.root, origname, "table cell",
|
||||
wait_for_focus=True).click()
|
||||
b = uiutils.find_pattern(self.app.root, "Shut Down", "push button",
|
||||
wait_for_focus=True)
|
||||
b.click()
|
||||
uiutils.check_in_loop(lambda: b.sensitive is False)
|
||||
|
||||
time.sleep(.5)
|
||||
self._testRename(origname, "test-new-name")
|
||||
|
@ -16,7 +16,9 @@ class NewVM(uiutils.UITestCase):
|
||||
###################
|
||||
|
||||
def _open_create_wizard(self):
|
||||
uiutils.find_pattern(self.app.root, "New", "push button").click()
|
||||
b = uiutils.find_pattern(self.app.root, "New", "push button",
|
||||
wait_for_focus=True)
|
||||
b.click()
|
||||
return uiutils.find_pattern(self.app.root, "New VM", "frame")
|
||||
|
||||
def _do_simple_import(self, newvm):
|
||||
@ -28,7 +30,6 @@ class NewVM(uiutils.UITestCase):
|
||||
uiutils.find_fuzzy(newvm, "Forward", "button").click()
|
||||
uiutils.find_fuzzy(newvm, "Forward", "button").click()
|
||||
uiutils.find_fuzzy(newvm, "Finish", "button").click()
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
##############
|
||||
@ -59,10 +60,9 @@ class NewVM(uiutils.UITestCase):
|
||||
uiutils.find_fuzzy(delete, "Delete", "button").click()
|
||||
alert = uiutils.find_pattern(self.app.root, "Warning", "alert")
|
||||
uiutils.find_fuzzy(alert, "Yes", "push button").click()
|
||||
time.sleep(1)
|
||||
|
||||
# Verify delete dialog and VM dialog are now gone
|
||||
self.assertFalse(vmwindow.showing)
|
||||
uiutils.check_in_loop(lambda: vmwindow.showing is False)
|
||||
|
||||
|
||||
def testNewVMCDROM(self):
|
||||
@ -82,12 +82,10 @@ class NewVM(uiutils.UITestCase):
|
||||
uiutils.find_fuzzy(browser, "default-pool", "table cell").click()
|
||||
uiutils.find_fuzzy(browser, "iso-vol", "table cell").click()
|
||||
uiutils.find_fuzzy(browser, "Choose Volume", "button").click()
|
||||
time.sleep(1)
|
||||
|
||||
self.assertFalse(browser.showing)
|
||||
self.assertEqual(
|
||||
uiutils.find_fuzzy(newvm, "os-version-label", "label").text,
|
||||
"Unknown")
|
||||
label = uiutils.find_fuzzy(newvm, "os-version-label", "label")
|
||||
uiutils.check_in_loop(lambda: browser.showing is False)
|
||||
uiutils.check_in_loop(lambda: label.text == "Unknown")
|
||||
|
||||
# Change distro to win8
|
||||
uiutils.find_fuzzy(newvm, "Automatically detect", "check").click()
|
||||
@ -123,12 +121,11 @@ class NewVM(uiutils.UITestCase):
|
||||
|
||||
# Start the install, close via the VM window
|
||||
uiutils.find_fuzzy(vmwindow, "Begin Installation", "button").click()
|
||||
time.sleep(1)
|
||||
uiutils.check_in_loop(lambda: newvm.showing is False)
|
||||
vmwindow = uiutils.find_fuzzy(self.app.root, "win8 on", "frame")
|
||||
self.assertFalse(newvm.showing)
|
||||
uiutils.find_fuzzy(vmwindow, "File", "menu").click()
|
||||
uiutils.find_fuzzy(vmwindow, "Quit", "menu item").click()
|
||||
time.sleep(.5)
|
||||
uiutils.check_in_loop(lambda: self.app.is_running())
|
||||
|
||||
|
||||
def testNewVMURL(self):
|
||||
@ -146,20 +143,19 @@ class NewVM(uiutils.UITestCase):
|
||||
"http://vault.centos.org/5.5/os/x86_64/")
|
||||
|
||||
version = uiutils.find_pattern(newvm, "install-os-version-label")
|
||||
time.sleep(1)
|
||||
uiutils.check_in_loop(lambda: "Detecting" not in version.text)
|
||||
self.assertEqual(version.text, "Red Hat Enterprise Linux 5.5")
|
||||
uiutils.check_in_loop(lambda: "Detecting" in version.text)
|
||||
uiutils.check_in_loop(
|
||||
lambda: version.text == "Red Hat Enterprise Linux 5.5",
|
||||
timeout=10)
|
||||
|
||||
uiutils.find_fuzzy(newvm, "Forward", "button").click()
|
||||
uiutils.find_fuzzy(newvm, "Forward", "button").click()
|
||||
uiutils.find_fuzzy(newvm, "Forward", "button").click()
|
||||
uiutils.find_fuzzy(newvm, "Finish", "button").click()
|
||||
time.sleep(.5)
|
||||
|
||||
progress = uiutils.find_fuzzy(self.app.root,
|
||||
"Creating Virtual Machine", "frame")
|
||||
uiutils.check_in_loop(lambda: not progress.showing)
|
||||
time.sleep(.5)
|
||||
uiutils.check_in_loop(lambda: not progress.showing, timeout=120)
|
||||
|
||||
uiutils.find_fuzzy(self.app.root, "rhel5.5 on", "frame")
|
||||
self.assertFalse(newvm.showing)
|
||||
@ -179,7 +175,6 @@ class NewVM(uiutils.UITestCase):
|
||||
|
||||
self._do_simple_import(newvm)
|
||||
|
||||
time.sleep(1)
|
||||
uiutils.find_fuzzy(self.app.root, "generic-ppc64 on", "frame")
|
||||
self.assertFalse(newvm.showing)
|
||||
|
||||
|
@ -76,6 +76,9 @@ class DogtailApp(object):
|
||||
self.open()
|
||||
return self._root
|
||||
|
||||
def is_running(self):
|
||||
return bool(self._proc and self._proc.poll() is None)
|
||||
|
||||
def open(self, extra_opts=None):
|
||||
extra_opts = extra_opts or []
|
||||
|
||||
@ -125,7 +128,8 @@ class DogtailApp(object):
|
||||
# Widget search helpers #
|
||||
#########################
|
||||
|
||||
def find_pattern(root, name, roleName=None, labeller_text=None, retry=True):
|
||||
def find_pattern(root, name, roleName=None, labeller_text=None, retry=True,
|
||||
wait_for_focus=False):
|
||||
"""
|
||||
Search root for any widget that contains the passed name/role regex
|
||||
strings.
|
||||
@ -133,14 +137,20 @@ def find_pattern(root, name, roleName=None, labeller_text=None, retry=True):
|
||||
pred = _FuzzyPredicate(name, roleName, labeller_text)
|
||||
|
||||
try:
|
||||
return root.findChild(pred, retry=retry)
|
||||
ret = root.findChild(pred, retry=retry)
|
||||
except dogtail.tree.SearchError:
|
||||
raise dogtail.tree.SearchError("Didn't find widget with name='%s' "
|
||||
"roleName='%s' labeller_text='%s'" %
|
||||
(name, roleName, labeller_text))
|
||||
|
||||
if wait_for_focus:
|
||||
ret.grabFocus()
|
||||
check_in_loop(lambda: ret.focused)
|
||||
return ret
|
||||
|
||||
def find_fuzzy(root, name, roleName=None, labeller_text=None, retry=True):
|
||||
|
||||
def find_fuzzy(root, name, roleName=None, labeller_text=None, retry=True,
|
||||
wait_for_focus=False):
|
||||
"""
|
||||
Search root for any widget that contains the passed name/role strings.
|
||||
"""
|
||||
@ -155,23 +165,22 @@ def find_fuzzy(root, name, roleName=None, labeller_text=None, retry=True):
|
||||
labeller_pattern = ".*%s.*" % labeller_text
|
||||
|
||||
return find_pattern(root, name_pattern, role_pattern,
|
||||
labeller_pattern, retry=retry)
|
||||
labeller_pattern, retry=retry, wait_for_focus=wait_for_focus)
|
||||
|
||||
|
||||
def check_in_loop(func, timeout=-1):
|
||||
def check_in_loop(func, timeout=1):
|
||||
"""
|
||||
Run the passed func in a loop every .5 seconds until timeout is hit or
|
||||
Run the passed func in a loop every .1 seconds until timeout is hit or
|
||||
the func returns True.
|
||||
If timeout=-1, check indefinitely.
|
||||
"""
|
||||
total_time = 0.0
|
||||
start_time = time.time()
|
||||
interval = 0.1
|
||||
while True:
|
||||
time.sleep(.5)
|
||||
total_time += .5
|
||||
if func() is True:
|
||||
return
|
||||
if timeout > 0 and total_time >= timeout:
|
||||
if (time.time() - start_time) > timeout:
|
||||
raise RuntimeError("Loop condition wasn't met")
|
||||
time.sleep(interval)
|
||||
|
||||
|
||||
#####################
|
||||
|
Loading…
Reference in New Issue
Block a user