Skip to content

Commit

Permalink
[Tests-Only]Enabled screenshot of desktop on test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Talank committed Mar 23, 2022
1 parent 56bb3db commit e3bf913
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
}]

Expand Down
10 changes: 9 additions & 1 deletion test/gui/drone/comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
18 changes: 18 additions & 0 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e3bf913

Please sign in to comment.