Clicking and comparing images from multiple websites

Class library usage, coding and language questions.
blackout
Posts: 14
Joined: Thu Mar 14, 2013 10:07 am

Clicking and comparing images from multiple websites

Post by blackout » Thu Mar 14, 2013 10:18 am

Hi guys,

I'm in the process of trying to figure how to make the automation find all the HTML image tags in a set section and clicking on the image; there's a built in loop so that it navigates back to the same page ready to click on the next image tag. Once on the new page, I'm then trying to compare an image within this section to that of another website to ensure they are the same.

Code so far:

Code: Select all

          Report.Info(repo.SmartTestWeb.parentSection.GetPath().ToString());
            
          IList<string> ImageList = repo.SmartTestWeb.Self.FindDescendants<Ranorex.ImgTag>().ToString();
            
            foreach(Ranorex.ImgTag currentImage in ImageList)
            {
            	if(currentImage.ToString().Contains("_sm") == true)
            	{
            	 	Report.Info(string.Format("Clicking on {0}", currentImage.ToString()));
            		currentImage.Click(Location.Center);
            		Thread.Sleep(3000);
            		
            		//Compare images
                        <code was here until I broke it somehow>
            	
            		//Navigate back to About Us
            		repo.SmartTestWeb.MenuBar.Banner1.MoveTo();
            		repo.SmartTestWeb.MenuBar.DropBanner1.Click();
            		Thread.Sleep(3000);	
That was working but now it won't let me implicitly make IList<string> ImageList a string using ToString.

Any thoughts on both how to resolve my above issue, as well the brick wall I've hit above the code, would be greatly appreciated.

cheers

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

Re: Clicking and comparing images from multiple websites

Post by Support Team » Fri Mar 15, 2013 2:49 pm

Hello,

You are trying to convert a list to a string which is not possible.
Please use the following code to store all tags in this list:
IList<Ranorex.ImgTag> ImageList = repo.SmartTestWeb.Self.FindDescendants<Ranorex.ImgTag>();
I don't understand your issue with comparing images from multiple pages.
Please provide more information about your issue.
You can save the image from the first page into a .bmp file to your local machine.
Bitmap yourImage = Imaging.CaptureImage(repo.YourElement);
myImage.Save(@"C:\Users\Path\YourImage.bmp");
To compare a image on the second page with the saved one you have to load the image.
Ranorex.Imaging.Load("YourImage.bmp")
After that you can use the Imaging.Compare() method in order to compare the images.

Regards,
Markus (T)
.
Image

blackout
Posts: 14
Joined: Thu Mar 14, 2013 10:07 am

Re: Clicking and comparing images from multiple websites

Post by blackout » Fri Mar 15, 2013 4:23 pm

Thanks Markus, you're 100% correct. That initial code for the image list worked perfect and just hearing it from another person, I'm not sure what I was thinking...

Regarding the image comparison, the reason I'm having difficulty in how I'm approaching it, is because I don't know which image will be on the screen.

Yes, a simple image to image comparison stored from computer would work as you describe above.

However, the reason for finding all the initial images in the list, is so that I go through a process of clicking each one (which has a link embedded) which takes me to another page. I then want to compare the image on that page, with the same image on a separate website.

At this stage, because of the loop, I don't know which page I'm on and therefore don't know which images I'm comparing at the stage in the automation.

I don't see the above solution working in that scenario.


cheers

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

Re: Clicking and comparing images from multiple websites

Post by Support Team » Mon Mar 18, 2013 5:17 pm

Hello,

You need to design your test in a way that you know which image you validate in your loop.
You could identify the image within the loop by a unique attribute (e.g. src or href) and use this in order to execute the image-related operations. For instance, with an image-related User Code method.

Regards,
Markus (T)
.
Image