How to detect changed Handle

Ask general questions here.
mats
Certified Professional
Certified Professional
Posts: 23
Joined: Tue May 18, 2010 12:58 pm

How to detect changed Handle

Post by mats » Mon Mar 26, 2012 9:29 am

Some GUI refresh are difficult to detect without doubt. The only clear difference is (in my case) the Handle.
Without completed GUI refresh, the following test step can fail. A workaround would be a huge timeout.

How to detect a changed Handle:
User-Code can be written firstly to save the actual Handle and secondly to wait until the saved Handle has changed. But this has to be done for every Repository-Item.

Is there an other way to detect a changed Handle?
A feature request would help: User-Code with Repository-Item as input parameter.

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

Re: How to detect changed Handle

Post by Support Team » Wed Mar 28, 2012 9:17 am

Hi,

Please explain your problem in detail, you want to detect if the GUI elements have changed or are updated?
Can you also send us two Ranorex snapshot files of your application, one before and one after the refresh?
Following link will show you how to generate a snapshot file.
How to detect a changed Handle ... but this has to be done for every Repository-Item.
If you want to check if all/more elements have changed you have to test each of these, or did I miss something?

Regards,
Markus
Ranorex Support Team
.
Image

mats
Certified Professional
Certified Professional
Posts: 23
Joined: Tue May 18, 2010 12:58 pm

Re: How to detect changed Handle

Post by mats » Mon May 21, 2012 12:33 pm

With some help by the Support Team I implemented two Methods.

Check if Mouse.CursorName != "WaitCursor" during 3s
Method Timeout ~= 20s (waitCountMax = 200 * 0.1s)

Code: Select all

public static void Wait_NotBusy()
{
  String CursorName;
  Int32 waitCountMax = 200;   // Method Timeout ~= 20s 
  Int32 notBusyCountMax = 30;
  Int32 notBusyCount = 0;
  Report.Info("Wait_NotBusy");
  for (int waitCount = 1; waitCount <= waitCountMax; waitCount++)
  {
    Delay.Duration(100, false);
    try
    {
      CursorName = Mouse.CursorName;
      if (CursorName != "WaitCursor")
      {
        notBusyCount++;
      } else {
        notBusyCount = 0;
        //Report.Warn("CursorName [" + CursorName + "] Reset notBusyCount" );
      }
      if (notBusyCount >= notBusyCountMax)
      {
        break;
      }
    }
    catch (Exception e2)
    {
      Report.Debug("Exception occured: " + e2.ToString());
      if (e2.GetType().ToString() != "System.NullReferenceException")
      {
        Report.Error("Unexpected exception occured: " + e2.ToString());
      }
    }
  }
}
Wait for changed AttributeValue
The first execution will wait waitCountMax, if repo.varFileName is not set to the valid value.

Code: Select all

public static void openedPDF()
{
  Int32 waitCountMax = 6;
  int waitCount;
  //Report.Warn("openedPDF");
  try
  {
    for (waitCount = 0; waitCount < waitCountMax; waitCount++)
    {
      //Report.Warn("opened PDF >>> repo.varFileName: " + repo.varFileName + " waitCount: "+ waitCount );
      if (repo.ARTSViewer.DocViewer.AdobeReader.SelfInfo.Exists())
      {
        string fileNameTemp = repo.ARTSViewer.DocViewer.AdobeReader.PDF_Title_Hidden.Element.GetAttributeValue("Caption").ToString();
        if (fileNameTemp != repo.varFileName)
        {
          Report.Info("opened PDF: " + fileNameTemp + "." );
          repo.varFileName = fileNameTemp;
          break;
        }
        Delay.Duration(500, false);
      }
    }
    if (waitCount == waitCountMax)
    {
      Report.Info("No other PDF opened!" );
    }
  }
  catch (Exception e2)
  {
    Report.Debug("Exception occured: " + e2.ToString());
    if (e2.GetType().ToString() != "System.NullReferenceException")
    {
      Report.Error("Unexpected exception occured: " + e2.ToString());
    }
  }
}