Add C# Code to Recording

Ranorex Spy, Recorder, and Studio.
gweisenb
Posts: 3
Joined: Fri Oct 24, 2014 12:01 am

Add C# Code to Recording

Post by gweisenb » Fri Oct 24, 2014 12:15 am

NEWBIE alert

Working in Ranorex Studio 5.1.2 and have recorded a web browser automation test. During the test an unexpected popup comes up sometimes. I saw code example on how to deal with this issue, but the .cs file for the recording is locked and I don't know how to add the popup watcher code.


Thanks.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Add C# Code to Recording

Post by krstcs » Fri Oct 24, 2014 1:52 pm

If you want to add "User Code" to your recording, you have a few ways to do that.

1. Select "User Code" from the "Add New Action" menu.
2. When you drag a repo item onto the action table, select "User Code" and a type.
3. Right-click on an action that is already in the action table and select "Convert to User Code" or "Merge Items to User Code Item" (if more than one is selected).


The recording itself (*.cs file, not the *.UserCode.cs file) is locked because it is system generated.

You can also create a new item in the project that is a Code Module instead of a Recording Module. This will allow you to put whatever code you want and still use the Code Module in test cases.


As for the unexpected popup, many times these popups happen in response to some input or timing that you, as the tester, could have some control over. If that is the case, then you should probably put in a better way to handle that test case. If it is NOT the case, and it is random (like network warnings, or something like that), then using the PopupWatcher class is your best bet. Note though that it runs in a separate thread from the main test, so it can't really communicate with the main test thread. Use it when you need to just click "OK" or "Cancel" on a dialog, but don't really care about the content or validation.
Shortcuts usually aren't...