Returning values from one project to another

Class library usage, coding and language questions.
seurrep
Posts: 17
Joined: Tue Aug 07, 2018 10:19 am

Returning values from one project to another

Post by seurrep » Tue Aug 07, 2018 10:25 am

What I'm currently trying to achieve is to write a separate project containing the code that will be posting data via HTTP using WebRequests. The idea is to have this as a generalised project that can be dropped into other Ranorex solutions and used whenever it's needed since some of our testers have no real development knowledge. The problem that I'm having is figuring out how to get functions (UserCodeMethods?) in the posting project to return values to recordings in the other project that references it.

How would I go about this? (am currently using Ranorex 8.2).

I'm also trying to return a value from a UserCodeMethod within a UserCodeLibrary to a recording with both the recording and the code located within the same project. I've seen elsewhere that I can apparently add a variable to the recording then set that within the code. Is that correct or does that only apply to modules? I've tried and all I get is the generic 'The name 'returnCode' does not exist in the current context (CS0103)' message when I try and use it within a method (returnCode obviously being the variable I'm trying to use and the code is trying to set)
Last edited by seurrep on Wed Aug 08, 2018 10:08 am, edited 1 time in total.

User avatar
N612
Posts: 62
Joined: Mon Jul 11, 2016 4:01 pm

Re: Returning values from one project to another

Post by N612 » Thu Aug 09, 2018 2:55 am

While you can return an object from a UserCodeCollection method, a recording module does not have a way to handle the returned object without going into code. The sample UserCodeCollection Method "MyMethod1" returns the string "Hello World!".

Code: Select all

[UserCodeMethod]
public static string MyMethod1()
{
     return "Hello World!";
}
If you are returning a string such as the above example, you can make a simple code method in the recording module that sets this value to a recording variable (which must be a string). If you are able to explain exactly what you are trying to return and why, we may be able to further assist you with your project structure.

Recording Module User Code Method "SetVariable"

Code: Select all

public void SetVariable()
{
     MyRecordingVariable = UserCodeCollection1.MyMethod1();
}
2018-08-08 21_49_57-ProjectA - Ranorex Studio (Administrator).png
2018-08-08 21_49_57-ProjectA - Ranorex Studio (Administrator).png (6.4 KiB) Viewed 118 times