areguera / rpms / cockpit

Forked from rpms/cockpit 4 years ago
Clone

Blame SOURCES/0001-test-Fix-selenium-test.patch

06bfda
From 0a1baf5a3c9eda9a827cbb69a3bb096983baf359 Mon Sep 17 00:00:00 2001
06bfda
From: Jan Scotka <jscotka@redhat.com>
06bfda
Date: Thu, 3 Mar 2016 16:40:19 +0100
06bfda
Subject: [PATCH] test: Fix selenium test
06bfda
06bfda
We shouldn't assume that we're the only ones working in /tmp during
06bfda
the tests, so take a bit more care with the filenames we choose.
06bfda
06bfda
Also:
06bfda
 - Handle exceptions in avocado tests while fetching results
06bfda
 - Limit length of selenium debug output
06bfda
06bfda
Reviewed-by: Dominik Perpeet <dperpeet@redhat.com>
06bfda
---
06bfda
 test/avocado/run-tests         | 13 +++++++++++--
06bfda
 test/avocado/selenium-login.py | 31 +++++++++++++++++--------------
06bfda
 test/avocado/seleniumlib.py    |  3 ++-
06bfda
 3 files changed, 30 insertions(+), 17 deletions(-)
06bfda
06bfda
diff --git a/test/avocado/run-tests b/test/avocado/run-tests
06bfda
index cc72fb1..e35b7e5 100755
06bfda
--- a/test/avocado/run-tests
06bfda
+++ b/test/avocado/run-tests
06bfda
@@ -55,7 +55,12 @@ def prepare_avocado_tests(machine):
06bfda
     machine.upload([os.path.join(machine.test_dir, "avocado")], machine_test_dir)
06bfda
 
06bfda
 def tap_output(machine):
06bfda
-    json_info = json.loads(machine.execute(command="cat " + os.path.join(avocado_results_dir, "latest/results.json"), quiet=True))
06bfda
+    try:
06bfda
+        json_info = json.loads(machine.execute(command="cat " + os.path.join(avocado_results_dir, "latest/results.json"), quiet=True))
06bfda
+    except Exception as e:
06bfda
+        print "ERROR: Unable to fetch JSON from remote machine:", os.path.join(avocado_results_dir, "latest/results.json")
06bfda
+        print e
06bfda
+        return None
06bfda
     print "\nTAP output -------------------------"
06bfda
     print "1..%s" % len(json_info['tests'])
06bfda
     counter = 1
06bfda
@@ -67,7 +72,11 @@ def tap_output(machine):
06bfda
         print "# ----------------------------------------------------------------------"
06bfda
         print "# %s (time %d secs)" % (test_name, test_time)
06bfda
         print "#"
06bfda
-        print machine.execute(command="cat " + test_log, quiet=True)
06bfda
+        try:
06bfda
+            print machine.execute(command="cat " + test_log, quiet=True)
06bfda
+        except Exception as e:
06bfda
+            print "ERROR: Unable to fetch testlog from remote machine:", test_log
06bfda
+            print e
06bfda
         print "# TEST LOG END -------"
06bfda
         if test_status == 'PASS':
06bfda
             print "ok %s %s (time %d secs)" % (counter, test_name, test_time)
06bfda
diff --git a/test/avocado/selenium-login.py b/test/avocado/selenium-login.py
06bfda
index 29c4404..1e9e081 100755
06bfda
--- a/test/avocado/selenium-login.py
06bfda
+++ b/test/avocado/selenium-login.py
06bfda
@@ -174,20 +174,23 @@ class BasicTestSuite(SeleniumTest):
06bfda
         self.wait_frame("terminal")
06bfda
         self.wait_id('terminal')
06bfda
         terminal = self.wait_xpath("//*[@class='terminal']")
