Repository images save location~~

Ask general questions here.
vglfbyv2124
Posts: 1
Joined: Fri May 17, 2019 5:57 am

Repository images save location~~

Post by vglfbyv2124 » Fri May 17, 2019 5:58 am

Hi,

seems that I need to do a lot of image validation because Android app is done with old "XWalk" :(

.\RepositoryImages\ProjectX_Repository32c80887.rximgres

Is this the location and file where the validation screenshot's are saved?

Is it possible to open this file and see the saved images?

If this file get's deleted, I will be in big trouble, right???

McTurtle
Posts: 255
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Repository images save location~~

Post by McTurtle » Tue May 21, 2019 3:42 pm

Hey man,

You have the correct file. However, you can't read that file outside of Ranorex Studio. It is possible to save every file separately from Studio. But that can be difficult if you have many screenshots... I've player around a bit and I built this code below. It will find all RepoItemInfo objects in the repository and then find their GetScreenshot() methods. The names of that methods depend on the names of the screenshots. Therefore, you must use reflections in order to get all methods with a return type "CompressedImage" and make sure the 1st overload is always taken. The only thing I did not figure out is how to find out how "deep" the repository structure goes (int level). In the code below i limited it to 4 levels deep, but you can just define more if you need them. Entry point is method SaveAllScreenshots():
void reportAndSave(RepoItemInfo element)
		{
			var methods = element
				.GetType()
				.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
				.Where(item => item.ReturnType.ToString()=="Ranorex.CompressedImage")
				.Where(item => item.GetParameters().Length==0);

			List<CompressedImage> images=new List<CompressedImage>();
			
			foreach (var method in methods)
			{
				images.Add((CompressedImage)method.Invoke(element, new Object[0]));
			}
			
			int i=1;
			
			foreach (var image in images)
			{
				Report.LogData(ReportLevel.Info,"Saving screenshot: ",(Bitmap)image);
				image.Image.Save("Repo_images//"+element.FullName.ToString()+"-"+i+".png");
				i++;
			}
		}
		
		IList<RepoItemInfo> GetAllChildren(RepoItemInfo child)
		{
			List <RepoItemInfo> found_Children=new List<RepoItemInfo>();
			
			if(child.Children.Count>0)
			{
				found_Children.AddRange(child.Children);
			}
			return found_Children;
		}
		
		public void SaveAllScreenshots()
		{

			List <RepoItemInfo> all_RepoItemInfo=new List <RepoItemInfo>();
			all_RepoItemInfo.AddRange(MyTestRepository.Instance.SelfInfo.Children);
			List <RepoItemInfo> intermediate_List=new List<RepoItemInfo>();
			
			int level=4;
			
			for (int i=0;i<=level;i++)
			{
				foreach(RepoItemInfo child in all_RepoItemInfo)
				{
					intermediate_List.AddRange(GetAllChildren(child));
				}
				
				foreach (RepoItemInfo _child in intermediate_List)
				{
					if(!all_RepoItemInfo.Contains(_child))
						all_RepoItemInfo.Add(_child);
				}
			}
			foreach(RepoItemInfo element in all_RepoItemInfo)
				reportAndSave(element);
			
		}
You need additional namespaces:
using System.Reflection;
using System.Linq;
using System.IO;
With this code you can save all images into a folder and see them there :)

Well, take care the file does not get deleted. Else you will be loading the images one by one or recreating them :)

Regards,
McTurtle