From 7e78b80d27bbc7546e7d50bfed98329bd09a8512 Mon Sep 17 00:00:00 2001 From: Talank Date: Tue, 15 Mar 2022 13:45:14 +0545 Subject: [PATCH] [Tests-Only]Enabled screenshot of desktop on test failure --- .drone.star | 4 ++-- test/gui/drone/comment.sh | 10 +++++++++- test/gui/shared/scripts/bdd_hooks.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.drone.star b/.drone.star index ae546341b71..88919b6273b 100644 --- a/.drone.star +++ b/.drone.star @@ -545,8 +545,8 @@ def setGuiTestReportDir(): "image": "owncloud/ubuntu:16.04", "pull": "always", "commands": [ - "mkdir %s" % GUI_TEST_REPORT_DIR, - "chmod ugo+rwx %s" % GUI_TEST_REPORT_DIR, + "mkdir %s/screenshots -p" % GUI_TEST_REPORT_DIR, + "chmod 777 %s -R" % GUI_TEST_REPORT_DIR, ], }] diff --git a/test/gui/drone/comment.sh b/test/gui/drone/comment.sh index e0e463c6690..730a843242d 100644 --- a/test/gui/drone/comment.sh +++ b/test/gui/drone/comment.sh @@ -13,7 +13,7 @@ else echo "creating comment for GUI log" # if there is index.html generated by squishrunner then create a comment indicating link of GUI result if [[ -f $1/index.html ]]; then - echo ":boom: The GUI tests failed." + echo ":boom: The GUI tests failed." >> $1/comments.file echo "GUI Logs: (${CACHE_ENDPOINT}/${CACHE_BUCKET}/$2/$3/guiReportUpload/index.html)" >> $1/comments.file fi @@ -22,4 +22,12 @@ else echo "creating comment for server log" echo "Server Logs: (${CACHE_ENDPOINT}/${CACHE_BUCKET}/$2/$3/guiReportUpload/serverlog.log)" >> $1/comments.file fi + + if ! [[ $(find $1/screenshots -maxdepth 0 -empty) ]]; then + echo "creating comment for screenshots" + echo "Screenshots:" >> $1/comments.file + for i in $(ls $1/screenshots); do + echo "- [$i](${CACHE_ENDPOINT}/${CACHE_BUCKET}/$2/$3/guiReportUpload/screenshots/$i)" >> $1/comments.file + done + fi fi \ No newline at end of file diff --git a/test/gui/shared/scripts/bdd_hooks.py b/test/gui/shared/scripts/bdd_hooks.py index 53492bd2f68..f36132868a4 100644 --- a/test/gui/shared/scripts/bdd_hooks.py +++ b/test/gui/shared/scripts/bdd_hooks.py @@ -93,6 +93,24 @@ def hook(context): @OnScenarioEnd def hook(context): + # capture screenshot if there is error in the scenario execution, and if the test is being run in CI + if test.resultCount("errors") > 0 and os.getenv('CI'): + import gi + + gi.require_version('Gtk', '3.0') + from gi.repository import Gdk + + window = Gdk.get_default_root_window() + pb = Gdk.pixbuf_get_from_window(window, *window.get_geometry()) + + filename = context._data["title"].replace(" ", "_") + ".png" + directory = os.environ["GUI_TEST_REPORT_DIR"] + "/screenshots" + + if not os.path.exists(directory): + os.makedirs(directory) + + pb.savev(os.path.join(directory, filename), "png", [], []) + # Detach (i.e. potentially terminate) all AUTs at the end of a scenario for ctx in applicationContextList(): ctx.detach()