tests: add wait_for_window function to reduce code duplication
This commit is contained in:
parent
cf110c74e2
commit
44c340c046
@ -35,6 +35,7 @@ import sys
|
|||||||
|
|
||||||
import qubes.backup
|
import qubes.backup
|
||||||
import qubes.qubes
|
import qubes.qubes
|
||||||
|
import time
|
||||||
|
|
||||||
VMPREFIX = 'test-'
|
VMPREFIX = 'test-'
|
||||||
|
|
||||||
@ -339,6 +340,28 @@ class SystemTestsMixin(object):
|
|||||||
for vmname in vmnames:
|
for vmname in vmnames:
|
||||||
self._remove_vm_disk(vmname)
|
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):
|
class BackupTestsMixin(SystemTestsMixin):
|
||||||
|
@ -907,15 +907,7 @@ class TC_30_Gui_daemon(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
testvm1.run('zenity --text-info --editable --title={}'.format(
|
testvm1.run('zenity --text-info --editable --title={}'.format(
|
||||||
window_title))
|
window_title))
|
||||||
|
|
||||||
wait_count = 0
|
self.wait_for_window(window_title)
|
||||||
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)
|
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
test_string = "test{}".format(testvm1.xid)
|
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)
|
window_title = 'user@{}'.format(testvm2.name)
|
||||||
testvm2.run('zenity --entry --title={} > test.txt'.format(
|
testvm2.run('zenity --entry --title={} > test.txt'.format(
|
||||||
window_title))
|
window_title))
|
||||||
wait_count = 0
|
self.wait_for_window(window_title)
|
||||||
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)
|
|
||||||
|
|
||||||
subprocess.check_call(['xdotool', 'key', '--delay', '100',
|
subprocess.check_call(['xdotool', 'key', '--delay', '100',
|
||||||
'ctrl+shift+v', 'ctrl+v', 'Return'])
|
'ctrl+shift+v', 'ctrl+v', 'Return'])
|
||||||
|
Loading…
Reference in New Issue
Block a user