summaryrefslogtreecommitdiff
path: root/uitest
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2021-12-27 16:50:20 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-12-30 11:03:38 +0100
commitd7fb6b22cf7e66eb2594001cc42c6bff8b5a49e2 (patch)
tree8e21662bc094489df5e8d953edd33a39abf0a13d /uitest
parent035422a44acb5fc19042199013eb01af3790632e (diff)
tdf#95217, tdf#142600: sc: Add UItest
for that, launch an http server in a separate thread Change-Id: I9d78c9a4349620a9de31b3963f2a31ff1d354f86 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127592 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'uitest')
-rw-r--r--uitest/uitest/test.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index 3beee0d274f2..c798e76533dd 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -6,11 +6,14 @@
#
import time
+import functools
import threading
from contextlib import contextmanager
from uitest.config import DEFAULT_SLEEP
from uitest.config import MAX_WAIT
from uitest.uihelper.common import get_state_as_dict
+from http.server import HTTPServer, SimpleHTTPRequestHandler
+import os
from com.sun.star.uno import RuntimeException
@@ -268,4 +271,27 @@ class UITest(object):
time.sleep(DEFAULT_SLEEP)
raise Exception("Did not execute a dialog for a blocking action")
+ @contextmanager
+ def launch_HTTP_server(self, file_name):
+ # Spawns an http.server.HTTPServer in a separate thread
+
+ tdoc = os.getenv("TDOC")
+
+ if not os.path.exists(os.path.join(tdoc, file_name)):
+ raise Exception("File doesn't exists: " + file_name)
+
+ # Serve in TDOC directory
+ handler = functools.partial(SimpleHTTPRequestHandler, directory=tdoc)
+
+ with HTTPServer(("localhost", 0), handler) as httpd:
+ try:
+ thread = threading.Thread(target=httpd.serve_forever)
+ thread.start()
+ url = "http://%s:%d/%s" % (httpd.server_name, httpd.server_port, file_name)
+ yield url
+ finally:
+ # Call shutdown in case the testcase fails
+ httpd.shutdown()
+ thread.join()
+
# vim: set shiftwidth=4 softtabstop=4 expandtab: