ContributionsMost RecentMost LikesSolutionsRe: Small image detection in a larger image but with undefined position If the CAD application can print an area of the overall view, then you can simply print images before and after your changes of that location and compare them. If it can only print the full image, then you can use this method to search for a bitmap image in a larger, or same size, source image. It’s complied from several sources, which I can no longer remember…it’s been about 15 years. I used it as part of an automated testing software that I created, so I know it works well and is very fast. It is a static method, and the images need to be bitmaps. There are lots of libraries that can convert PDFs to images, if images are not an option from your CAD package. It will return the location, in pixels, of the smaller image within the larger image as a rectangle. If the image is not found it will return a rectangle with x, y, width and height with zero values. The returned rectangle can be used to highlight the location in the source image, if needed. Of course, it can be modified to just return a Boolean true/false. I hope this helps. This can be complied into a DLL file and used through the DotNet libraires of TestComplete. public void Test() { System.Drawing.Bitmap source = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(@"C:\Source.bmp"); System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(@"C:\Search2.bmp"); Rectangle r = source.InImage(bmp); } public static Rectangle InImage(this System.Drawing.Bitmap src, System.Drawing.Bitmap bmp) { Rectangle result = default; if (src== null || bmp == null || bmp.Width > src.Width || bmp.Height > src.Height) return result; src=(System.Drawing.Bitmap)src.Clone(); bmp = (System.Drawing.Bitmap)bmp.Clone(); Rectangle sr = new Rectangle(0, 0, src.Width, src.Height); Rectangle br = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData srcLock = src.LockBits(sr, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); BitmapData bmpLock = bmp.LockBits(br, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); int sStride = srcLock.Stride; int bStride = bmpLock.Stride; checked { int srcSz = sStride * src.Height; int bmpSz = bStride * bmp.Height; byte[] srcBuff = new byte[srcSz + 1]; byte[] bmpBuff = new byte[bmpSz + 1]; System.Runtime.InteropServices.Marshal.Copy(srcLock.Scan0, srcBuff, 0, srcSz); System.Runtime.InteropServices.Marshal.Copy(bmpLock.Scan0, bmpBuff, 0, bmpSz); bmp.UnlockBits(bmpLock); src.UnlockBits(srcLock); int bw = bmp.Width; int bh = bmp.Height; int sw = src.Width - bw; int sh = src.Height - bh; int bx; int by; int num = sh; for (int y = 0; y <= num; y++) { int sy = y * sStride; int num2 = sw; for (int x = 0; x <= num2; x++) { int sx = sy + x * 3; byte r = srcBuff[sx + 2]; byte g = srcBuff[sx + 1]; byte b = srcBuff[sx]; if (r == bmpBuff[2] && g == bmpBuff[1] && b == bmpBuff[0]) { result = new Rectangle(x, y, bmp.Width, bmp.Height); int num3 = bh - 1; for (int y2 = 0; y2 <= num3; y2++) { by = y2 * bStride; int num4 = bw - 1; for (int x2 = 0; x2 <= num4; x2++) { bx = by + x2 * 3; sy = (y + y2) * sStride; sx = sy + (x + x2) * 3; r = srcBuff[sx + 2]; g = srcBuff[sx + 1]; b = srcBuff[sx]; if (r != bmpBuff[bx + 2] || g != bmpBuff[bx + 1] || b != bmpBuff[bx]) { result = default; sy = y * sStride; break; } } if (result == default) break; } } if (result != default) break; } if (result != default) break; } return result; } } Re: How to compare images? Hiclaudio Image comparison is never one size fits all. Do you want to know if an image is similar, the same, or contains certain features of another image (like image recognition)? It can become very complicated quickly. That being said, a very simple, direct pixel color comparison is a good place to start. We are only interested in the pixels that differ from two same sized images. This function will take two bitmaps and returns a bitmap that is slightly bigger (based on diffStrip value), highlighting the x and y pixel locations that differ only in color. There are faster ways to compare image pixels, however, if speed isn’t an issue this function should be fine. (NOTE: This function does not have error trapping or validation) private Bitmap CompareImages(Bitmap bitmap1, Bitmap bitmap2) { int diffStrip = 2; // get the width and height and add a pixels // use this to create the overlay of each image plus area on the left/top to show were differences are at. Bitmap bmpResult = new Bitmap(bitmap1.Width + diffStrip, bitmap1.Height + diffStrip); List<Point> diffPoints = new List<Point>(); for (int j = 0; j < bitmap1.Width; j++) { for (int k = 0; k < bitmap1.Height; k++) { // get the pixesl and compare if (!bitmap1.GetPixel(j, k).Equals(bitmap2.GetPixel(j, k))) diffPoints.Add(new Point(j, k)); } } Graphics gSource = Graphics.FromImage(bitmap1); Graphics gCompare = Graphics.FromImage(bitmap2); Graphics gResult = Graphics.FromImage(bmpResult); // draw the images on top of each other... gResult.Clear(Color.White); gResult.DrawImage(bitmap1, diffStrip, diffStrip); gResult.DrawImage(bitmap2, diffStrip, diffStrip); // highlight any differences along the top and left edges of the result bitmap foreach (Point p in diffPoints) { for (int j = 0; j < diffStrip; j++) { bmpResult.SetPixel(j, diffStrip + p.Y, Color.Red); bmpResult.SetPixel(diffStrip + p.X, j, Color.Red); } } return bmpResult; } The image below shows a dialog with the first, second and result images. Notice the highlights will be along the top and left side of the returned image. The variable diffStrip can be set to a value, as in the sample code, or it could be set to a percentage of the passed in bitmap’s width or height. This would keep the highlighted lines from being too wide/thick for smaller images and too narrow/thin for larger images. Lastly, the function could be modified to return a Boolean value and save off the result bitmap to a desired locction. Or it could be modified to return an object like KeyValuePair or a custom object that contains the Boolean value and result bitmap. I hope this helps. Regards, Re: How to compare images? Hiclaudio. Image comparison is never one size fits all. Do you want to know if an image is similar, the same, or contains certain features of another image (like image recognition)? It can become very complicated quickly. That being said, a very simple, direct pixel color comparison is a good place to start. We are only interested in the pixels that differ from two same sized images. This function will take two bitmaps and return a bitmap that is slightly bigger using the diffStip value, highlighting the x and y pixel locations that differ only in color. There are faster ways to iterate over image pixels, but this is a simple way if speed isn't a concern. (NOTE: The function does not include any error trapping or validation) private Bitmap CompareImages(Bitmap bitmap1, Bitmap bitmap2) { int diffStrip = 2; // get the width and height and add a pixels // use this to create the overlay of each image plus area on the left/top to show were differences are at. Bitmap bmpResult = new Bitmap(bitmap1.Width + diffStrip, bitmap1.Height + diffStrip); List<Point> diffPoints = new List<Point>(); for (int j = 0; j < bitmap1.Width; j++) { for (int k = 0; k < bitmap1.Height; k++) { // get the pixesl and compare if (!bitmap1.GetPixel(j, k).Equals(bitmap2.GetPixel(j, k))) diffPoints.Add(new Point(j, k)); } } Graphics gSource = Graphics.FromImage(bitmap1); Graphics gCompare = Graphics.FromImage(bitmap2); Graphics gResult = Graphics.FromImage(bmpResult); // draw the images on top of each other... gResult.Clear(Color.White); gResult.DrawImage(bitmap1, diffStrip, diffStrip); gResult.DrawImage(bitmap2, diffStrip, diffStrip); // highlight any differences along the top and left edges of the result bitmap foreach (Point p in diffPoints) { for (int j = 0; j < diffStrip; j++) { bmpResult.SetPixel(j, diffStrip + p.Y, Color.Red); bmpResult.SetPixel(diffStrip + p.X, j, Color.Red); } } return bmpResult; } This image displays a dialog showing the first, second and result images. Notice the difference highlights will be along the top and left side of the returned image. The variable diffStrip can be set to a value, as in the sample code, or it could be set to a percentage of the passed in bitmap’s width or height. This would keep it from being too wide/thick for smaller images or to narrow/thin for larger images. Lastly, the function could be modified to return a Boolean value for your testing needs and the bitmap could be saved to a desired location. Or it could be modified to return any other object type, like KeyValuePair or a custom object that contains the Boolean value and result bitmap. I hope this helps. Re: How to read a JSON file You browse to the location of your desired dll(s) and load it(them) in. Then in your code (I use JavaScript) you can call static methods or instantiate an object through the dotNet object. Note: scripting languages like Javascript don’t support method overloading, so for each constructor method you will see zctor(), zctor_1(), zctor_2(), etc. where each will show you the needed parameters. Below is sample code that writes a JSON file. You might need to add a reference to System.Runtime.dll to access string builder, text writer and file writer. function NewtonSoft() { var sb = dotNET.System_Text.StringBuilder.zctor(); var sw = dotNET.System_IO.StringWriter.zctor_3(sb); var jtw = dotNET.Newtonsoft_Json.JsonTextWriter.zctor(sw); jtw.WriteStartObject(); jtw.WritePropertyName("Make"); jtw.WriteValue_33("Porsche"); jtw.WritePropertyName("Model"); jtw.WriteValue_33("911 GT3"); jtw.WritePropertyName("Engine"); jtw.WriteStartArray(); jtw.WriteValue_33("4.0L"); jtw.WriteComment("(640bhp)"); jtw.WriteEnd(); jtw.WritePropertyName("Transmission"); jtw.WriteStartArray(); jtw.WriteValue_33("6 Speed"); jtw.WriteValue_33("Manual"); jtw.WriteEnd(); jtw.WriteEndObject(); dotNET.System_IO.File.WriteAllText("C:\\test.txt", sb.ToString()); } Output file contents: {"Make":"Porsche","Model":"911 GT3","Engine":["4.0L"/*(640bhp)*/],"Transmission":["6 Speed","Manual"]} I hope this helps. Regards, Re: Process & Popup Window not recognized Hijmoe, Assuming you can see the process in task manager, you could use that name to look for the process for a specified time and if found then terminate it. Something like this: if (Sys.WaitProcess("YourProcessName", 2000).Exists) Sys.Process("YourProcessName").Terminate(); Or if you have the System.Diagnostics.dll added in the Project's CLR Bridge, like this: Then you could possible utilize DotNet, like this: var processes = dotNET.System_Diagnostics.Process.GetProcessesByName("YourProcessName"); for (var i = 0; i < processes.Length; i++) { var p = processes.Get(i); p.Kill(); } Please note: this approach will terminate All process with the provided name. I hope this helps. Regards, Re: Object in Name Mapping only using the first selector (Web application) Hi Katherine, TestComplete will search for an object based on the properties you supply and return the first one that matches your criteria. If you don’t define the criteria narrow enough, then it might find a very similar object but not the one you desire or expect. In your case the application probably has both the AccountCash and AccountCreditCard listboxes created in memory. However, the AccountCash listbox, based on some condition, hasn’t been made visible and has a width of zero, top left and bottom right points both are at the same location (0,103). By narrowing your criteria (adding not(@style="display: none;")) you are searching for visible textboxes, so the AccountCash textbox, which is not visible and has zero width, is not found and TestCopmlete then moves to your second xpath definition. You can see in the image below if you search for a window that have a WindClass of XLMAIN, then TestComplete might find the Windows(“XLMAIN”, “”, 2) window and not Window(“XLMAIN”, “Book1 – Excel”, 1), which is the visible window. I hope this helps. Regards, Re: How to read a JSON file Hiprasath_2k Since the JSON file is a text file you might want to compare files doing one of the following: 1. Use the Files.Compare method:Files.Compare Method | TestComplete Documentation (smartbear.com) 2. Do a simple line-by-line comparison of the contents. Reading each file using the aqFile.OpenTextFile method:aqFile.OpenTextFile Method | TestComplete Documentation (smartbear.com) AsAlexKarasstated JScript supports JSON, so you could read it into an object, but the comparison of objects can be difficult. Regardless, below is a screenshot, with code, that shows a JSON object created from a GIS Json file. It shows how to access each of the objects properties (i.e., features, geometry, rings, etc.). Re: How to read a dynamically generated file using regular expression HiSravani93 If the directory will only have one file then you could use aqFIleSystem.FindFiles function to get the path to that one file. Something like this: var pathToDirectory = "c:\\"; var searchPattern = "*.txt"; var files = aqFileSystem.FindFiles(pathToDirectory , searchPattern, false); var file = file.Next(); var path = file.Path; If there will be more than one file in that directory then you could try a couple of different things. 1. Get the list of files before and after running your test. Then compare the lists to find the new file. 2. If each test creates a new file then you could just get the most recent file: The code below comes from this post:Solved: Re: How to Validate recently downloaded output Exc... - SmartBear Community function getMostRecentCreatedFile(directoryPath, searchPattern) { var newestFilePath = ""; var previousCreationTime = "1/1/1900"; try { var files = aqFileSystem.FindFiles(directoryPath, searchPattern, false); if (files != null) { while(files.HasNext()) { var file = files.Next(); var creationTime = aqFile.GetCreationTime(file.Path); if (aqDateTime.Compare(creationTime, previousCreationTime) == 1) { previousCreationTime = creationTime; newestFilePath = file.Path; } } } } catch(e) { Log.Error("Exception in getMostRecentCreatedFile", e.descrpition); } // return newestFilePath; } function testGetFile() { var filePath=getMostRecentCreatedFile("C:\\Users\\herrerae\\Downloads", "*.xlsx"); } Re: How to validate text color for element using with OCR in Desktop application Hiveerasureshk I am not sure if OCR provides the color property text, but you should be able to capture an image of your control and get the color of specific pixels, which you can compare. Have a look at this entire post, it gives sample code and steps for locating the pixels location in an image: Solved: Re: How to get the font color of a JTree item usin... - SmartBear Community I hope this helps. Re: Issue with Data-Driven Loop, script is not gracefully exiting on error Hidiwakar_sh12, I am not that proficient with python, but you might want to put the try/except block inside of the while loop, that way it can continue with the next entry if an error is raised. I'm not certain of the exact syntax/format, but something like this might work: while not ddv.EOF aqTestCase.Begin("Test Case" + ddv.Value[0]); try: openApp() clickObject(contactUs) waitTillPageLoads() fillContactForm(ddv) except: Log.Error("Error Occured") closeBrowser(Project.Variables.browser) aqTestCase.End() ddv.Next() I hope this helps.