Use of constructor arguments

Ranorex Spy, Recorder, and Studio.
montb
Posts: 3
Joined: Tue Nov 06, 2018 11:46 am

Use of constructor arguments

Post by montb » Tue Nov 06, 2018 12:03 pm

Hi everyone,

I am new to Ranorex and have been testing some scenarios. I am using Ranorex 8.3
I have a question if it is possible to pass constructor arguments to a TestModule (CodeModule)?

Like this

Code: Select all

public class Test : ITestModule
{
	private MyOtherClass other;
	public Test(MyOhterClass other) 
	{
		this.other = other;
	}
}
Regards
Thomas

User avatar
RobinHood42
Posts: 239
Joined: Fri Jan 09, 2015 3:24 pm

Re: Use of constructor arguments

Post by RobinHood42 » Wed Nov 07, 2018 9:56 am

Hi,

I guess you read the following auto-generated comment? :D
   public UserCodeModule1()
        {
            // Do not delete - a parameterless constructor is required!
        }
Maybe you could explain your requirement/test scenario in more detail.

Cheers,
Robin :mrgreen:

montb
Posts: 3
Joined: Tue Nov 06, 2018 11:46 am

Re: Use of constructor arguments

Post by montb » Wed Nov 07, 2018 11:29 am

Hi Robin,

Thanx for your reply.

Yes I have read that comment, the reason is that I would like pass a database helper class to my test modules. I use it for some performance tests that is logged in an SQL Server database. I use a static class for this purpose right now, that I would like to get rid of :)

Regards
Thomas

User avatar
RobinHood42
Posts: 239
Joined: Fri Jan 09, 2015 3:24 pm

Re: Use of constructor arguments

Post by RobinHood42 » Thu Nov 08, 2018 10:35 am

Hi,

I'm afraid that it is not possible to pass the object to your UserCode instance. How do you actually call your UserCodeModule? I would simply create a setter method, which allows you to pass your custom class object to the UserCodeModule.

Cheers,
Robin

montb
Posts: 3
Joined: Tue Nov 06, 2018 11:46 am

Re: Use of constructor arguments

Post by montb » Fri Nov 09, 2018 8:12 am

Hi Robin,

Thanx for your answer.
The UserCodeModules are called by the Ranorex framework, I never call them in my own code. I use them in my test suite.

Regards
Thomas