How to capture screenshot of test application - testcomplete

Is there any way to capture screenshot of test application and save that screenshot to particular location via script in testcomplete.

Call the .Picture method of your application's main window to capture its image, then call the image's .SaveToFile method.
// JScript
var img = Sys.Process("notepad").Window("Notepad").Picture();
img.SaveToFile("C:\\Work\\img.png");

Related

Coded UI - How to Capture Image After a Mouse Click Event

What is the best option of capturing image after each mouse click in recorded session of Coded UI?
For example, in UIMap.Designer.Cs file I have entered image capturing lines:
Mouse.Click(uIOutagesandSafetyHyperlink, new Point(62, 2));
Image MSOPic1 = UITestControl.Desktop.CaptureImage();
MSOPic1.Save(#"C:\Automation\TestAutomation\web\Recordings\FullSite1\Screenshots\MSO\HomePage_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".png");
The above code takes a screenshot but it does not take the current browser's screenshot, just captures another screen where the current browser window does not exist. How can I capture screenshot of the active browser where the test is taking place?
One more question: Does Visual Studio provide an alternative way to capture images during playback? Like through configuration?
One more question: Does Visual Studio provide an alternative way to capture images during playback? Like through configuration?
By default coded ui test should take a screenshot with each action it does.
You can find these screenshots in the html outputs for your tests.
See: https://msdn.microsoft.com/en-us/library/jj159363.aspx
If in any case it is not enabled for your tests you have to set:
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
If you want to have this setting in all tests and for all actions call it in the [TestInitialize()] method of each test you want to apply it to.
Like so:
[TestInitialize()]
public void MyTestInitialize()
{
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
}
The UITestControl class has a CaptureImage method. To get an image of the current browser, find its UITestControl object (which may be derived from that) and call its CaptureImage method.
Please do not edit the uimap.designer.cs file as it is an auto-generated file and your edits may be lost. See this answer.

InDesign Script to Maximize Window

In my Adobe InDesign I have a startup script where I want to automatically maximize the entire InDesign window.
This says I have an invalid object.
var window = app.documents[0].layoutWindows[0];
window.maximize();
How do I make this work?
This works for me:
var w = app.windows[0];
w.maximize();
Object 'Window' only parent is 'Document'. It means you can't control the main app window using script (in Windows).

How can I use AppleScriptObjC to get the current url of a web view in Xcode?

I have a webView in Xcode, and after a few seconds of browsing I want to be able to get the current URL of the web view. I've searched around but I can't find how. Any help would be appreciated!
If you set the WebView's frameLoadDelegate outlet to your AppleScript class in the nib file, you can implement the AppleScript-Objc equivalent of the WebFrameLoadDelegate's webView:didStartProvisionalLoadForFrame: method to be informed when the WebView starts loading a new page (which comes from WebKit Objective-C Programming Guide - Loading Pages - Displaying the Current URL):
on webView_didStartProvisionalLoadForFrame_(sender, frame)
log "webView_didStartProvisionalLoadForFrame_"
if frame is equal to sender's mainFrame then
set currentURLRequest to frame's provisionalDataSource()'s request
log currentURLRequest
set theURL to currentURLRequest's mainDocumentURL()
log theURL
set theURLString to theURL's absoluteString()
log theURLString
set textField's stringValue to theURLString
end if
end webView_didStartProvisionalLoadForFrame_
In this sample code, I set a text field's string value to the current URL, like a browser usually does when you navigate to another page. You could always store this value in an AppleScript property if need be.
Sample Project: WebViewFinaglerAS-Objc.zip

How to get a snapshot image of running window in Xorg?

I wanted to migrate Compiz's Window Picker function to XFCE environment , so i needed to grab an image of the window running in current display , and display it with an GtkWidget , but how ?
If you don't mind relying on an external tool, you can acquire the image by invoking ImageMagick's import -window 0xid bmp-. Read the output from a pipe and create the appropriate GTK object.
Of course, you will to replace the window ID you want to get the image from. Here is a post that will help you get the window ID from a a Process ID.

QTP How to save images from webpages

I would like to know if it's possible to simulate the process: Right click on an image -> Click on "Save image as.." on the popup menu -> save the image in local.
I tried CaptureBitmap() function, but the result is just a screenshot taken by QTP, not the same image file obtained as the procedure above.
Are there other ways? Many thanks in advance.
Allen
I suppose it depends what you want to do. If you want to compare the bitmap then the CaptureBitmap options should work. If you want to compare the path to the image you can use Image("x").GetROProperty("src").
If you really want to save the src image file then unfortunately QTP doesn't supply a way to interact with the browser's context menu. You can try to use some third-party mechanism to download the image from the src URL (e.g. wget).
Edit: I just had another thought, I'm not at work so I can't verify that it will work but I'm pretty sure it will.
First cause the context menu to appear, in order to do this you have to change the replay mode to device and run a RightClick operation.
replayType = Setting.WebPackage("ReplayType") ' Store old replay mode
Setting.WebPackage("ReplayType") = 2 ' change to device replay mode
Browser("b").Page("p").Image("I").RightClick
Setting.WebPackage("ReplayType") = replayType ' Revert to old mode
Then send the letter v to the browser which will select the Save menu item (on both IE and Firefox) by using the device replay object
Set deviceReplay = CreateObject( “Mercury.DeviceReplay” )
deviceReplay.SendString "v"
Now interact with the save dialog as a usual Win32 control.
Moral: Never underestimate what QTP will let you do if you try hard enough

Resources