Ranorex does not hit controls sporadically

Class library usage, coding and language questions.
Ralf
Posts: 4
Joined: Thu Apr 12, 2012 2:21 pm

Ranorex does not hit controls sporadically

Post by Ralf » Thu Apr 12, 2012 2:51 pm

Hi Everyone,

I am using Ranorex V3.1 for our automated testing. We do not use the Ranorex Studio nor the Recorder. I just use Ranorex Api methods and address the Control via the Ranorex Path.
Everything works fine, but sometimes Ranorex does not hit the Control correct or the PressKeys method looses single keys.
I experienced theese Problems in 2 different situations:

1. Ranorex looses input keys

Code: Select all

Ranorex.Text textBox = ...... //Find TextBox
if (textBox.Enabled)
{
    //Select old value
    textBox.Select(0, textBox.TextValue.Length);
    //Delete old value
    textBox.PressKeys("{Delete down}{Delete up}");
    //Input new value
    textBox.PressKeys("my new Value");
    //Leave TextBox for Validation
    textBox.PressKeys("{Tab}");
    //Make sure, that the right value was set
    if (textBox.TextValue != "my new Value")
    {
        //What went wrong?
    }
}
With this code I experienced, that the TextValue Property of the TextBox did not get all of the characters. Some were missing. Even in between the value.
So I tried to do it different via clipboard an pasting, but even then the PressKeys method misses the past command sometimes.

Code: Select all

Ranorex.Text textBox = ...... //Find TextBox
if (textBox.Enabled)
{
    //Select old value
    textBox.Select(0, textBox.TextValue.Length);
    //Input new value
    Clipboard.SetText(p_Text);
    textBox.PressKeys("{Control down}{vKey}{Control up}");
    //Leave TextBox for Validation
    textBox.PressKeys("{Tab}");
    //Make sure, that the right value was set
    if (textBox.TextValue != "my new Value")
    {
        //What went wrong?
    }
}

2. When clicking on a menu item, the cursor moves to upper left corner of the screen

Code: Select all

Ranorex.MenuItem mainMenu = ...... //Find Menu
if (mainMenu.Enabled)
{
    mainMenu.Click();
    
    Ranorex.MenuItem subMenu;
    //Try to find the submenu
    if (!mainMenu.TryFindSingle(@"./contextmenu/menuitem[@accessiblekeyboardshortcut='n']", 500, out subMenu))
    {
        //What went wrong?
    }

    //Continue
}
This is a example code, how I click on a menu. Sometimes, during the Click method of the menu, the cursor moves to the icon in the window's taskbar and clicks there (maximized window). I have no clue why?! If Ranorex would not find the menu, I would get an Exception before, right?


So I hope you can help me. Are problems like this already known?
I have to say, that I run a lot of tests for several hours, so I changed the default times:

Code: Select all

Ranorex.Mouse.DefaultMoveTime = new Ranorex.Duration(10);
Ranorex.Mouse.DefaultClickTime = new Ranorex.Duration(10);
But otherwise Ranorex would be ways too slow.

Thanks for your help.
Greets Ralf

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Ranorex does not hit controls sporadically

Post by Ciege » Thu Apr 12, 2012 4:59 pm

For 1, it could be the keys are being pressed too fast... What I have done for this situation is I wrote a little keypress method that accepts a string var and slows down the input..
Here is the meat of the method that slows down the input...

Code: Select all

foreach (char c in strMyString)
{
  Keyboard.Press(c);
  Thread.Sleep(300);
}
For 2, when the cursor moves to the top left, that means Ranorex does not have or cannot find the proper element it is trying to click on.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

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

Re: Ranorex does not hit controls sporadically

Post by Support Team » Fri Apr 13, 2012 11:43 am

Ciege wrote:This is a example code, how I click on a menu. Sometimes, during the Click method of the menu, the cursor moves to the icon in the window's taskbar and clicks there (maximized window). I have no clue why?! If Ranorex would not find the menu, I would get an Exception before, right?
Did you try to add a short delay of before you click the submenu item? Maybe the object is only partially visible and has no real screen coordinates yet. Then Ranorex finds the object but clicks on 0;0 because the item is there but with wrong coordinates. Does this occur always or only sometimes?

Regards,
Peter
Ranorex Team
.
Image

Ralf
Posts: 4
Joined: Thu Apr 12, 2012 2:21 pm

Re: Ranorex does not hit controls sporadically

Post by Ralf » Wed May 09, 2012 3:29 pm

Hi again,

thanks for your replies.

The answer
Did you try to add a short delay of before you click the submenu item?
is not an option for me, because I do so many tests, that my test application runs all night to do the tests. And this is the slowest testing time possible, because we do the development during the day and the tests at night. So turning Ranorex slow, is not an option for us.

