[gnome-boxes/wip/automated-tests: 6/21] Add automated snapshots tests



commit ffe150e04ddf034bbed9e7ea5d853cae1fdd4680
Author: Vladimir Benes <vbenes redhat com>
Date:   Tue Jan 6 09:42:20 2015 -0500

    Add automated snapshots tests
    
    Snapshots are tested via saving snapshot with working network then
    shutting the network down from inside the box and reverting back to the
    working state.
    
    Coverage:
     * Create and revert snapshots
     * Rename snapshot
     * Delete
    
    https://bugzilla.gnome.org/review?bug=736288

 Makefile.am             |    1 +
 tests/README            |    3 ++
 tests/snapshots.feature |   32 +++++++++++++++++
 tests/steps/general.py  |   12 ++++++
 tests/steps/snapshot.py |   86 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 134 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 04d1516..31f11cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -79,6 +79,7 @@ INSTALLED_TESTS=                              \
        import-vms.feature                      \
        livecd.feature                          \
        multi-windows.feature                   \
+       snapshots.feature                       \
        $(NULL)
 INSTALLED_TESTS_TYPE=session-exclusive
 -include $(top_srcdir)/git.mk
diff --git a/tests/README b/tests/README
index 41ad1e7..ef4cf4c 100644
--- a/tests/README
+++ b/tests/README
@@ -27,6 +27,9 @@ Structure
   * multi-windows.feature
     * open one/several new windows
     * poweroff in new window
+  * snapshots.feature
+    * create and revert snapshots
+    * delete snapshot
 * Environment file
   * everything for setting/cleaning up the environment
 * Steps
diff --git a/tests/snapshots.feature b/tests/snapshots.feature
new file mode 100644
index 0000000..f13188d
--- /dev/null
+++ b/tests/snapshots.feature
@@ -0,0 +1,32 @@
+Feature: Snapshots
+
+  Background:
+    * Make sure that gnome-boxes is running
+    * Wait until overview is loaded
+
+  @snapshots_create_an_revert
+  Scenario: Create snapshots and revert to them
+    * Create new box "Core-5"
+    * Create snapshot "working network" from machine "Core-5"
+    * Go into "Core-5" box
+    * Wait for "sleep 1" end
+    * Type "sudo ifconfig eth0 down"
+    * Press "back" in vm
+    * Wait for "sleep 5" end
+    * Create snapshot "network down" from machine "Core-5"
+    When "network down" is visible with command "virsh snapshot-current boxes-unknown |grep description"
+    When Cannot ping "Core-5"
+    * Revert machine "Core-5" to state "working network"
+    When "working network" is visible with command "virsh snapshot-current boxes-unknown |grep description"
+    When Ping "Core-5"
+    * Revert machine "Core-5" to state "network down"
+    Then Cannot ping "Core-5"
+
+  @delete_snapshots
+  Scenario: Delete snapshots
+    * Initiate new box "Core-5" installation
+    * Create snapshot "working network" from machine "Core-5"
+    * Create snapshot "network down" from machine "Core-5"
+    * Delete machines "Core-5" snapshot "working network"
+    * Delete machines "Core-5" snapshot "network down"
+    Then "error: domain 'boxes-unknown' has no current snapshot" is visible with command "virsh 
snapshot-current boxes-unknown"
diff --git a/tests/steps/general.py b/tests/steps/general.py
index 771d783..d7727a0 100644
--- a/tests/steps/general.py
+++ b/tests/steps/general.py
@@ -176,6 +176,18 @@ def start_boxes_via_vm(context, box):
     sleep(5)
     context.app = root.application('gnome-boxes')
 
+ step(u'Verify back button "{state}" visible for machine "{vm_name}"')
+def verify_back_button_visibility(context, state, vm_name):
+    if state == "is":
+        main = context.app.children[0]
+        core = context.app.findChildren(lambda x: x.name == vm_name)[-1]
+        frame = core.findAncestor(predicate.GenericPredicate(name='Boxes', roleName='frame'))
+        assert frame != main, "Cannot focus detached window"
+        top_frame_panel = frame.children[0]
+        main_window_panel = top_frame_panel.children[-1]
+        back_button = main_window_panel.child(roleName='push button')
+        assert back_button.showing == False, "Back button is visible but it shouldn't be"
+
 @step(u'Wait until overview is loaded')
 def initial_page_loaded(context):
     wait_until(lambda x: x.name != 'New', context.app)
