How can I insert a step into a PopupWatcher

Class library usage, coding and language questions.
kdreiling
Posts: 34
Joined: Mon Sep 24, 2012 9:45 pm
Location: Kansas City

How can I insert a step into a PopupWatcher

Post by kdreiling » Fri Apr 16, 2021 5:06 pm

Hello!

I would like to StartPopupWatcher but before the clickElement is clicked enter a phone number in a field on the popup. Populating this field with a phone number enables the button so it can be clicked and move on.

{
CheckArgumentNotNull(findElement, "findElement");
CheckArgumentNotNull(clickElement, "clickElement");

var key = findElement.GetMetaInfos()["id"] + clickElement.GetMetaInfos()["id"];

if (watchers.ContainsKey(key))
{
throw new ArgumentException("Popup watcher with given parameters already exists.");
}

var watcher = new PopupWatcher();
watcher.WatchAndClick(findElement, clickElement);
watcher.Start();
watchers.Add(key, watcher);
Report.Info("Popup watcher started.");
return watcher;
}


Here is the text path:
/form[@controlname='frmFaxNumberOverride']/?/?/text[@accessiblerole='Text']

Is there some way to do this without having to write custom user code, since I'm not a developer? I have done this before, but it is fairly inconsistent.
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How can I insert a step into a PopupWatcher

Post by odklizec » Tue Apr 20, 2021 12:09 pm

Hi,

In my opinion, your best hope is to use PauseWhileExists method from "Ranorex Automation Helpers". In this method is called method RequestPauseWhileExists, in which you should be able to add your code. Eventually, write your own RequestPauseWhileExists overloaded method and use it instead of the default one ;) There is, unfortunately, no way to do this without code. Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

kdreiling
Posts: 34
Joined: Mon Sep 24, 2012 9:45 pm
Location: Kansas City

Re: How can I insert a step into a PopupWatcher

Post by kdreiling » Tue Apr 20, 2021 1:42 pm

Thank you, Pavel:

Unfortunately, I'm not a developer other than writing a bit of code here and there to set dates in the future or past, so that was the reason I reached out. I did try PauseWhileExists, and I could take the recorded steps and attempt to insert them (trial by error) into the method, but where in the method would I insert the code? I might be able to reach out to one of our developers to see if they can assist, but they don't know Ranorex.

It may be best to open a ticket with Ranorex, but I'd sure like to learn some coding techniques as I try to improve my skills. Basically, when FrmFaxNumberOverride form displays, I want to set a generic fax number (of type text), which then enables the Send Fax button so it can be clicked . The form and the button should be handled, but the step to enter the fax number has to be inserted somewhere. Sounds pretty simple, unless you are not a developer. :)

If you could return some code format suggestions. I can take it and try to incorporate it into the PauseWhileExists. You helped me several years back embed SQL calls into my recordings that is still in use today. I am still grateful for that!

Any suggestions would be so appreciated.

Thanks in advance.

[UserCodeMethod]
public static PopupWatcher PauseWhileExists(RepoItemInfo findElement)
{
CheckArgumentNotNull(findElement, "findElement");

var key = findElement.GetMetaInfos()["id"];

if (watchers.ContainsKey(key))
{
throw new ArgumentException("Popup watcher with given parameters already exists.");
}

var watcher = new PopupWatcher();
watcher.Watch(findElement, RequestPauseWhileExists);
watcher.Start();
watchers.Add(key, watcher);
Report.Info(string.Format("Started watching for '{0}'.", findElement.FullName));
return watcher;
}