Forum Discussion
8 Replies
Hi Lukas,
Thanks for sharing your example!
I have something to add: practically each object (web or window) has TestComplete's Picture method. So, if you want to save only an object to a file (not the whole page or the window), you can use this method. In this case, the code will look like this:
function saveObjectToFile(obj, fileName)
{
var pic = obj.Picture();
pic.SaveToFile(fileName);
}
I guess the Picture method is similar to QTP's CaptureBitmap method.
- rmanningContributorFigured it out:
To save a screenshot:
Sys.Desktop.Picture.SaveToFile "C:\TEMP\Desktop.jpg"
To email saved screenshot:
If SendMail("ClareJ@clarejeffersoncorp.com", "mail.johnsmithcorp.com", "John Smith", "JohnS@johnsmithcorp.com", "Notification", "Hello Clare, Your application is nice.", "C:\TEMP\Desktop.jpg") Then
Log.Message "Mail was sent"
Else
Log.Warning "Mail was not sent"
End If
My only question now is how to take multiple/incremental screenshots instead of overwriting the same file every time.. So like a "Desktop1.jpg", "Desktop2.jpg", etc. Any suggestions? I'll keep digging... - rmanningContributorWow. I'm doing pretty well at answering my own questions. I figured it out, by setting a Variable in my KeywordTest and using the method described here: http://www.automatedqa.com/forums/forum/post/?mode=singlethread&thread=f4f9ec73-0f9a-4daa-b464-4979166ac90f
1. Creat a Vaiable under the "Variables" tab in the KeyWordTest that you are running the script routine from.
2. Give it any name and make it an integer with a default value of 0 (or whatever number you wish to start at)
3. Create a script routine and use the following:
Sub Main
Sys.Desktop.ActiveWindow().Picture.SaveToFile "C:\TEMP\Desktop" + VarToStr(KeywordTests.YourKeywordTest.Variables.Var1) + ".jpg"
End Sub
4. Add the "Set Variable Value" to your KeyWordTest Steps window (before or after the "Run Script Routine" of the script above) and use the following: Use a variable of the Integer type. To increment its value, on the "Set New Value" page of the "Set Variable Value" dialog choose the "Code Expression" mode and set Value to "Project.Variables.YourVariableName + 1" (without quotes).
That's it. - rmanningContributorI think I found my answer here: http://www.automatedqa.com/forums/forum/post/?mode=singlethread&thread=5b348aea-d11b-4a6c-922e-bcc7cc9dbbc0 but how does this work for VBScript?
- krupa_lukeOccasional ContributorHi 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 Hi Ryan,
It looks like you've found answers for all the questions. If some points are still unclear for you, please let us know.
- krupa_lukeOccasional ContributorThanks Tanya,
sorry... my solution is kind of blunt compared to yours :-)
Even thought I have 8years xp with QTP/UFT, I have started with testComplete 1-2 months ago so my xp got still big gaps :-)
L.
Hi Lukas,
I'd better say that your solution is a bit tricky :)
Good luck with learning TestComplete! I'm sure, you are in the right direction.