How to know script is getting executed byscheduled task

Ranorex Studio, Spy, Recorder, and Driver.
bheemuabhigna
Posts: 49
Joined: Thu Feb 03, 2011 3:15 pm

How to know script is getting executed byscheduled task

Post by bheemuabhigna » Mon Feb 14, 2011 7:46 am

Hi,

We have scheduled our code to get executed daily at particular time.
The scheduled task daily executes the script i.e., at given it is double clicking the exe file.

The problem is the test data will be taken from database and our client want the scheduled task to execute only particular set of test cases and that too without updating the database.

Is it possible to know whether the script got initiated due to scheduled task. If so I can keep a if conditions and if yes it takes data from excel and if not it takes data from database.

Thanks
Abhigna

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: How to know script is getting executed byscheduled task

Post by artur_gadomski » Mon Feb 14, 2011 7:58 am

I don't know if there is a way to tell if script is executed from scheduler, but you could add a command line parameter say '-database' to you test so that when present will make data come from database. Then you add this parameter into a scheduled run and you can still run the tests without parameters taking data from excel.

bheemuabhigna
Posts: 49
Joined: Thu Feb 03, 2011 3:15 pm

Re: How to know script is getting executed byscheduled task

Post by bheemuabhigna » Mon Feb 14, 2011 8:45 am

Hi Arthur,
Thanks for response.
I want scheduler to take data from excel only and manual execution will take data from database and how can we add only a single parameter to scheduled task.
Can be more specific on your reply "Then you add this parameter into a scheduled run and you can still run the tests without parameters taking data from excel."

Thanks
Abhigna

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: How to know script is getting executed byscheduled task

Post by artur_gadomski » Mon Feb 14, 2011 11:30 am

You can write a code that checks the parameters like so:
static void Main(string[] args)
        {
            bool takeParametersFromExcel = false;
            foreach (string parameter in args)
            {
                if (parameter.Equals("-excel"))
                {
                    takeParametersFromExcel = true;
                }
            }
            if (takeParametersFromExcel)
            {
                // Code taking parameters from excel
            }
            else
            {
                // Code taking parameters from database
            }
}
Then when you're scheduling a task you have an option to specify parameters (On Edit Action dialog -> Add arguments (optional)). So you just say:
Program: c:\Mytest.exe
Add arguments (optional): -excel

When you run it manually you just say MyTest.exe without any command line arguments (making it default way to run your tests).

bheemuabhigna
Posts: 49
Joined: Thu Feb 03, 2011 3:15 pm

Re: How to know script is getting executed byscheduled task

Post by bheemuabhigna » Tue Feb 15, 2011 10:59 am

Hi Artur,

Thanks for the solution.
It really helped me out in solving the issue. The code works fine now

Thanks
Abhigna