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