06bfda
-        self.send_keys(terminal, "touch /tmp/testabc\n", clear=False)
06bfda
-        self.wait_text("touch /tmp/testabc", user, element="div")
06bfda
-        self.send_keys(terminal, "touch /tmp/testabd\n", clear=False)
06bfda
-        self.wait_text("touch /tmp/testabd",user, element="div")
06bfda
-        self.send_keys(terminal, "ls /tmp/test*\n", clear=False)
06bfda
-        self.wait_text("ls /tmp/test*",'/tmp/testabc /tmp/testabd', element="div")
06bfda
-        process.run("ls /tmp/testabc", shell=True)
06bfda
-        process.run("ls /tmp/testabd", shell=True)
06bfda
-        self.send_keys(terminal, "rm /tmp/testabc /tmp/testabd\n", clear=False)
06bfda
-        self.wait_text("rm /tmp/testabc /tmp/testabd",user, element="div")
06bfda
-        self.send_keys(terminal, "ls /tmp/test*\n", clear=False)
06bfda
-        self.wait_text("ls /tmp/test*",'cannot access', element="div")
06bfda
-        process.run("ls /tmp/testabc |wc -l |grep 0", shell=True)
06bfda
-        process.run("ls /tmp/testabd |wc -l |grep 0", shell=True)
06bfda
+        prefix = "/tmp/cockpitrndadr/"
06bfda
+        self.send_keys(terminal, "mkdir {0}\n".format(prefix), clear=False)
06bfda
+        self.wait_text("mkdir {0}".format(prefix), user, element="div")
06bfda
+        self.send_keys(terminal, "touch {0}abc\n".format(prefix), clear=False)
06bfda
+        self.wait_text("touch {0}abc".format(prefix), user, element="div")
06bfda
+        self.send_keys(terminal, "touch {0}abd\n".format(prefix), clear=False)
06bfda
+        self.wait_text("touch {0}abd".format(prefix), user, element="div")
06bfda
+        self.send_keys(terminal, "ls {0}*\n".format(prefix), clear=False)
06bfda
+        self.wait_text("ls {0}*".format(prefix), '{0}abc'.format(prefix), element="div")
06bfda
+        process.run("ls {0}abc".format(prefix), shell=True)
06bfda
+        process.run("ls {0}abd".format(prefix), shell=True)
06bfda
+        self.send_keys(terminal, "rm {0}abc {0}abd\n".format(prefix), clear=False)
06bfda
+        self.wait_text("rm {0}abc {0}abd".format(prefix), user, element="div")
06bfda
+        self.send_keys(terminal, "ls {0}*\n".format(prefix), clear=False)
06bfda
+        self.wait_text("ls {0}*".format(prefix), 'cannot access', element="div")
06bfda
+        process.run("ls {0}abc |wc -l |grep 0".format(prefix), shell=True)
06bfda
+        process.run("ls {0}abd |wc -l |grep 0".format(prefix), shell=True)
06bfda
         self.mainframe()
06bfda
         self.error=False
06bfda
 
06bfda
diff --git a/test/avocado/seleniumlib.py b/test/avocado/seleniumlib.py
06bfda
index 8d99cd3..e8e05f9 100755
06bfda
--- a/test/avocado/seleniumlib.py
06bfda
+++ b/test/avocado/seleniumlib.py
06bfda
@@ -111,8 +111,9 @@ class SeleniumTest(Test):
06bfda
                 self.log.info('ERR: Unable to close WEBdriver: {0}'.format(e))
06bfda
 
06bfda
     def get_debug_logs(self, logs=['browser','driver','client','server']):
06bfda
+        max_line_log_count = 10
06bfda
         for log in logs:
06bfda
-            receivedlog = self.driver.get_log(log)
06bfda
+            receivedlog = [x for x in self.driver.get_log(log)][-max_line_log_count:]
06bfda
             if receivedlog:
06bfda
                 self.log.info(">>>>> " + log)
06bfda
                 for line in receivedlog:
06bfda
-- 
06bfda
1.8.3.1
06bfda