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.
Screenshot() Name
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Screenshot() Name
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:
The new name for your screenshots will be "SCREENSHOTNAME_X_rxlog.jpg" whereby X is an automatically consecutive number.
Regards,
Markus (S)
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;
}
Regards,
Markus (S)
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Screenshot() Name
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:
I hope this workaround meets your needs.
Regards,
Markus (S)
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)
Re: Screenshot() Name
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);
}
}