User code: RepoItemInfo.CreateAdapter's timeout

Best practices, code snippets for common functionality, examples, and guidelines.
HansSchl
Posts: 143
Joined: Wed Sep 19, 2018 10:05 am

User code: RepoItemInfo.CreateAdapter's timeout

Post by HansSchl » Wed Apr 05, 2023 7:59 am

Hi,

I wrote user code in C# which wait for a progress dialog to pop up and then watches its progress bar until the dialog closes, and throws an exception if the progress doesn't change over a period of time. The first few lines of this function are as follows:

Code: Select all

public static bool WatchProgress(RepoItemInfo progressInfo, ..., Duration initialTimeout, ...)
{
	var dlgInfo = new RepoItemInfo(progressInfo.ParentFolder, "Progress Dialog", ".", initialTimeout, false);
	Report.Info("Progress", string.Format(@"Watching progress dialog ""{0}""", progressInfo.ParentFolder.ToString()));
	var dlgAdapter = dlgInfo.CreateAdapter<Unknown>(false, initialTimeout);
	if (dlgAdapter == null)
	{
		Report.Info("Progress", "The progress dialog was removed before it could be found (or it has never existed)");
		return false;
	}
	...
}
When called, the 'progressInfo' parameter is the progress bar from the test suite's repository, and 'initialTimeout' is set to 10s. 'dlgInfo' is created as the RepoItemInfo for the progress dialog whose immediate child the progress bar is.

The problem is that this occasionally runs into the 'return false;' even though, in my opinion, it shouldn't. In the report I see those lines:

Code: Select all

19:11:57 Info Progress Watching progress dialog "DBMCommonRepo.DBM_Dialogs.Copying_Dialog"  
19:12:02 Info Progress The progress dialog was removed before it could be found (or it has never existed)  
In the screen video I can see that the dialog pops up at 19:11:57. At this moment, the Ranorex execution window displays the message 'Watching progress dialog "DBMCommonRepo.DBM_Dialogs.Copying_Dialog"'. Obviously the 'CreateAdapter' function doesn't wait the full timeout before it gives up and returns null. at 19:12:03, when 'return false' has already executed, the progress dialog is still visible.

I assume this occurs when the dialog pops up a moment (a few millisecs maybe) after the call to 'CreateAdapter'. Since these events occur asynchronously to each other, there is a chance that it works or that it fails. I should mention that I recently upgraded from Ranorex 10.1.3 to 10.5.4 and that these failures have become much more frequent.

Is it my misunderstanding of 'CreateAdapter' or is it a bug in Ranorex (or neither)? What can I do to make this test more stable?

Thank you
Hans