1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

Add save to disk ScreenShot.

This commit is contained in:
Gunther Brunner 2014-09-25 18:33:20 +09:00
parent a4a11c1680
commit 2f1908b718
2 changed files with 34 additions and 0 deletions

View file

@ -15,6 +15,35 @@ module.exports = function deviceContextMenuDirective($window) {
$window.close()
}
function saveToDisk(fileURL, fileName) {
// for non-IE
if (!window.ActiveXObject) {
var save = document.createElement('a')
save.href = fileURL
save.target = '_blank'
save.download = fileName || 'unknown'
var event = document.createEvent('Event')
event.initEvent('click', true, true)
save.dispatchEvent(event)
(window.URL || window.webkitURL).revokeObjectURL(save.href)
}
// for IE
else if (!!window.ActiveXObject && document.execCommand) {
var _window = window.open(fileURL, '_blank')
_window.document.close()
_window.document.execCommand('SaveAs', true, fileName || fileURL)
_window.close()
}
}
scope.saveScreenShot = function () {
scope.control.screenshot().then(function (result) {
saveToDisk(result.body.href, result.body.name)
})
}
}
}
}