Forum Discussion
krupa_luke
13 years agoOccasional Contributor
Hi Ryan and everyone!
Problem in TC is that I have not found any clear and simple explanation about how to make a universal screenshot ... something similar to QTP/UFT's obj.CaptureBitmap. Mentioned function is great, because it is universal. It does care whether it is web or non-web application and allows you to simply stores picture (in bmp or png format) anywhere you want on you hardisk
In testComplete, 99% information forwards you to work with TC's log. But I do not want that! I simply wanted to take a screenshot of whatever I want and stores it where I want.
But in TC, there seems not to be one single function for it. Of course, you can use Sys.Desktop.ActiveWindow.Picture().SaveToFile() but it does not work for web apps. Sys.Desktop.Picture().SaveToFile() stores on the other hand whole desktop, while still your application can be behind different object. PagePicture() works greatly for web apps while again is not usable for non-web apps.
Here is a function I created today, which handles both - web/non-web apps and stores it to place you want. I am not saying you cannot find better solution, however this works so far well for me.
For non-web apps, it uses Desktop.Picture() - it takes only picture of application due to extracted pozition and size, so... nothing from the rest of desktop is taken into screenshot. For web apps, it simply uses obj.PagePicture() method...
I am aware of fact that I could have used Desktop.Picture() even for web apps, but I think it is faster and more elegant to use obj.PagePicture().
function snapShot (obj, filePath) {
// page or non-page object
if (aqObject.GetPropertyValue(obj, "ObjectType")=="Page") {
var ssPicture = obj.PagePicture();
}
else {
var appLeft = aqObject.GetPropertyValue(obj, "ScreenLeft");
var appTop = aqObject.GetPropertyValue(obj, "ScreenTop");
var appWidth = aqObject.GetPropertyValue(obj, "Width");
var appHeight = aqObject.GetPropertyValue(obj, "Height");
// activate application before taking a snapshot
obj.Activate();
var ssPicture = Sys.Desktop.Picture(appLeft, appTop, appWidth, appHeight );
}
// store picture to the file
ssPicture.SaveToFile(filePath);
}
Let me know if you find better solution and you want to share :-).
Thanks
Problem in TC is that I have not found any clear and simple explanation about how to make a universal screenshot ... something similar to QTP/UFT's obj.CaptureBitmap. Mentioned function is great, because it is universal. It does care whether it is web or non-web application and allows you to simply stores picture (in bmp or png format) anywhere you want on you hardisk
In testComplete, 99% information forwards you to work with TC's log. But I do not want that! I simply wanted to take a screenshot of whatever I want and stores it where I want.
But in TC, there seems not to be one single function for it. Of course, you can use Sys.Desktop.ActiveWindow.Picture().SaveToFile() but it does not work for web apps. Sys.Desktop.Picture().SaveToFile() stores on the other hand whole desktop, while still your application can be behind different object. PagePicture() works greatly for web apps while again is not usable for non-web apps.
Here is a function I created today, which handles both - web/non-web apps and stores it to place you want. I am not saying you cannot find better solution, however this works so far well for me.
For non-web apps, it uses Desktop.Picture() - it takes only picture of application due to extracted pozition and size, so... nothing from the rest of desktop is taken into screenshot. For web apps, it simply uses obj.PagePicture() method...
I am aware of fact that I could have used Desktop.Picture() even for web apps, but I think it is faster and more elegant to use obj.PagePicture().
function snapShot (obj, filePath) {
// page or non-page object
if (aqObject.GetPropertyValue(obj, "ObjectType")=="Page") {
var ssPicture = obj.PagePicture();
}
else {
var appLeft = aqObject.GetPropertyValue(obj, "ScreenLeft");
var appTop = aqObject.GetPropertyValue(obj, "ScreenTop");
var appWidth = aqObject.GetPropertyValue(obj, "Width");
var appHeight = aqObject.GetPropertyValue(obj, "Height");
// activate application before taking a snapshot
obj.Activate();
var ssPicture = Sys.Desktop.Picture(appLeft, appTop, appWidth, appHeight );
}
// store picture to the file
ssPicture.SaveToFile(filePath);
}
Let me know if you find better solution and you want to share :-).
Thanks