Passing variables from user code module to user code module

Ask general questions here.
charleyrobertson
Posts: 8
Joined: Thu Sep 29, 2022 4:33 pm

Passing variables from user code module to user code module

Post by charleyrobertson » Tue Oct 25, 2022 12:44 pm

My colleague and I are currently creating a smoke test suite where on multiple occasions we are having to pass variables between two different user code modules contained within one test case.
We are managing to pass single variables between the user code modules but whenever we have multiple variables defined and attempt to pass them the information does not get passed through to the next module. The information gets stored inside of the variables in the first step in the first test in the test suite, it just does not pass through.

Is there a standard way to pass variables (single and multiple)?

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: Passing variables from user code module to user code module

Post by doke » Wed Oct 26, 2022 7:24 am

Hi Charley,

see attached demo project for some simple paramater propagation.
Mypassvars.zip
hope this fits your needs,
regards ,

Don
You do not have the required permissions to view the files attached to this post.

charleyrobertson
Posts: 8
Joined: Thu Sep 29, 2022 4:33 pm

Re: Passing variables from user code module to user code module

Post by charleyrobertson » Wed Oct 26, 2022 12:36 pm

Hey Don,
This isn't what I was quite looking for but thank you for the reply. My issue is being able to pass it through user code modules.
Thanks, Charley :)

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: Passing variables from user code module to user code module

Post by doke » Wed Oct 26, 2022 1:17 pm

Hi,

In that case, did you use the ADD-button which is above the usercodemodule code to create module variables ?
    /// <summary>
    /// Description of UserCodeModule1.
    /// </summary>
    [TestModule("614685C1-AF3B-4A52-9FDC-7C61A49C0911", ModuleType.UserCode, 1)]
    public class UserCodeModule1 : ITestModule
    {
	    string _var1 = "";
	    [TestVariable("08d53ec0-41ca-4e33-b8af-83c08b0f5d74")]
	    public string var1
	    {
	    	get { return _var1; }
	    	set { _var1 = value; }
	    }
    
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public UserCodeModule1()
        {
if you use a usercodecollection you could add private/public variables there:
UserCodeCollection]
    public class MyUserCodeCollection
    {
        string _mystring = "";
        public string mytestvar
		{
			get { return _mystring; }
			set { _mystring = value; }
		}

regards,
Don

charleyrobertson
Posts: 8
Joined: Thu Sep 29, 2022 4:33 pm

Re: Passing variables from user code module to user code module

Post by charleyrobertson » Wed Oct 26, 2022 3:01 pm

Hi Don,

Yes, I have added both variables that I want to pass through to the next user code module, I have managed to figure out how to pass a singular variable between code modules. However, when you have two variables like this:
 string _previousID = "";
        [TestVariable("928f0119-31c4-4e6b-b706-e8ab9c4f9b9e")]
        public string previousID
        {
        	get { return _previousID ; }
        	set { _previousID = value; }
        }
        
        string _currentID = "";
        [TestVariable("89f3b1d3-b937-4dd9-9d64-b6bf94bef606")]
        public string currentID 
        {
        	get { return _currentID ; }
        	set { _currentID = value; }
        }
Then try to access them in the following code module, no values seem to be passed over. The variables definitely have values stored in the first user code module as I have them being logged to the console and it prints the correct values.

Thanks,
Charley

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: Passing variables from user code module to user code module

Post by doke » Wed Oct 26, 2022 6:29 pm

Hi,

make sure to bind the variables in the rxtst-file !
I updated the example solution.
Mypassvars.zip
Don
You do not have the required permissions to view the files attached to this post.

charleyrobertson
Posts: 8
Joined: Thu Sep 29, 2022 4:33 pm

Re: Passing variables from user code module to user code module

Post by charleyrobertson » Thu Oct 27, 2022 1:49 pm

Hi,

Thank you! This has worked.

Regards,
Charley