summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRashi Aswani <aswanirashi19@gmail.com>2015-08-21 00:43:02 +0530
committerRashi Aswani <aswanirashi19@gmail.com>2015-08-27 15:16:43 +0530
commit4fba527f9538edc0778a3e89a55863622de5919c (patch)
treef1293e6ae8912b996ee9a80fce2c9d11cf0b9f9a
parentfe92b2417b91b32543791527f0c4a4028ea84553 (diff)
downloadgnome-logs-4fba527f9538edc0778a3e89a55863622de5919c.tar.gz
Add behave and dogtail tests for help and quit
-rw-r--r--Makefile.am1
-rw-r--r--tests/common_steps.py30
-rw-r--r--tests/general.feature20
-rw-r--r--tests/shortcuts.feature13
-rw-r--r--tests/steps/general.py41
-rw-r--r--tests/steps/util.py15
6 files changed, 120 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index b048902..58c059b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -267,6 +267,7 @@ endif
@BEHAVE_INSTALLED_TESTS_RULE@
INSTALLED_TESTS= \
general.feature \
+ shortcuts.feature \
$(NULL)
INSTALLED_TESTS_TYPE=session-exclusive
diff --git a/tests/common_steps.py b/tests/common_steps.py
index 9bd283d..f05662b 100644
--- a/tests/common_steps.py
+++ b/tests/common_steps.py
@@ -22,6 +22,36 @@ class dummy(TestCase):
def runTest(self): # pylint: disable=R0201
assert True
+def wait_until(my_lambda, element, timeout=30, period=0.25):
+ """
+ This function keeps running lambda with specified params until the result is True
+ or timeout is reached
+ Sample usages:
+ * wait_until(lambda x: x.name != 'Loading...', context.app)
+ Pause until window title is not 'Loading...'.
+ Return False if window title is still 'Loading...'
+ Throw an exception if window doesn't exist after default timeout
+
+ * wait_until(lambda element, expected: x.text == expected, element, ('Expected text'))
+ Wait until element text becomes the expected (passed to the lambda)
+
+ """
+ exception_thrown = None
+ mustend = int(time()) + timeout
+ while int(time()) < mustend:
+ try:
+ if my_lambda(element):
+ return True
+ except Exception as e:
+ # If lambda has thrown the exception we'll re-raise it later
+ # and forget about if lambda passes
+ exception_thrown = e
+ sleep(period)
+ if exception_thrown:
+ raise exception_thrown
+ else:
+ return False
+
class TimeoutError(Exception):
"""
Timeout exception class for limit_execution_time_to function
diff --git a/tests/general.feature b/tests/general.feature
index 0f9a6b8..38ca03f 100644
--- a/tests/general.feature
+++ b/tests/general.feature
@@ -17,3 +17,23 @@ Feature: General
* Assert the message in details view
* Press the back button
Then return to the main window
+
+ @open_help_via_menu
+ Scenario: Open help from menu
+ * Make sure gnome-logs-behave-test is running
+ * Select "Help" from supermenu
+ Then Help is shown
+
+ @quit_via_panel
+ Scenario: Quit Logs via super menu
+ * Make sure gnome-logs-behave-test is running
+ * Select "Quit" from supermenu
+ Then Logs are not running
+
+ @open_about_via_menu
+ Scenario: Open about from menu
+ * Make sure gnome-logs-behave-test is running
+ * Select "About" from supermenu
+ * Press "Credits"
+ * Press "About"
+ Then About is shown
diff --git a/tests/shortcuts.feature b/tests/shortcuts.feature
new file mode 100644
index 0000000..7125dd7
--- /dev/null
+++ b/tests/shortcuts.feature
@@ -0,0 +1,13 @@
+Feature: Shortcuts
+
+ @quit_via_shortcut
+ Scenario: Quit Logs via shortcut
+ * Make sure gnome-logs-behave-test is running
+ * Hit "<Control>Q"
+ Then Logs are not running
+
+ @open_help_via_shortcut
+ Scenario: Open help via shortcut
+ * Make sure gnome-logs-behave-test is running
+ * Hit "<F1>"
+ Then Help is shown
diff --git a/tests/steps/general.py b/tests/steps/general.py
index 62f38f2..58b88f3 100644
--- a/tests/steps/general.py
+++ b/tests/steps/general.py
@@ -4,6 +4,22 @@ from os import system
from pyatspi import STATE_SENSITIVE
from time import sleep
from common_steps import App
+from dogtail.tree import root
+from dogtail.rawinput import typeText, pressKey, keyCombo
+
+def get_showing_node_name(name, parent, timeout=30, step=0.25):
+ wait = 0
+ while len(parent.findChildren(lambda x: x.name == name and x.showing and x.sensitive)) == 0:
+ sleep(step)
+ 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]
+
+@step('About is shown')
+def about_shown(context):
+ assert context.app.child('About Logs') != None, "About window cannot be focused"
@step(u'Open gnome-logs-behave-test')
def run_gnome_logs_test(context):
@@ -55,7 +71,32 @@ def return_main_window(context):
def help_shown(context):
sleep(1)
yelp = root.application('yelp')
+ assert yelp.child('Logs') != None, "Yelp wasn't opened"
+ system("killall yelp")
@step('Assert the message in details view')
def assert_message_details_view(context):
assert context.app.child('This is a test').sensitive
+
+@step('Select "{action}" from supermenu')
+def select_menu_action(context, action):
+ keyCombo("<Super_L><F10>")
+ if action == 'Help':
+ pressKey('Down')
+ if action == 'About':
+ pressKey('Down')
+ pressKey('Down')
+ if action == 'Quit':
+ pressKey('Down')
+ pressKey('Down')
+ pressKey('Down')
+ pressKey('Enter')
+
+@step('Logs are not running')
+def logs_not_running(context):
+ assert context.app_class.isRunning() != True, "Logs window still visible"
+
+@step('Press "{button}"')
+def press_button(context, button):
+ get_showing_node_name(button, context.app).click()
+ sleep(0.5)
diff --git a/tests/steps/util.py b/tests/steps/util.py
new file mode 100644
index 0000000..7adc18f
--- /dev/null
+++ b/tests/steps/util.py
@@ -0,0 +1,15 @@
+# -*- coding: UTF-8 -*-
+
+from __future__ import unicode_literals
+from behave import step
+from dogtail.rawinput import typeText, pressKey, keyCombo
+from time import sleep
+from subprocess import call, check_output, CalledProcessError, STDOUT
+
+@step('Hit "{keycombo}"')
+def hit_keycombo(context, keycombo):
+ sleep(0.2)
+ if keycombo == "Enter":
+ pressKey("Enter")
+ else:
+ keyCombo('%s'%keycombo)