Report.Screenshot opening in new window/tab

Class library usage, coding and language questions.
User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Report.Screenshot opening in new window/tab

Post by artur_gadomski » Thu Aug 26, 2010 1:51 pm

Is it possible to make screenshots open in new windows using Report.Screenshot method?
Is it possible to get the html message Report.Screenshot is producing and edit it in my own code?
Is it possible to get the code for Report.Screenshot() so that I could alter it and use it in my code instead of Report.Screenshot?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Report.Screenshot opening in new window/tab

Post by Ciege » Fri Aug 27, 2010 12:24 am

artur_gadomski wrote:Is it possible to make screenshots open in new windows using Report.Screenshot method?
That would be nice. I had to teach myself and others to control click or middle click the thumbnails in the log so that they would open the image in another tab and not lose their place in the log.

I like this idea. +1 make this the way it works or to at least make it an option we can set.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Report.Screenshot opening in new window/tab

Post by artur_gadomski » Fri Aug 27, 2010 6:44 am

Since we're talking about screnshots:
It waould also be nice to specify if we want to keep them in a seperate folder. (If not possible now, if possible let me know how). I sometimes generate 100+ screenshots per test, all are named Logsomethingsomething, my logfile is named Log and it's sometimes hard to find it. I would like to have just logfile in my report directory and a folder with images/xls sheet.

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

Re: Report.Screenshot opening in new window/tab

Post by Support Team » Fri Aug 27, 2010 9:38 am

The subdirectory thing is already on our TODO list.
It might also be a good idea to add a "open in new window" link next to the thumbnail.

To answer your other questions: there is currently no easy way of customizing Report.Screenshot()
Here is the code that accomplishes it:

LogData() gets called by Report.Screenshot() with a Bitmap object as data
public static void Screenshot(Element target)
{
	Image screenShot = Imaging.CaptureImage(target, 0, false);
	LogData(ReportLevel.Info, "Screenshot", screenShot);
}
LogData then creates a thumbnail, saves both original and thumbnail to a (new) file and logs the necessary HTML.

To create your own version of this, you need to wrap an XmlLogger instance in a new class implementing
IReportLogger, passing everything through to the XmlLogger, except the LogData() call . Then instead of calling Report.Setup() with an xmlLog file name, use Report.AttachLogger() with a newly configured instance of your custom logger.
public void LogData(ReportLevel level, string category, object data)
{
	const int ThumbWidth = 300;
	const string thumbImgSuffix = "_rxlog_thumb.jpg";
	const string fullImgSuffix = "_rxlog.jpg";

	Bitmap img = data as Bitmap;
	if (img != null)
	{
		Image thumb = img.GetThumbnailImage(ThumbWidth, ThumbWidth * img.Height / img.Width, null, IntPtr.Zero);
		string dir = System.IO.Path.GetDirectoryName(workingFileName);
		
		string fileNoExt;
		string imgFileName;
		string imgThumbFileName;

		do
		{
			fileNoExt = System.IO.Path.GetFileName(logFileName) + "_" + imgCnt;
			imgFileName = System.IO.Path.Combine(dir, fileNoExt + fullImgSuffix);
			imgThumbFileName = System.IO.Path.Combine(dir, fileNoExt + thumbImgSuffix);
			imgCnt++;
		}
		while (appendExisting && File.Exists(imgFileName));

		string msg = String.Format("<a href=\"{1}\"><img src=\"{0}\" alt=\"Screenshot\"/></a>\r\n",
									fileNoExt + thumbImgSuffix, fileNoExt + fullImgSuffix);
		LogText(level, category, msg, false);

		img.Save(imgFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
		thumb.Save(imgThumbFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
	}
}
It should be quite easy to customize the file names, for example, or adding a "target" attribute to the "a" tag to open the image in a new window.

Reporting is currently receiving a major overhaul with 3.0, and we are still open to suggestions and small feature requests.

Michael
Ranorex Team
.
Image

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Report.Screenshot opening in new window/tab

Post by artur_gadomski » Fri Aug 27, 2010 9:46 am

Great Thx. With this I should be able to tune screenshots to my liking.