In my understanding a Ranorex object is accessable, if I found it via the FindSingle-Method. And I find my objects, but sometimes the actions (e.g. Click, PressKeys) just do not work. As I understood your answers, it is possible that I found a Ranorex.Adapter, but it is still not "ready" to be used? - That would be a bug in my eyes :(

In the last weeks I discovered that several commands have not been executed. E.g:
Button.Click
CheckBox.Click
TextBox.PressKeys
ComboBox.Click
Cell.DoubleClick

Is there any secure way to make sure, that Ranorex does execute called Commands? Even if I do it in a fast way?

Thanks for you help.
With best regards
Ralf

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

Re: Ranorex does not hit controls sporadically

Post by Support Team » Thu May 10, 2012 10:17 am

Ralf wrote:As I understood your answers, it is possible that I found a Ranorex.Adapter, but it is still not "ready" to be used
This is possible, e.g. this is always true for disabled controls. The control will be found, but is not enabled for use.

You can check the "Enabled" attribute of the corresponding Ranorex element to make sure the control is ready for use. The easiest way to do that is to add a check to the RanoreXPath, e.g. "[@enabled='true'], then the element will only be found if it is enabled.

That said, what technologies (WinForms, WPF, Web, Flex, Java ...) are used by the application you automate?

Regards,
Alex
Ranorex Team
.
Image

Ralf
Posts: 4
Joined: Thu Apr 12, 2012 2:21 pm

Re: Ranorex does not hit controls sporadically

Post by Ralf » Thu May 10, 2012 10:36 am

Thanks for your reply.
Here is an example how I click a Button. I search it via the Path, then I call my WaitControl2BeEnabled Method and after that I try to click the Button. And still it is not secured that it will work.

Code: Select all

public static Ranorex.Button Click(Ranorex.Adapter p_Parent, string p_SubPath, int p_ControlId)
{
    Ranorex.Button button = RxWrapperBasics.FindElement(@"." + p_SubPath + "/button[@controlid=" + p_ControlId + "]", p_Parent);

    WaitControl2BeEnabled(button); 
    
    if (button.Enabled)
    {
        button.Click(MouseButtons.Left, new Duration(50));
    }
    else
    {
        throw new EndTestCaseException(string.Format("Button \"{0}\" was not enabled, while trying to click", button.GetPath()));
    }
    return button;
}

Code: Select all

private const int c_WaitingTimeControl2BeEnabled = 500;
private const int c_WaitingCountControl2BeEnabled = 5;
public static void WaitControl2BeEnabled(Ranorex.Adapter p_Control)
{
    for (int i = 0; i < c_WaitingCountControl2BeEnabled; i++)
    {
        if (p_Control.Enabled)
        {
            break;
        }
        Thread.Sleep(c_WaitingTimeControl2BeEnabled);
    }
}
A call would look like this:

Code: Select all

RxWrapper.Button.Click(motorAssistent, "/container", 12324); //motorAssistent is the parent dialog
RanorexPath in Spy: /form[@title~'^Motorassistent\ 1LA\ \ \ Schr']/container/button[@controlid='12324']

I do the test automation for an MFC Appliaction. Its quite old and was tested with Rational Robot before. But at the moment we are changing the test software to Ranorex. :)

Thanks for your help.
Ralf

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

Re: Ranorex does not hit controls sporadically

Post by Support Team » Fri May 11, 2012 2:40 pm

Hi,
And still it is not secured that it will work.
Can you determine what the problem was?
Was the click maybe performed on a different location, for instance on the left corner?
Did the click work properly if the button was enabled?
I would use the mentioned RxPath in combination with a timeout:
Ranorex.Button button = RxWrapperBasics.FindElement(@"." + p_SubPath + "/button[@controlid=" + p_ControlId + "and @enabled='true']",p_Parent);
Regards,
Markus
Ranorex Support Team
.
Image

Shannon
Posts: 2
Joined: Fri Nov 21, 2014 7:15 pm

Re: Ranorex does not hit controls sporadically

Post by Shannon » Fri Nov 21, 2014 7:19 pm

I am having the same problem. I record a web script and when I play it the mouse moves to the upper left hand corner of the window and just sits there.

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Ranorex does not hit controls sporadically

Post by JSH_QA » Mon Nov 24, 2014 11:35 am

Hi Shannon,

You might want to look at the thread at http://www.ranorex.com/forum/some-adapt ... t7013.html

The mouse pointer moving to the top-left can result from state changing in the Application Under Test (AUT)between the point that the Ranorex script does a Find operation, and the point that it does a Click or other operation. We have an application that reacts to mouse hover-over events and that has asynchronous behaviour such as auto-complete on edit boxes. Both of these can change the state of the AUT between the point that we Find what we want to click on and the point that we actually click. When we identify such cases, we modify the scripts to one of the following:
(1) bypass the asynchronous behaviour by implementing a different set of test steps, or by using Invoke Action operations rather than mouse moves/clicks.
(2) wait until any asynchronous behaviour is complete.
(3) detect when a click does not result in the AUT doing anything, and then implement a retry mechanism (this is a last resort).

Regards,

John H.