Page 1 of 1

Returning values from one project to another

Posted: Tue Aug 07, 2018 10:25 am
by seurrep
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)

Re: Returning values from one project to another

Posted: Thu Aug 09, 2018 2:55 am
by N612
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

Re: Returning values from one project to another

Posted: Wed Nov 28, 2018 5:27 pm
by JimLin
Hi N612, thanks for your answer to this, as it's solved something I have been banging my head against for the last day and thought I was going mad :-D.

Does anyone know why it is currently so difficult to get to the values in a User Code Module and whether Ranorex are going to make it easier, as the current way of doing it is a bit cumbersome?

Cheers,
JimLin