summaryrefslogtreecommitdiff
path: root/tests/uitests/details.py
blob: 0c8358a00e55a2ff8289f0e929ae936096a7511c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import dogtail.rawinput
import pyatspi

from tests.uitests import utils as uiutils


class Details(uiutils.UITestCase):
    """
    UI tests for virt-manager's VM details window
    """

    ###################
    # Private helpers #
    ###################

    def _open_details_window(self, vmname="test-many-devices"):
        uiutils.find_fuzzy(self.app.root, vmname, "table cell").click(button=3)
        uiutils.find_pattern(self.app.root, "Open", "menu item").click()

        win = uiutils.find_pattern(self.app.root, "%s on" % vmname, "frame")
        uiutils.find_pattern(win, "Details", "radio button").click()
        return win


    ##############
    # Test cases #
    ##############

    def testDetailsHardwareSmokeTest(self):
        """
        Open the VM with all the crazy hardware and just verify that each
        HW panel shows itself without raising any error.
        """
        win = self._open_details_window()

        # Ensure the Overview page is the first selected
        uiutils.find_pattern(win, "Hypervisor Details", "label")
        uiutils.find_pattern(win, "Overview", "table cell").click()

        # After we hit this number of down presses, start checking for
        # widget focus to determine if we hit the end of the list. We
        # don't check for widget focus unconditionally because it's slow.
        # The seemingly arbitrary number here is because it matches the
        # number of devices in test-many-devices at the time of this writing.
        check_after = 93

        focused = None
        old_focused = None
        count = 0
        while True:
            count += 1
            dogtail.rawinput.pressKey("Down")

            if not win.getState().contains(pyatspi.STATE_ACTIVE):
                # Should mean an error dialog popped up
                uiutils.find_pattern(self.app.root, "Error", "alert")
                raise AssertionError(
                    "One of the hardware pages raised an error")

            if count < check_after:
                #time.sleep(.05)
                continue

            # pylint: disable=not-an-iterable
            old_focused = focused
            focused = uiutils.focused_nodes(win)
            if old_focused is None:
                continue

            overlap = [w for w in old_focused if w in focused]
            if len(overlap) == len(old_focused):
                # Focus didn't change, meaning we hit the end of the HW list,
                # so our testing is done
                break

        return

    def _testRename(self, origname, newname):
        win = self._open_details_window(origname)

        # Ensure the Overview page is the first selected
        uiutils.find_pattern(win, "Hypervisor Details", "label")
        uiutils.find_pattern(win, "Overview", "table cell").click()

        oldcell = uiutils.find_fuzzy(self.app.root, origname, "table cell")
        uiutils.find_pattern(win, None, "text", "Name:").text = newname
        uiutils.find_pattern(win, "config-apply", "push button").click()

        # Confirm lists were updated
        uiutils.find_pattern(self.app.root, "%s on" % newname, "frame")
        uiutils.find_fuzzy(self.app.root, newname, "table cell")

        # Make sure the old entry is gone
        uiutils.check_in_loop(lambda: origname not in oldcell.name)

    def testDetailsRenameSimple(self):
        """
        Rename a simple VM
        """
        self._testRename("test-clone-simple", "test-new-name")

    def testDetailsRenameNVRAM(self):
        """
        Rename a VM that will trigger the nvram behavior
        """
        origname = "test-many-devices"
        # Shutdown the VM
        uiutils.find_fuzzy(self.app.root, origname, "table cell").click()
        b = uiutils.find_pattern(self.app.root, "Shut Down", "push button")
        b.click()
        # This insures the VM finished shutting down
        uiutils.check_in_loop(lambda: b.sensitive is False)

        self._testRename(origname, "test-new-name")