Import settings using a command line

Ask general questions here.
jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Import settings using a command line

Post by jackrabbit » Fri Oct 30, 2015 3:05 pm

On all my VMs that I use to do run my tests, I would like to automate the settings upgrade using a command line call.

For example:

When upgrading a test, un programmer needs to add a "GDI Capture Settings" to be able to run his project. Unfortunatly, this setting is not saved as part of his project, so when my VMs run his new test automatically at night, it fails because the "GDI Capture Settings" of my VMs is not identical to the programmer's.

To upgrade my VMs, I have to manually RDP to each VM, start the Ranorex Settings program, import the new settings. Is there a way to call a command line function to upgrade the settings of a VM?

I wish those settings would follow the package, it just does not make sense that the "GDI Capture Settings" must be synchronized manually between every VM that will run the test, otherwise my test succeeds on some VMs and fails on others that run the same Ranorex test.

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

Re: Import settings using a command line

Post by Support Team » Mon Nov 02, 2015 3:02 pm

Hello jackrabbit,

Yes, the “GDI Capturing list” is not part of the Ranorex test project. This might be changed in future versions of Ranorex. For now, I would suggest adding the processes and classes to the capturing list as part of your test. This can be done by using the following code:
//To add the process name to the config  
RawTextFlavor.Instance.ProcessNames.Add(new Regex("processname pattern"));  
//To add the class name to the config  
RawTextFlavor.Instance.ClassNames.Add(new Regex("classname pattern"));
Hope this helps.

Regards,
Robert
.
Image

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Import settings using a command line

Post by jackrabbit » Mon Nov 09, 2015 10:44 pm

Regarding the rest of the global settings, is there a way to "import" them using code, to make sure I have the right configuration?

Also, is it possible to change some parameters like the "General --> The factor that all timeouts of find operations are multiplied with" using code?

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

Re: Import settings using a command line

Post by Support Team » Tue Nov 10, 2015 2:15 pm

Hello jackrabbit,

Yes, please just deploy your local RanorexConfigX.xml to your „slave“-machines. The config file resists in %appdata%. Within your Ranorex solution, simply use the following line of code in order to apply the XML file:
Configuration.Import("...\RanorexConfig5.xml");
Please note that it's not recommended to set the timeout factor within user code, but yes, it's possible:
Configuration.Current.Adapter.TimeoutFactor
Regards,
Robert
.
Image

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Import settings using a command line

Post by jackrabbit » Wed Nov 18, 2015 8:48 pm

I tried your code to dynamically add items to the GDI list:

//To add the process name to the config
RawTextFlavor.Instance.ProcessNames.Add(new Regex("processname pattern"));
//To add the class name to the config
RawTextFlavor.Instance.ClassNames.Add(new Regex("classname pattern"));

It does not even compile (I tried with version 5.3.4 and 5.4.3).
RawTextFlavor does not exists.
Instance does not have a property ProcessNames or ClassNames.
Do I need to add references, add extra code at the beginning or anything else?

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

Re: Import settings using a command line

Post by Support Team » Thu Nov 19, 2015 12:35 pm

Hello jackrabbit,

Yes, I forgot to mention that you also need to add following using:

Code: Select all

using Ranorex.Plugin;
Regards,
Robert
.
Image

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Import settings using a command line

Post by jackrabbit » Tue Nov 24, 2015 10:52 pm

I just have one small glitch with my function to dynamically add a process to the GDI list.

When I check for the REGEX in the list it always tells me it does not exists, so I could potentially add multiple instances of the same REGEX in the GDI list. Am I using the right syntax for the CONTAINS method?

Code: Select all

public void GDI_AddProcess(string ProcessRegex)
{
   if (ProcessRegex.Trim() != "") {
      Regex MyRegex = new Regex(ProcessRegex);
      if (! RawTextFlavor.Instance.ProcessNames.Contains(MyRegex)) {
         Report.Info(String.Format("Add REGEX to GDI '{0}'", ProcessRegex));
         RawTextFlavor.Instance.ProcessNames.Add(MyRegex);   
         RawTextFlavor.Instance.SaveToConfig();
         Report.Info("Total of " + RawTextFlavor.Instance.ProcessNames.Count.ToString() + " REGEX");
      }
   }
}

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

Re: Import settings using a command line

Post by Support Team » Thu Nov 26, 2015 11:49 am

Hello jackrabbit,

The Contains()-method does not compare the name of the regex. Further information can be found here:
I would suggest using the following:
public void GDI_AddProcess(string ProcessRegex)
		{
			if (ProcessRegex.Trim() != "") {
				
				Regex MyRegex = new Regex(ProcessRegex);
				
				if (!CheckIfAlreadyAdded(ProcessRegex))
				{
					Report.Info(String.Format("Add REGEX to GDI '{0}'", ProcessRegex));
					RawTextFlavor.Instance.ProcessNames.Add(MyRegex);
					RawTextFlavor.Instance.SaveToConfig();
					Report.Info("Total of " + RawTextFlavor.Instance.ProcessNames.Count.ToString() + " REGEX");
				}
			}
		}
		
		private bool CheckIfAlreadyAdded(string ProcessRegex)
		{
			foreach(Regex r in RawTextFlavor.Instance.ProcessNames)
			{
				if(r.ToString() == ProcessRegex)
				{
					return true;
				}
			}
			return false;
		}
Hope this helps.

Sincerely,
Robert
.
Image