You might have already wondered; Ranorex does object-based recording, so a click action, for example, is always performed on a specific UI element, no matter how it looks or what screen coordinates it has. However, if you look closely on the action spot of a click action, you can still see that behind the word “Relative” a strange value like 51;13 is hidden. So, does this mean that Ranorex still records coordinate-based? And can I change this behavior? And what side-effects could this have? This small article should answer all those questions.
Coordinate Recording Mode
The setting that defines this behavior is the Coordinate Recording Mode that can be found in Settings -> Recorder Defaults. This setting has three possible values: Pixel, None, and Proportional. This setting defines how the exact action spot within a UI element is determined. The default is Pixel. This setting records the exact location of a click within the UI element. For example, if you click on a button in recording mode near its top left corner, you will get small coordinate value like 5;8, since the top left corner always has the coordinates 0;0. These coordinates use integer values and will also be used for playback. The setting None behaves differently: Here, it doesn’t matter where on the element you click in recording mode, Ranorex will use the action spot Center and in playback will always click on the middle part of the button. The setting Proportional uses coordinates in the form of .5;.6, thus using floating point numbers instead of integers. This means that if you click on a pixel in recording mode that is 30% of the button size from the top, then in playback Ranorex will also click a pixel that is 30% from the top in playback mode.
Advantages and disadvantages
All three of these settings each have a set of disadvantages and advantages. In fact, None might seem to be the best setting, but Pixel is the default value in Ranorex.
This setting is the default in Ranorex. It recognizes the exact (=pixel-perfect) action spot in the UI element in recording mode and uses these coordinates for playback. This has one huge advantage: When running the test, Ranorex does exactly the same thing that you were doing when you recorded the test. At least as long as you stay on your same screen with the same screen resolution and the same screen scaling, that is. In modern applications, especially web applications, responsive design has become increasingly more important, and a button or a text field might change its size drastically, depending on the size of the application window, the screen, the device orientation, etc. For example, on the Amazon homepage, you might want to click into the search field, somewhere in the middle:
If we put our browser from maximized mode into a much smaller window size and try to run the test, this click suddenly doesn’t work anymore, because the coordinates that I have recorded (958;17 in my case) are suddenly outside of this element, since this text box has shrunk in size. This warning looks like this:
Suddenly, Pixel looks like a far from the optimal default setting. Especially in modern, web-based applications that use responsive design, this setting is far from ideal. So why is it that it still is the default setting in Ranorex? Consider this element in your application:
Unfortunately, the checkbox with its label is recognized as just one element. Especially in deprecated desktop technologies, this is very common. You also often see the small triangles or plus-symbols that should expand a section of a list or tree – those are also often not recognized as separate buttons. However, automating only works if you exactly click these buttons, not the text near it. This makes it necessary that a click is performed on the exact same spot within the control as it was recorded. Would the click just be performed on the Center location of that element, the checkbox in this example wouldn’t get ticked.
This setting works very differently, and it changes the behavior of the test run drastically compared to the recording. Every action spot is set to Center. This might sound as if it makes sense in many cases, especially when you have responsive design, but it has a few serious drawbacks. For example, consider you want to click on this headline on a web page:
When recording, you would click this text, and it would work. However, in the test run, the action spot would be Center, and therefore the click spot would not actually be on the text itself:
Although the value None might seem like a good setting on the first glance, you can run into these issues frequently. So, is there a better way to do it, if both Pixel and None have some big drawbacks?
This setting tries to, similarly to Pixel, retain the action spot exactly where it was while recording, but in relation to the size of the element. This means that a click on a spot that is 30% from the left edge and 60% from the top edge will also be done 30% from the left and 60% from the top in the test run, no matter how big or small the element now is. This mitigates the problem that the Pixel setting had: if a button shrinks, the action spot is still inside of the button. And some issues that None has are also solved, but still, Proportional suffers from similar issues. For example, a click here…
…would translate to a click here in the test run, if the screen size becomes a bit smaller:
Thus, the setting Proportional suffers from very similar issues to None. This setting is represented by floating point numbers in Ranorex. For example, the Center location could also be written as 5;.5 in proportional notation.
The Best Setting
So, the question is: What is the best setting for me? The answer is pretty unsatisfying: It depends on your application. Pixel is the default because we think that if you record a test and then run it afterward without changing anything in between, it should run. None does not have this property, and while None looks logical up to a certain degree, Proportional seems to do very illogical things if you don’t know how the action spot is calculated. Therefore, we have decided to stick with Pixel as the default. This is often best for pure desktop applications and works fine if you don’t change the screen resolution. None and Proportional both have their uses in applications with responsive design (mostly in the web and on mobile devices), however, they can have strange side-effects. In all three cases, depending on your actual UI element, it might be necessary to change the action spot manually if it doesn’t do what you want. There is no cure-all type of setting. All of them have advantages and disadvantages. If you know what properties those settings have, you can easily pick the one that suits your project best.