tests: add wait_for_window function to reduce code duplication

This commit is contained in:
Marek Marczykowski-Górecki 2015-11-03 02:43:46 +01:00
parent cf110c74e2
commit 44c340c046
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 25 additions and 17 deletions

View File

@ -35,6 +35,7 @@ import sys
import qubes.backup
import qubes.qubes
import time
VMPREFIX = 'test-'
@ -339,6 +340,28 @@ class SystemTestsMixin(object):
for vmname in vmnames:
self._remove_vm_disk(vmname)
def wait_for_window(self, title, timeout=30, show=True):
"""
Wait for a window with a given title. Depending on show parameter,
it will wait for either window to show or to disappear.
:param title: title of the window to wait for
:param timeout: timeout of the operation, in seconds
:param show: if True - wait for the window to be visible,
otherwise - to not be visible
:return: None
"""
wait_count = 0
while subprocess.call(['xdotool', 'search', '--name', title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) == 0:
wait_count += 1
if wait_count > timeout*10:
self.fail("Timeout while waiting for {} window to {}".format(
title, "show" if show else "hide")
)
time.sleep(0.1)
class BackupTestsMixin(SystemTestsMixin):

View File

@ -907,15 +907,7 @@ class TC_30_Gui_daemon(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
testvm1.run('zenity --text-info --editable --title={}'.format(
window_title))
wait_count = 0
while subprocess.call(['xdotool', 'search', '--name', window_title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) > 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for text-info window")
time.sleep(0.1)
self.wait_for_window(window_title)
time.sleep(0.5)
test_string = "test{}".format(testvm1.xid)
@ -946,14 +938,7 @@ class TC_30_Gui_daemon(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
window_title = 'user@{}'.format(testvm2.name)
testvm2.run('zenity --entry --title={} > test.txt'.format(
window_title))
wait_count = 0
while subprocess.call(['xdotool', 'search', '--name', window_title],
stdout=open(os.path.devnull, 'w'),
stderr=subprocess.STDOUT) > 0:
wait_count += 1
if wait_count > 100:
self.fail("Timeout while waiting for input window")
time.sleep(0.1)
self.wait_for_window(window_title)
subprocess.check_call(['xdotool', 'key', '--delay', '100',
'ctrl+shift+v', 'ctrl+v', 'Return'])