diff --git a/tests/uitests/newvm.py b/tests/uitests/newvm.py index 8355b6a12..735eeb52d 100644 --- a/tests/uitests/newvm.py +++ b/tests/uitests/newvm.py @@ -143,10 +143,7 @@ class NewVM(unittest.TestCase): version = uiutils.find_pattern(newvm, "install-os-version-label") time.sleep(1) - while True: - if "Detecting" not in version.text: - break - time.sleep(.5) + uiutils.check_in_loop(lambda: "Detecting" not in version.text) self.assertEquals(version.text, "Red Hat Enterprise Linux 5.5") uiutils.find_fuzzy(newvm, "Forward", "button").click() @@ -157,10 +154,7 @@ class NewVM(unittest.TestCase): progress = uiutils.find_fuzzy(self.app.root, "Creating Virtual Machine", "frame") - while True: - if not progress.showing: - break - time.sleep(.5) + uiutils.check_in_loop(lambda: not progress.showing) time.sleep(.5) uiutils.find_fuzzy(self.app.root, "rhel5.5 on", "frame") diff --git a/tests/uitests/utils.py b/tests/uitests/utils.py index 93eb4d425..7e43db516 100644 --- a/tests/uitests/utils.py +++ b/tests/uitests/utils.py @@ -139,3 +139,19 @@ def print_nodes(root): print "got exception: %s" % e root.findChildren(_walk, isLambda=True) + + +def check_in_loop(func, timeout=-1): + """ + Run the passed func in a loop every .5 seconds until timeout is hit or + the func returns True. + If timeout=-1, check indefinitely. + """ + total_time = 0.0 + while True: + time.sleep(.5) + total_time += .5 + if func() is True: + return + if timeout > 0 and total_time >= timeout: + raise RuntimeError("Loop condition wasn't met")