Page 1 of 1

Ranorex Layout Methods

Posted: Mon Oct 18, 2010 5:47 pm
by costamesakid
This post is rather vague. Im just looking for some direction to get me started.

Basically, I have a form with the following xPath

/form[@title~'^TacViewC2\ \ \ \(map:\ DefaultMap\.map\)\ \(terra']

This form is just a rectangular map, where you can right click on the map to add other elements. In Ranorex Spy I can see under the Details tab the various Layout properties for this form. Including Height and Width.

Eventually I want to write code that will randomly right click anywhere within the confines of this form, but I have to avoid right clicking near the edges. For instance, if the form is 100 x 120, I want to randomly click within the confines of 80 x100.

Are there any Ranorex or C# Layout methods I can further investigate to help me accomplish the above? Thanks

Re: Ranorex Layout Methods

Posted: Mon Oct 18, 2010 6:23 pm
by Ciege
If you know the height and width and just want a random X,Y within that you could just write a random number generator method that takes parameters (I.e. the widths to be within or the heights to be within) and return a random number. Then pass the two random numbers you receive to a click method that clicks at the point you pass in.

So in theory you would have 3 generic methods:
1) FindFormSize - Takes a form var and returns it's X/Y mins a maxs
2) CreateRandomNumer - Takes a min and a max and returns a random number
3) ClickHere - Takes an X and a Y and clicks there

Re: Ranorex Layout Methods

Posted: Mon Oct 18, 2010 6:43 pm
by costamesakid
Yep, thats just what I ended up doing. I just didnt know how to determine the width and height of my repository item. Looks like ScreenRectangle.Width and .Height did the trick. The code looks like this:

public static void RandCoord()
{

Ranorex.Container test = @"/form[@title~'^TacViewC2\ \ \ \(map:\ DefaultMap\.map\)\
\(terra']/element/container[@accessiblename='RvView']";
var a = test.ScreenRectangle.Width;
var b = test.ScreenRectangle.Height;
int c = Convert.ToInt32(a);
c = c - 100;
int d = Convert.ToInt32(b);
d = d - 100;
string w = CommonUtilLib.Util.Random(100, c);
string h = CommonUtilLib.Util.Random(100, d);
repo.FormTacViewC2____map__Defaul.ContainerRvView.Click(MouseButtons.Right, "" + w + ";" + h + "");
}

Re: Ranorex Layout Methods

Posted: Mon Oct 18, 2010 6:50 pm
by Ciege
Looks pretty good. One thing that I see that could present an issue for you is that your code is assuming your form/container will always be at the left and top of the screen. What if the container is not at 0,0?

What you can do is also get the test.ScreenRectangle.X and test.ScreenRectangle.Y vars and add 100 (or whatever to them) and pass that result into your CommonUtilLib.Util.Random commands. That way you are certain to be within the bounds of your container.

Good job!