Saving Part of Message Into a Variable

Ranorex Spy, Recorder, and Studio.
jkang
Posts: 2
Joined: Fri Sep 06, 2013 3:54 pm

Saving Part of Message Into a Variable

Post by jkang » Fri Sep 06, 2013 4:37 pm

So here's what happens in the application. When case information is entered completely and is saved, the following confirmation message should appear:
CaseCreationMessage.jpg
CaseCreationMessage.jpg (16.17 KiB) Viewed 885 times
When the case is saved, the case number is auto-generated a random number/combination and assigned to that case. So in that confirmation message I need to just extract the "F2-13-000153" portion of the message and save it into a variable that I can use later to enter this case number into a case number field when I later perform a case search.

Ideally, if I could also use this variable with the case number saved, in continuation to another recording (i.e. creating a case and then searching for a case) that would be great.

So far this is what I have to get the text value:

Code: Select all

Accessible accElement = new Accessible(repo.MessageBoxDialog.CaseSuccessfullyCreatedWithCaseNumb);
string FullCaseSuccessMessage = accElement.Value;
As of now I'm thinking of first assigning that accessible value to a string, and then splitting the string and storing just the CaseNumber into a separate Variable. However when I tried to use this "FullCaseSuccessMessage" variable that I set again, it appears to come out as null.

If someone could help me with writing the code for this, that would be awesome.

Thanks.

jkang
Posts: 2
Joined: Fri Sep 06, 2013 3:54 pm

Re: Saving Part of Message Into a Variable

Post by jkang » Fri Sep 06, 2013 9:51 pm

I got it to work and Heres my code:

Code: Select all

repo.FrmMain.FrmCreateCase.Save.Click();
Accessible accElement = new Accessible(repo.MessageBoxDialog.CaseSuccessfullyCreatedWithCaseNumb);
string FullCaseSuccessMessage= accElement.Name;
string []SavedCaseNumber = FullCaseSuccessMessage.Split(" ".ToCharArray());
repo.FrmMain.None.PressKeys(SavedCaseNumber[7]);
I have a different question. As you can see the extracted case Number is set to the variable SavedCaseNumber. Is it possible to make this variable and value usuable in another recording.

For example: Lets say I wanted to create 2 separate recordings to create a case and search for a case. Is there a way I can use the SavedCaseNumber variable saved from the create case recording and use it in the search case recording?

Thanks.

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

Re: Saving Part of Message Into a Variable

Post by Support Team » Tue Sep 10, 2013 4:44 pm

Hello,

Thank you for providing your solution.
In order to use the value of your variable in other modules you can use a global parameter.
Please read the section "Ranorex Test Suite" in our user guide in order to get more information about global parameters.

Regards,
Bernhard
.
Image