Blob Blame History Raw
From 0a1baf5a3c9eda9a827cbb69a3bb096983baf359 Mon Sep 17 00:00:00 2001
From: Jan Scotka <jscotka@redhat.com>
Date: Thu, 3 Mar 2016 16:40:19 +0100
Subject: [PATCH] test: Fix selenium test

We shouldn't assume that we're the only ones working in /tmp during
the tests, so take a bit more care with the filenames we choose.

Also:
 - Handle exceptions in avocado tests while fetching results
 - Limit length of selenium debug output

Reviewed-by: Dominik Perpeet <dperpeet@redhat.com>
---
 test/avocado/run-tests         | 13 +++++++++++--
 test/avocado/selenium-login.py | 31 +++++++++++++++++--------------
 test/avocado/seleniumlib.py    |  3 ++-
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/test/avocado/run-tests b/test/avocado/run-tests
index cc72fb1..e35b7e5 100755
--- a/test/avocado/run-tests
+++ b/test/avocado/run-tests
@@ -55,7 +55,12 @@ def prepare_avocado_tests(machine):
     machine.upload([os.path.join(machine.test_dir, "avocado")], machine_test_dir)
 
 def tap_output(machine):
-    json_info = json.loads(machine.execute(command="cat " + os.path.join(avocado_results_dir, "latest/results.json"), quiet=True))
+    try:
+        json_info = json.loads(machine.execute(command="cat " + os.path.join(avocado_results_dir, "latest/results.json"), quiet=True))
+    except Exception as e:
+        print "ERROR: Unable to fetch JSON from remote machine:", os.path.join(avocado_results_dir, "latest/results.json")
+        print e
+        return None
     print "\nTAP output -------------------------"
     print "1..%s" % len(json_info['tests'])
     counter = 1
@@ -67,7 +72,11 @@ def tap_output(machine):
         print "# ----------------------------------------------------------------------"
         print "# %s (time %d secs)" % (test_name, test_time)
         print "#"
-        print machine.execute(command="cat " + test_log, quiet=True)
+        try:
+            print machine.execute(command="cat " + test_log, quiet=True)
+        except Exception as e:
+            print "ERROR: Unable to fetch testlog from remote machine:", test_log
+            print e
         print "# TEST LOG END -------"
         if test_status == 'PASS':
             print "ok %s %s (time %d secs)" % (counter, test_name, test_time)
diff --git a/test/avocado/selenium-login.py b/test/avocado/selenium-login.py
index 29c4404..1e9e081 100755
--- a/test/avocado/selenium-login.py
+++ b/test/avocado/selenium-login.py
@@ -174,20 +174,23 @@ class BasicTestSuite(SeleniumTest):
         self.wait_frame("terminal")
         self.wait_id('terminal')
         terminal = self.wait_xpath("//*[@class='terminal']")
-        self.send_keys(terminal, "touch /tmp/testabc\n", clear=False)
-        self.wait_text("touch /tmp/testabc", user, element="div")
-        self.send_keys(terminal, "touch /tmp/testabd\n", clear=False)
-        self.wait_text("touch /tmp/testabd",user, element="div")
-        self.send_keys(terminal, "ls /tmp/test*\n", clear=False)
-        self.wait_text("ls /tmp/test*",'/tmp/testabc /tmp/testabd', element="div")
-        process.run("ls /tmp/testabc", shell=True)
-        process.run("ls /tmp/testabd", shell=True)
-        self.send_keys(terminal, "rm /tmp/testabc /tmp/testabd\n", clear=False)
-        self.wait_text("rm /tmp/testabc /tmp/testabd",user, element="div")
-        self.send_keys(terminal, "ls /tmp/test*\n", clear=False)
-        self.wait_text("ls /tmp/test*",'cannot access', element="div")
-        process.run("ls /tmp/testabc |wc -l |grep 0", shell=True)
-        process.run("ls /tmp/testabd |wc -l |grep 0", shell=True)
+        prefix = "/tmp/cockpitrndadr/"
+        self.send_keys(terminal, "mkdir {0}\n".format(prefix), clear=False)
+        self.wait_text("mkdir {0}".format(prefix), user, element="div")
+        self.send_keys(terminal, "touch {0}abc\n".format(prefix), clear=False)
+        self.wait_text("touch {0}abc".format(prefix), user, element="div")
+        self.send_keys(terminal, "touch {0}abd\n".format(prefix), clear=False)
+        self.wait_text("touch {0}abd".format(prefix), user, element="div")
+        self.send_keys(terminal, "ls {0}*\n".format(prefix), clear=False)
+        self.wait_text("ls {0}*".format(prefix), '{0}abc'.format(prefix), element="div")
+        process.run("ls {0}abc".format(prefix), shell=True)
+        process.run("ls {0}abd".format(prefix), shell=True)
+        self.send_keys(terminal, "rm {0}abc {0}abd\n".format(prefix), clear=False)
+        self.wait_text("rm {0}abc {0}abd".format(prefix), user, element="div")
+        self.send_keys(terminal, "ls {0}*\n".format(prefix), clear=False)
+        self.wait_text("ls {0}*".format(prefix), 'cannot access', element="div")
+        process.run("ls {0}abc |wc -l |grep 0".format(prefix), shell=True)
+        process.run("ls {0}abd |wc -l |grep 0".format(prefix), shell=True)
         self.mainframe()
         self.error=False
 
diff --git a/test/avocado/seleniumlib.py b/test/avocado/seleniumlib.py
index 8d99cd3..e8e05f9 100755
--- a/test/avocado/seleniumlib.py
+++ b/test/avocado/seleniumlib.py
@@ -111,8 +111,9 @@ class SeleniumTest(Test):
                 self.log.info('ERR: Unable to close WEBdriver: {0}'.format(e))
 
     def get_debug_logs(self, logs=['browser','driver','client','server']):
+        max_line_log_count = 10
         for log in logs:
-            receivedlog = self.driver.get_log(log)
+            receivedlog = [x for x in self.driver.get_log(log)][-max_line_log_count:]
             if receivedlog:
                 self.log.info(">>>>> " + log)
                 for line in receivedlog:
-- 
1.8.3.1