Page 1 of 1

How to pass Data Source name via command line

Posted: Thu Jan 26, 2017 4:41 am
by faik.faisal
Hello,
Currently in our project, We are planning on keeping the expected value in Excel DataSource. My expected data changes when we run our application in English or French (due to language), however the test steps remains the same.

Therefore I was wondering if I could execute my tests from command line by specifying which data source to look. For example, expected_smoke_en.xlsx for english and expected_smoke_fr.xlsx for french.

Feel free to suggest me any alternative approach.

Re: How to pass Data Source name via command line

Posted: Thu Jan 26, 2017 9:07 am
by Martin
I believe you could do this with run configuration parameter.
http://www.ranorex.com/support/user-gui ... html#c3019

Basically just have 1 test step that initializes english and another one which initializes french and link them to different run configurations. You can specify which run configuration to use with command line argument.

Also another possibility would be to use a custom command line argument.
For this you need to go modify Program.cs file a bit:

If normal program.cs file would look like this:
namespace Regression
{
    class Program
    {
        [STAThread]
        public static int Main(string[] args)
        {
            // Uncomment the following 2 lines if you want to automate Windows apps
            // by starting the test executable directly
            //if (Util.IsRestartRequiredForWinAppAccess)
            //    return Util.RestartWithUiAccess();

            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
            int error = 0;

            try
            {
                error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
            }
            catch (Exception e)
            {
                Report.Error("Unexpected exception occurred: " + e.ToString());
                error = -1;
            }
            return error;
        }
    }
}
Then the modified one with additional parameter would look like as followed:
namespace Regression
{
	static class Parameters
	{
		public static string _env = "QUA";
	}
	
    class Program
    {
        [STAThread]        
        public static int Main(string[] args)
        {
            // Uncomment the following 2 lines if you want to automate Windows apps
            // by starting the test executable directly
            //if (Util.IsRestartRequiredForWinAppAccess)
            //    return Util.RestartWithUiAccess();

            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
            int error = 0;
            
            //Set default environment for Tests (When parameter is not inserted on launch)
            string env = "QUA";

            for (int i = 0; i < args.Length-1; i++)
            {
            	if (args == "/env")
            		env = args[i+1];
            }
            
            Parameters._env = env;

            try
            {
                error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
            }
            catch (Exception e)
            {
                Report.Error("Unexpected exception occurred: " + e.ToString());
                error = -1;
            }
            return error;        
    	}        
    }  
}


So my example shows that it is accepting a command line argument called "/env" which when given will set the value for the static class which i can access from anywhere. So just replace with what needed and get the value (in your case e.g /lan, set value to either english or french and act accordingly after getting the value). So you would only need 1 code module to handle the excel connections.

Re: How to pass Data Source name via command line

Posted: Thu Jan 26, 2017 4:16 pm
by faik.faisal
I like both of your ideas.

Going with the first one. I will update the post once I implemented it.

Thank you so much!!!