[gnome-boxes/wip/automated-tests: 8/19] Add VNC tests



commit 1b785c639657e6610db62f7bf4ead0b7b32c4bea
Author: Vladimir Benes <vbenes redhat com>
Date:   Tue Jan 6 10:16:07 2015 -0500

    Add VNC tests
    
    These tests have prerequisites for available vncserver binary. Otherwise
     skipped with exit(77).
    
    Coverage:
     * new local vnc box
     * restart persistence
    
    Let's do some test description here. It may be of value for other tests
    too..
    
    test case:
    
      Background:
        * Make sure that gnome-boxes is running
        * Wait until overview is loaded
    
      @new_vnc_localhost_box
      Scenario: New vnc box
        * Create new box from url "vnc://localhost:5901;"
        * Wait for "sleep 2" end
        * Press "Create"
        Then Box "localhost" "does" exist
        * Go into "localhost" box
        * Wait for "sleep 1" end
        * Hit "<Super_L>"
        * Wait for "sleep 1" end
        * Type "gnome-terminal"
        * Wait for "sleep 1" end
        * Type "echo 'walderon' > /tmp/vnc_text.txt"
        Then "walderon" is visible with command "cat /tmp/vnc_text.txt"
        Then Press "back" in vm
    
    so. the first thing which is called in test itself by behave is
    execution of environment.py. Behave defines several possible actions
    that differ according to execution time. The order (and names) of these
    actions is as follows:
    
    0. before all <-executed prior every single test
    1. before scenario  <- executed prior name specified scenario
    2. before tag <- executed prior tag (tag == go_into_local_livecd_box)
    3. after scenario
    4. after tag
    5 after all
    
    This environment is executed for every single test.
    Before all action for first time setup (downloading images, disabling
    screen saver, etc), then touching /tmp/boxes_counfigured and not
    repeating this again. App class is defined here via
    context.app_class = App('gnome-boxes')
    (App class comes from common_steps)
    
    Before scenario is not used in my tests at all.
    Before tag is used in this test (via vnc tag) for starting localhost
    vncserver.
    After step is not used except test.status is fail for log bundling.
    After tag is used for vncserver stopping
    After scenario is used deleting all possible boxes by selecting
    one-by-one and clicking delete .. and x next to undo. then boxes are
    terminated. Some more logging is done here and some sanity deletes too.
    Not sure if these deletes are still needed but they're there just to be
    sure env is clean.
    
    Note that even if tests are defined via features (like a bunch of tests)
     in Makefile.am they're executed one by one by beaker. So all this does
    not change even if features are used instead of tests.
    
    Behave then moves to vnc.feature file (via tag again): Feature files
    contain Scenarios (accompanied by tags for execution and setup/teardown
    -- scenario may have more tags) and scenarios contain steps that are
    defined in steps/steps.py which are very likely absorbing parameters to
    be as widely reusable as possible.
    
    Background:
    describes steps that are executed for every single test
    in this case
        * Make sure that gnome-boxes is running
         ^^ this goes back to common_steps and starts application itself
        * Wait until overview is loaded
         ^^ this waits until overview is loaded. In fact it waits for New
            button being visible. This step contains sub-step
    
      @new_vnc_localhost_box
         ^^ this defines tag for execution and via if 'vnc' in tag: in
            environment for start/stop of vnc server
    
      Scenario: New vnc box
         ^^ just human readable scenario name..not used anywhere
    
        * Create new box from url "vnc://localhost:5901;"
         ^^ here comes a bit of dogtail. Behave searches in steps.py for
            according step.  In this case:
    
    @step(u'Create new box from url "{url}"')
    def create_new_vm_via_url(context, url):
        context.app.child('New').click()
        context.app.child('Continue').click()
        context.app.child('Enter URL').click()
    
        typeText(url)
        context.app.child('Continue').click()
    <snip>
    
    so it clicks New, then Continue and then Enter URL, then url (before
    mentioned step parameter) is typed in and Continue is clicked. Some more
     logic for http downloading is there but that's not important now.
    
        * Wait for "sleep 2" end
         ^^ waiting for two seconds
        * Press "Create"
          ^^ pressing create. Create is done separately as you may want to
             change some VM prefs before. Not applied here.
             After create, Boxes goes back to overview.
    
        Then Box "localhost" "does" exist
         ^^ Check that localhost box is present in overview
    
        * Go into "localhost" box
          ^^ localhost box is clicked
    
        * Wait for "sleep 1" end
         ^^ wait for 1 second to vnc screen to appear (sufficient while
            it's local, should be more if remote)
    
        * Hit "<Super_L>"
         ^^ call step that contains pressKey dogtail method with Super_L
            param. Thus overview is opened in vnc box as it should be
            focused after Go into "vm_name" step
    
        * Wait for "sleep 1" end
         ^^ Wait one more second for overview to appear
    
        * Type "gnome-terminal"
         ^^ enter gnome-terminal into overview search bar and hit enter
    
        * Wait for "sleep 10" end
         ^^ wait 10 more seconds (it has to be quite a lot as low memory
            machines are sllooooww)
    
        * Type "echo 'walderon' > /tmp/vnc_text.txt"
         ^^ now while focused into terminal write above mentioned echo into
            a file in /tmp
    
        Then "walderon" is visible with command "cat /tmp/vnc_text.txt"
         ^^ as the box is local, the file will be in /tmp dir with walderon
            inside.
    
        Then Press "back" in vm
         ^^ this just goes back to overview.
    
    then after tag and after scenario are executed, vncserver stopped and
    boxes deleted.
    
    https://bugzilla.gnome.org/review?bug=736288

 Makefile.am          |    1 +
 tests/README         |    6 ++++++
 tests/environment.py |   12 ++++++++++++
 tests/steps/utils.py |   12 ++++++------
 tests/vnc.feature    |   29 +++++++++++++++++++++++++++++
 5 files changed, 54 insertions(+), 6 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index d17a0f9..59d2470 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -82,6 +82,7 @@ INSTALLED_TESTS=                              \
        snapshots.feature                       \
        spice.feature                           \
        system-broker.feature                   \
+       vnc.feature                             \
        $(NULL)
 INSTALLED_TESTS_TYPE=session-exclusive
 -include $(top_srcdir)/git.mk
diff --git a/tests/README b/tests/README
index 1f6f586..6a7cf05 100644
--- a/tests/README
+++ b/tests/README
@@ -40,6 +40,9 @@ Structure
     * pause/resume SB box
     * force shutdown in SB
     * restart persistence
+  * vnc.feature
+    * connect to vnc box
+    * restart persistence
 * Environment file
   * everything for setting/cleaning up the environment
 * Steps
@@ -53,6 +56,9 @@ Requirements
   * behave (python-behave in Fedora)
   * dogtail
 
+* for vnc tests execution
+  * tigervnc-server (or similar)
+
 * for system-broker test execution
   * virt-install
   * passwordless access to virtualization to wheel group
diff --git a/tests/environment.py b/tests/environment.py
index 368fe25..1a417dd 100644
--- a/tests/environment.py
+++ b/tests/environment.py
@@ -68,6 +68,13 @@ def before_scenario(context, scenario):
     pass
 
 def before_tag(context, tag):
+    if 'vnc' in tag:
+        if not os.path.isfile('/usr/bin/vncserver'):
+            sys.exit(77)
+
+        os.system('vncserver -SecurityTypes None > /dev/null 2>&1')
+        sleep(1)
+
     if 'system_broker' in tag:
         if call('pkcheck -a org.libvirt.unix.manage --process $BASHPID', shell=True) != 0 \
             or not os.path.isfile('/usr/bin/virt-install') \
@@ -93,6 +100,11 @@ def after_step(context, step):
         print "Error in after_step: %s" % str(e)
 
 def after_tag(context, tag):
+    if 'vnc' in tag:
+        os.system('vncserver -kill :1 > /dev/null 2>&1')
+        os.system('rm -rf /tmp/vnc_text.txt')
+        sleep(1)
+
     if 'help' in tag:
         os.system('pkill -9 yelp')
 
diff --git a/tests/steps/utils.py b/tests/steps/utils.py
index 0514203..3327386 100644
--- a/tests/steps/utils.py
+++ b/tests/steps/utils.py
@@ -6,21 +6,21 @@ from time import sleep
 from subprocess import call, check_output, CalledProcessError, STDOUT
 
 def get_showing_node_name(name, parent, timeout=30, step=0.25):
-    sleep = 0
+    wait = 0
     while len(parent.findChildren(lambda x: x.name == name and x.showing and x.sensitive)) == 0:
         sleep(step)
-        sleep += step
-        if sleep == timeout:
+        wait += step
+        if wait == timeout:
             raise Exception("Timeout: Node %s wasn't found showing" %name)
 
     return parent.findChildren(lambda x: x.name == name and x.showing and x.sensitive)[0]
 
 def get_showing_node_rolename(rolename, parent, timeout=30, step=0.25):
-    sleep = 0
+    wait = 0
     while len(parent.findChildren(lambda x: x.roleName == rolename and x.showing and x.sensitive)) == 0:
         sleep(step)
-        sleep += 1
-        if sleep == timeout:
+        wait += 1
+        if wait == timeout:
             raise Exception("Timeout: Node %s wasn't found showing" %rolename)
 
     return parent.findChildren(lambda x: x.roleName == rolename and x.showing and x.sensitive)[0]
diff --git a/tests/vnc.feature b/tests/vnc.feature
new file mode 100644
index 0000000..0e2b6d7
--- /dev/null
+++ b/tests/vnc.feature
@@ -0,0 +1,29 @@
+Feature: Vnc
+
+  Background:
+    * Make sure that gnome-boxes is running
+    * Wait until overview is loaded
+
+  @new_vnc_localhost_box
+  Scenario: New VNC box
+    * Create new box from url "vnc://localhost:5901;"
+    * Press "Create"
+    * Wait for "sleep 2" end
+    Then Box "localhost" "does" exist
+    * Go into "localhost" box
+    * Wait for "sleep 10" end
+    * Hit "<Super_L>"
+    * Wait for "sleep 5" end
+    * Type "gnome-terminal"
+    * Wait for "sleep 10" end
+    * Type "echo 'walderon' > /tmp/vnc_text.txt"
+    Then "walderon" is visible with command "cat /tmp/vnc_text.txt"
+    Then Press "back" in vm
+
+  @vnc_restart_persistence
+  Scenario: VNC restart persistence
+    * Create new box from url "vnc://localhost:5901;"
+    * Press "Create"
+    * Quit Boxes
+    * Start Boxes
+    Then Box "localhost" "does" exist


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