Screenshot() Name

Ask general questions here.
jjorgens
Posts: 14
Joined: Wed Apr 01, 2009 7:32 pm

Screenshot() Name

Post by jjorgens » Tue May 06, 2014 9:20 pm

Is there a way to give the screenshot a custom name rather than it taking the log name and renaming it to log_file_1.jpg log_file_2.jpg

I know that screenshot has several overloads but I don't see any of them allowing a custom name for the screenshot.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Screenshot() Name

Post by Support Team » Mon May 12, 2014 1:16 pm

Hi jjorgens,

Unfortunately it is not possible to set the screenshot name directly.
The screenshots are automatically named as the reports.

In order to set a new report name you could for instance use this little workaround in a user code module:

Code: Select all

private void ReportScreenshot()
{
string oldreportname = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportName;
string newreportname = "SCREENSHOTNAME";
Ranorex.Core.Reporting.TestReport.ReportFilename = newreportname;
Report.Screenshot(REPOELEMENT);
Ranorex.Core.Reporting.TestReport.ReportFilename = oldreportname;
}
The new name for your screenshots will be "SCREENSHOTNAME_X_rxlog.jpg" whereby X is an automatically consecutive number.

Regards,
Markus (S)
.
Image

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Screenshot() Name

Post by Support Team » Tue Jul 29, 2014 12:57 pm

Hi jjorgens,

I have another idea regarding your issue. You can also use the Imaging class instead of the Report class in order to make a screenshot of an element.
For example:
Bitmap bmp = Imaging.CaptureImage(repo.YourElement.Self);
bmp.Save(@"C:\PathToAFolder\CustomName.jpg");
The code snippet above will capture a screenshot from your element and will save it in the given location.
I hope this workaround meets your needs.

Regards,
Markus (S)
.
Image

skhanpara
Posts: 94
Joined: Wed Apr 23, 2014 3:55 pm

Re: Screenshot() Name

Post by skhanpara » Wed Jul 30, 2014 6:32 pm

What i do is call this function in catch block to get the error screen

Code: Select all

 private static void screenshot(){
        	//Screenshot Start
			            try{
        		
			            var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                               Screen.PrimaryScreen.Bounds.Height,
                               PixelFormat.Format32bppArgb);
						
						// Create a graphics object from the bitmap.
						var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
						
						// Take the screenshot from the upper left corner to the right bottom corner.
						gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
						                            Screen.PrimaryScreen.Bounds.Y,
						                            0,
						                            0,
						                            Screen.PrimaryScreen.Bounds.Size,
						                            CopyPixelOperation.SourceCopy);
						
						// Save the screenshot to the specified path that the user has chosen.
						bmpScreenshot.Save("Screenshot123.png", ImageFormat.Png);
						
			            }catch(Exception e){
			            	Report.Log(ReportLevel.Error, "Screenshot", e.Message);
			            }
        }