Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests-Only]Enabled screenshot of desktop on test failure #9518

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "- [$i](${CACHE_ENDPOINT}/${CACHE_BUCKET}/$2/$3/guiReportUpload/screenshots/$i)" >> $1/comments.file
echo "- [$i](${CACHE_ENDPOINT}/${CACHE_BUCKET}/$2/$3/${GUI_TEST_REPORT_DIR}/screenshots/$i)" >> $1/comments.file

also $1 $2 $3 should be given nice names
both could happen in a different PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$GUI_TEST_REPORT_DIR is /drone/src/test/guiReportUpload. We either need to create new env variable to store the directory name guiReportUpload or we should leave it as it is, AFAIK.

And yes, we can give some nice name to all the variables, that can be done in some other PR.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that will create an screenshot AFTER the issue
so e.g. if the app crashes this will be the screen after the crash, meaning the app would not even be visible
Do we need (additionally?) the screenshot just before the problematic action? But that might be hard to achive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the app is not closed automatically after the crash then the screenshot is captured that shows the state of crash. For instance in #9518 (comment)

Otherwise, the only option that I can think of right now is to capture the video of test run (anyway) and then delete it if there is no test error. I can not say that can be done easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this could be a good enhancement. I will open an issue. May be we can try it later.

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
kiranparajuli589 marked this conversation as resolved.
Show resolved Hide resolved

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