Page 1 of 1

Unexpected dialog separate thread issue

Posted: Thu Aug 15, 2013 1:52 am
by paul@tmd
Hi,

I use Ranorex to perform bulk input of data into HR databases that I host, rather than as a testing application.

Quite often when entering data, dialogs are displayed depending on the conditions of the individual entry. The thing is, they aren't always displayed so I needed a way of dealing with these unexpected dialogs.

I followed the instructions on the Ranorex Blog 'Handling dialog and pop-up windows' and it seems to work for a few entries and then I get an odd error, where Ranorex cannot find the unexpected dialogs. From my understanding, the separate thread is constantly looking for the dialogs, however only closes them IF they are found. I can't understand why the error is being displayed.

This is the user code I'm using as the separate thread:

using Ranorex.Core.Testing;

namespace Upload_skills
{
public partial class Recording1
{

private void Init()
{
Thread dialogWatcher = new Thread(ClosePopUpDialogs);
dialogWatcher.IsBackground = true;
dialogWatcher.SetApartmentState(ApartmentState.STA);
dialogWatcher.Start();


}
public static void ClosePopUpDialogs()
{
while (true)
{
if (repo.Unknown.SelfInfo.Exists() )
{
Thread.Sleep(300);
repo.Unknown.Close.Click();
}

Thread.Sleep(1000);



}
}
}
}


This is my "Unknown" item in the repository that is being watched for:

/form[@title!='(Empower-HR(raven::mydb_prod)|Skill|Skill - Add|admin)' and @accessiblename='Empower-HR'] - essentially watching for any window other than the ones I need to enter data into.

And this is the error message that randomly pops up:

Ranorex.ElementNotFoundException: Failed to find item 'Upload_skillsRepository.Unknown.Close'. ---> Ranorex.ElementNotFoundException: No element found for path 'titlebar/button[@accessiblename='Close']' within 30s.
at Ranorex.Core.Repository.RepoItemInfo.Find
at Ranorex.Core.Repository.RepoItemInfo.CreateAdapter
at UnknownAppFolder.get_Close in c:\Users\TEMP.TMD.018\Documents\Ranorex\RanorexStudio Projects\Upload_skills\Upload_skills\Upload_skillsRepository.cs:line 3172
at Upload_skills.Recording1.ClosePopUpDialogs in c:\Users\TEMP.TMD.018\Documents\Ranorex\RanorexStudio Projects\Upload_skills\Upload_skills\Recording1.UserCode.cs:line 46
at System.Threading.ThreadHelper.ThreadStart_Context
at System.Threading.ExecutionContext.Run
at System.Threading.ExecutionContext.Run
at System.Threading.ThreadHelper.ThreadStart




Also, I get some strange behavior from Ranorex occasionally where it seems to get stuck mid-script. I have a couple of 3500ms delays built in but apart from that each action is 200ms. The only way to recover from the 'freezes' is to stop the script.

This is my first time using user code and I'm at a loss. Any help anyone could give would be greatly appreciated! :) Thank you for your time.

Paul

Re: Unexpected dialog separate thread issue

Posted: Sat Aug 17, 2013 10:28 pm
by Support Team
A few ideas pop up to my mind, what could cause the "Close" button not to be found. These are the most likely ones :D
  • The dialog has no "Close" button. Rather use the Form.Close method
  • Do you start the recording a few times? If yes, then with every recording a new thread will be launched searching for the dialog. If two threads happen to execute the Click on the "Close" button at the same time, the error will pop up.
Regards,
Alex
Ranorex Team