diff --git a/tests/steps/snapshot.py b/tests/steps/snapshot.py
new file mode 100644
index 0000000..363130b
--- /dev/null
+++ b/tests/steps/snapshot.py
@@ -0,0 +1,86 @@
+# -*- coding: UTF-8 -*-
+
+from behave import step
+from dogtail.rawinput import typeText, pressKey
+from time import sleep
+from utils import get_showing_node_name
+
+ step(u'Add Snapshot named "{name}"')
+def add_snapshot(context, name):
+    wait = 0
+    while len(context.app.findChildren(lambda x: x.roleName == 'push button' and x.showing and not x.name)) 
== 0:
+        sleep(0.25)
+        wait += 1
+        if wait == 20:
+            raise Exception("Timeout: Node %s wasn't found showing" %name)
+
+    context.app.findChildren(lambda x: x.roleName == 'push button' and x.showing and not x.name)[0].click()
+
+    wait = 0
+    while len(context.app.findChildren(lambda x: x.roleName == 'toggle button' and x.showing \
+                                                                            and x.sensitive and x.name == 
'Menu')) == 0:
+        sleep(1)
+        wait += 1
+        if wait == 5:
+            raise Exception("Timeout: Node %s wasn't found showing" %name)
+
+    sleep(1)
+    context.app.findChildren(lambda x: x.roleName == 'toggle button' and x.showing \
+                                                                     and x.sensitive and x.name == 
'Menu')[-1].click()
+
+    renames = context.app.findChildren(lambda x: x.name == 'Rename' and x.showing)
+    if not renames:
+        context.app.findChildren(lambda x: x.roleName == 'toggle button' and x.showing and x.sensitive \
+                                                                                      and x.name == 
'Menu')[-1].click()
+        renames = context.app.findChildren(lambda x: x.name == 'Rename' and x.showing)
+    renames[0].click()
+    sleep(0.5)
+    typeText(name)
+    context.app.findChildren(lambda x: x.showing and x.name == 'Done')[0].click()
+
+ step(u'Create snapshot "{snap_name}" from machine "{vm_name}"')
+def create_snapshot(context, snap_name, vm_name):
+    context.execute_steps(u"""
+        * Select "%s" box
+        * Press "Properties"
+        * Press "Snapshots"
+        * Add Snapshot named "%s"
+        * Press "Back"
+        """ %(vm_name, snap_name))
+
+ step(u'Delete machines "{vm_name}" snapshot "{snap_name}"')
+def delete_snapshot(context, vm_name, snap_name):
+    context.execute_steps(u"""
+        * Select "%s" box
+        * Press "Properties"
+        * Press "Snapshots"
+        """ % vm_name)
+
+    name = context.app.findChildren(lambda x: x.name == snap_name and x.showing)[0]
+    name.parent.child('Menu').click()
+    delete = context.app.findChildren(lambda x: x.name == "Delete" and x.showing)[0]
+    delete.click()
+
+    context.app.findChildren(lambda x: x.name == 'Undo' and x.showing)[0].grabFocus()
+    pressKey('Tab')
+    pressKey('Enter')
+    sleep(2)
+
+    get_showing_node_name('Back', context.app).click()
+    sleep(0.5)
+
+ step(u'Revert machine "{vm_name}" to state "{snap_name}"')
+def revert_snapshot(context, vm_name, snap_name):
+    context.execute_steps(u"""
+        * Select "%s" box
+        * Press "Properties"
+        * Press "Snapshots"
+        """ % vm_name)
+
+    name = context.app.findChildren(lambda x: x.name == snap_name and x.showing)[0]
+    name.parent.child('Menu').click()
+    revert = context.app.findChildren(lambda x: x.name == "Revert to this state" and x.showing)[0]
+    revert.click()
+
+    get_showing_node_name('Back', context.app).click()
+    sleep(0.5)
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]