summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozscreenshot
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mozbase/mozscreenshot
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozbase/mozscreenshot')
-rw-r--r--testing/mozbase/mozscreenshot/mozscreenshot/__init__.py61
-rw-r--r--testing/mozbase/mozscreenshot/setup.py26
2 files changed, 87 insertions, 0 deletions
diff --git a/testing/mozbase/mozscreenshot/mozscreenshot/__init__.py b/testing/mozbase/mozscreenshot/mozscreenshot/__init__.py
new file mode 100644
index 000000000..56c62cb23
--- /dev/null
+++ b/testing/mozbase/mozscreenshot/mozscreenshot/__init__.py
@@ -0,0 +1,61 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import mozinfo
+import tempfile
+import subprocess
+from mozlog.formatters.process import strstatus
+
+
+def printstatus(name, returncode):
+ """
+ print the status of a command exit code, formatted for tbpl.
+
+ Note that mozlog structured action "process_exit" should be used
+ instead of that in new code.
+ """
+ print "TEST-INFO | %s: %s" % (name, strstatus(returncode))
+
+
+def dump_screen(utilityPath, log):
+ """dumps a screenshot of the entire screen to a directory specified by
+ the MOZ_UPLOAD_DIR environment variable"""
+
+ is_structured_log = hasattr(log, 'process_exit')
+
+ # Need to figure out which OS-dependent tool to use
+ if mozinfo.isUnix:
+ utility = [os.path.join(utilityPath, "screentopng")]
+ utilityname = "screentopng"
+ elif mozinfo.isMac:
+ utility = ['/usr/sbin/screencapture', '-C', '-x', '-t', 'png']
+ utilityname = "screencapture"
+ elif mozinfo.isWin:
+ utility = [os.path.join(utilityPath, "screenshot.exe")]
+ utilityname = "screenshot"
+
+ # Get dir where to write the screenshot file
+ parent_dir = os.environ.get('MOZ_UPLOAD_DIR', None)
+ if not parent_dir:
+ log.info('Failed to retrieve MOZ_UPLOAD_DIR env var')
+ return
+
+ # Run the capture
+ try:
+ tmpfd, imgfilename = tempfile.mkstemp(
+ prefix='mozilla-test-fail-screenshot_',
+ suffix='.png', dir=parent_dir
+ )
+ os.close(tmpfd)
+ if is_structured_log:
+ log.process_start(utilityname)
+ returncode = subprocess.call(utility + [imgfilename])
+ if is_structured_log:
+ log.process_exit(utilityname, returncode)
+ else:
+ printstatus(utilityname, returncode)
+ except OSError, err:
+ log.info("Failed to start %s for screenshot: %s"
+ % (utility[0], err.strerror))
diff --git a/testing/mozbase/mozscreenshot/setup.py b/testing/mozbase/mozscreenshot/setup.py
new file mode 100644
index 000000000..fbc147462
--- /dev/null
+++ b/testing/mozbase/mozscreenshot/setup.py
@@ -0,0 +1,26 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from setuptools import setup
+
+
+PACKAGE_NAME = 'mozscreenshot'
+PACKAGE_VERSION = '0.1'
+
+
+setup(
+ name=PACKAGE_NAME,
+ version=PACKAGE_VERSION,
+ description="Library for taking screenshots in tests harness",
+ long_description="see http://mozbase.readthedocs.org/",
+ classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ keywords='mozilla',
+ author='Mozilla Automation and Tools team',
+ author_email='tools@lists.mozilla.org',
+ url='https://wiki.mozilla.org/Auto-tools/Projects/Mozbase',
+ license='MPL',
+ packages=['mozscreenshot'],
+ zip_safe=False,
+ install_requires=['mozlog', 'mozinfo'],
+)