Page 1 of 1

Import settings using a command line

Posted: Fri Oct 30, 2015 3:05 pm
by jackrabbit
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.

Re: Import settings using a command line

Posted: Mon Nov 02, 2015 3:02 pm
by Support Team
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

Re: Import settings using a command line

Posted: Mon Nov 09, 2015 10:44 pm
by jackrabbit
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?

Re: Import settings using a command line

Posted: Tue Nov 10, 2015 2:15 pm
by Support Team
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

Re: Import settings using a command line

Posted: Wed Nov 18, 2015 8:48 pm
by jackrabbit
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?

Re: Import settings using a command line

Posted: Thu Nov 19, 2015 12:35 pm
by Support Team
Hello jackrabbit,

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

Code: Select all

using Ranorex.Plugin;
Regards,
Robert

Re: Import settings using a command line

Posted: Tue Nov 24, 2015 10:52 pm
by jackrabbit
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");
      }
   }
}

Re: Import settings using a command line

Posted: Thu Nov 26, 2015 11:49 am
by Support Team
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