Is there a way to schedule SilkTest Classic TestPlans?
The ability to run a smoke or regression test at a scheduled time can be a real asset to a development or IT organization. Tests can be triggered to run after a daily build is complete or after new content is pushed to a Web application each morning. With SilkTest"s test plan queries, its command line interface and a task scheduler such as NT"s "at" or the newer "Scheduled Tasks Wizard", it"s easy to do. Let"s take a closer look at each of the components.
TestPlan Attributes and Queries
SilkTest"s test planning module offers the ability to select tests based on an attribute query. Choose between one of the existing attributes (category, component, developer) or create your own. To define a new attribute, invoke the Define Attributes dialog by selecting the Main Menu->Testplan->Define Attributes menu item. In this example, a new attribute called Environment has been added. The values web1 through web5 were also added as possible values for the attribute.
The next step is to label sub-plans, sections or individual tests in your Testplan with the new Attribute values. An example might be a sub-plan that contains a Web environment smoke test. The different environments can easily be selected to run by labelling the sub-plans by Environment and then creating a Testplan query to mark them at runtime. The following is an example of how the Testplan might be labelled to select a smoke test to run in the desired environment(s):
optionset: myapp_web1.opt environment: web1 include: mysmoketest.pln optionset: myapp_web2.opt environment: web2 include: mysmoketest.pln optionset: myapp_web3.opt environment: web3 include: mysmoketest.pln
Using the Testplan query feature, a query is created to select each Web environment. To create a new query, invoke the "Mark By Query" dialog by selecting the MainMenu->Testplan->Mark By Query menu item. Select the Attribute(s) and Value(s) from the "Test Attributes Tab" and name the query for later use.
To mark the tests based on this query, invoke the "Mark By Named Query" dialog by selecting the MainMenu->Testplan->Mark By Named Query menu item. This selection provides a means of running only those tests associated with the Attribute(s) specified by the query.
The power of queries is the manner in which they can be combined. Through unions and intersections of different queries, virtually any combination of tests could be selected for runtime. For example, additional queries can be created by combining the web1 through web5 queries so that the smoke test could be run against any combination of environments.
Understanding SilkTest Command Line Options
Now that there is a Testplan labelled with Attributes and queries to select upon them, the next step is to learn how to launch SilkTest from the command line. The SilkTest help provides a syntax guide with an explanation all of the configuration options. For this example the following would be required.
partner [[-q] [-query query name [-r] scr.t/suite.s/plan.pln]
The first term in the command line string, "partner", is the name of the SilkTest executable. What follows are two switches and their arguments. The first switch, "-q" allows the user to name the query that will be used to mark tests for execution. The query name is defined by the user such as "web1" from our example above. The last switch "-r" indicates what to run. In our example case, a Testplan is to be run. The name of a script or suite file can also be specified. An example of a command line for this example follows:
partner.exe -query web1 -r smoketests.pln
This command line string can be improved by using environment variables to specify the location of the partner executable and Testplan to be run:
"%SEGUE_HOME%\partner.exe" -query web1 -r "%SCRIPTDIR%\ smoketests.pln"
This command line string will run successfully on any machine regardless of the location of the SilkTest executable or the Testplan to be run.
Scheduling Your Test Jobs
There are two ways to schedule your test jobs. If using Windows NT and have not installed Internet Explorer 5.x, your machine is probably using an executable called atsvc.exe as its task scheduler. This scheduler is also known as "at". To use at, it will be necessary to save the command line as a batch file. To do so, simply paste the command line string into a notepad file and save it with a .bat extension, e.g. mysilktestjob.bat. Then complete the following steps:
- Bring up a command prompt.
- Type: at time /interactive /every:days "%SCRIPTDIR%mysilktestjob.bat"
Where time = the time of day to schedule using a 24 clock and days = the days of the week to schedule the task using M,F,T,W,Th,F to represent the desired days. For example:
at 06:00 /interactive /every:M,F,T,W,Th,F "%SCRIPTDIR%\mysilktestjob.bat"
To check on the status of your scheduled jobs, simply type at without any arguments.
There are some security issues that may be encountered along the way because the at scheduler uses the system account to launch jobs. For example, if the test attempts to delete browser cookies, there will likely not be adequate permissions. Another limitation is that it will not be able to copy files to other machines on the network because the network does not recognise the system account on the local machine. Although Microsoft" documentation suggests that you can configure the at scheduler to use an alternate account with adequate permissions, the facility appears to be disabled.
If using Windows2000 or Windows NT and have installed Internet Explorer 5.x, the machine is probably using an executable called mstask.exe as its task scheduler. This executable provides a mechanism for using an alternate account to resolve the permissions issues described above. It also provides a handy wizard for scheduling the tasks. To schedule the test job, simply complete the following steps:
- Doubleclick MyComputer on the desktop
- Doubleclick on Scheduled Tasks
- Doubleclick on Add Scheduled Task
- Follow through the steps of the wizard:
- Select SilkTest from the list of applications
- Select Daily
- Select Weekdays unless you want the task to run on the weekend as well
- Select the desired start time of the task
- Enter the user id and password of the user to run the task as
- Check the CheckBox to invoke the Advanced Properties dialog
- Complete the Run field per this example:
"%SEGUE_HOME%\partner.exe" -query web1 -r "scriptdir location on your machine\smoketests.pln"
- Complete the Start in field as follows: % SEGUE_HOME %
The next time you get home and realize that you forgot to kick off the daily regression, consider this automatic scheduling alternative. It could save you a day on your schedule!