There are three major articles KB articles on Automating LR:

1. Command line arguments for the LoadRunner Controller – Previously Mercury KB 13352
2. How to execute Analysis with a .lrr or .lra file from DOS - Previously Mercury KB 9241
3. How to create an HTML report without user intervention using Analysis - Previously Mercury KB 38562

4. There is also an API by which you can set some of the Runtime settings, but not launch tests. 

1. Command line arguments for the LoadRunner Controller

The basic syntax is:

     Wlrun.exe –TestPath C:\Temp\Scenario1.lrs –ResultLocation C:\Temp –ResultCleanName Res1 –Run

Note:
1. Make sure that the Controller is shut down before starting the scheduled task.
2. When running the Controller via the Command Line, Controller will be shut down automatically after the scenario ends.

Command line parameters are parameters that the Controller receives when it is invoked. They are used to instruct the Controller on how to behave. When invoked, the Controller checks all the received parameters and sets its startup environment accordingly. If no parameters are passed, the Controller uses its default settings.

By passing parameters in the command line, you may set the Controller and the scenario’s settings without the need to manually define them in the Controller UI. For example, you can instruct the Controller whether to connect to TestDirector on startup by using the ConnectToTD parameter, save the results to a directory other than that defined in the scenario by using the ResultName parameter, or invoke Analysis upon scenario termination with the InvokeAnalysis parameter.

The most common use of the Command Line is done by TestDirector. TestDirector includes a special program called "Test Run Scheduler," which was designed for scheduling the Controller to run scenarios at a specific date and time. It automatically invokes the Controller and runs scenarios. Results are saved in the TestDirector database. To do that, TestDirector must set the scenario’s environment by supplying the Controller with specific parameters.

Predefined rules:

  • When one or more parameters are not passed, the Controller uses its default settings.
  • Results will always be overwritten.
  • The Controller will automatically terminate upon scenario termination and the results will be then collated.
  • The Controller’s settings are loaded from wlrun5.ini located in the Windows directory.
  • The following parameters are supported on all Windows 9x and Windows NT platforms.

Switches for LoadRunner/TestDirector integration:

  • ConnectToTD - Should the Controller connect to TestDirector on startup (0/1 or ON/OFF).
  • TDServer - TestDirector server name. Must be a computer name with TestDirector installed.
  • TDDB - Database name. For example, "lrun."
  • UserName - User name.
  • Password - Password for the user name.
  • TestPath - Path to scenario in the TestDirector database. For example, "[TD]\Subject\LoadRunner\Scenario1." If the path includes white spaces, use quotation marks.
  • TestId – Test ID (for TestDirector only).
  • ResultCleanName - For use with ResultCycle only, for example, "Res1."
  • ResultCycle - TestDirector cycle, for example, "LR_60_SP1_247." To define the results path in TestDirector, the Controller must be provided with two parameters: ResultCycle and ResultCleanName.

Run-Time Switches:

  • Run – Runs scenario, dumps all output messages into res_dir\output.txt and closes the Controller.
  • InvokeAnalysis - InvokeAnalysis will set a flag in the Controller, which will invoke Analysis upon scenario termination (If not used, the scenario value will be taken).

Results Switches (for File System):

  • ResultName - Full results path, for example, "C:\Temp\Res_01."
  • ResultCleanName - Results name, for example, "Res_01."
  • ResultLocation - Results directory. For example, "C:\Temp".
  • Note:
    • If the scenario does not specify a results directory and one of the above parameters was not passed, the scenario will not run!
    • The results will always be automatically collated upon scenario termination.
    • The results will always be automatically overwritten.

Command Line Syntax examples:

·  Wlrun.exe –TestPath C:\Temp\Scenario1.lrs -ResultName C:\Temp\Res1 –Run –InvokeAnalysis

·  Wlrun.exe –TestPath C:\Temp\Scenario1.lrs –ResultLocation C:\Temp –ResultCleanName Res1 –Run

·  Wlrun.exe –ConnectToTD on –TDServer localhost –TDDB lrun –UserName yaniv18 –Passwordb#12GcSA –TestPath "[TD]\Subject\Trash for LR/TD Integration\Scenario1" –Run

·  Wlrun.exe –ConnectToTD 1 –TestPath "[TD]\Subject\Trash for LR/TD Integration\Scenario1"


Related articles that may be of interests:
Problem ID 2782   - How to run a scenario at a specific (absolute) time
Problem ID 15717 - Wlrun.exe does not close when executing a scenario via command line option
Problem ID 9277   - How can we read in string/text content from command line in controller and use them in a script
Problem ID 22476 - Running LR from Command line does not collate results from remote machine
Problem ID 3894   - How to pass command line arguments to a WinRunner script
Problem ID 45309- How to execute a VuGen script from DOS
Problem ID 9241- How to execute Analysis with a .lrr or .lra file from DOS

Attachment : CPT13351.zip

 ----------------------------------------------------------------------------

You can also run Vugen from DOS

How to execute a VuGen script from DOS (previously http://kb-web.mercury.com/KBA/KBAview.asp?Conceptid=45309&Product=LR)

Solution: Executing a VuGen script from the command line

Here is the command line that you need to execute to run a VuGen script from the command prompt:

   <LoadRunner>\bin\mmdrv.exe -usr <path to usr file>

Note:
In order to get all the other options that go with the command, run mmdrv.exe from the command prompt without any options.

 --------------------------------------------------------------------------
Setting the Granularity Programatically

http://kb-web.mercury.com/KBA/KBAview.asp?Conceptid=11762&Product=LR

Problem Description: Can the default granularity for new graphs be set?

Is there a way to set the Analysis Tool to open new graphs with a custom granularity? For example, LoadRunner may open all graphs with the granularity set to 300 seconds. Is there away to set it to 10 seconds?

Solution: Create a user-defined template for the Analysis tool.

There is no way to set the same granularity to all graphs in Analysis once the result set has been processed. However as a work-around, create and use a user-defined template.

1. Open a result set in Analysis.
2. Open up all sets of graphs.
3. In each graph, set the granularity you want (i.e., 10 seconds).
4. Choose Tools -> Templates -> Save as template.
5. Clear the "Use automatic granularity" checkbox.
6. Select the "Automatically set to new result" checkbox.

As a result, each new result set will be opened with the above graphs and granularity desired, with the exception of the Throughput graph. For the Throughput graph, the minimum granularity is 5 seconds by the product design. The reason for it is to avoid too much overhead. If you would like to set it to a lower value (not recommended due to overhead), here's what you can do (before you run your scenario):

Note:
Please back up your files before any modification.

1. Open the default.cfg file of the script using a word editor. In the [WEB] section add one more line:

[WEB]
WebGraphsAggregation=n

where n is the number of seconds for graph aggregation.

2. Open throughput.def in the <LoadRunner>bin\dat directory using a word editor. In the [Granularity] section, comment out "BaseGranularityUIName" by putting a semicolon at the beginning of the line:

Example:
[Granularity]
Dimension=Scenario Elapsed Time
;BaseGranularityUIName=Throughput

3 Open Result0_Graph2.def in <LoadRunner>\AnalysisTemplates\DefaultTemplate1 using a word editor. In the [Granularity] section, comment out "BaseGranularityUIName" by putting a semicolon at the beginning of the line:

Example:
[Granularity]
Dimension=Scenario Elapsed Time
;BaseGranularityUIName=Throughput

4. Save the changes and rerun your scenario.

 ----------------------------------------------------------------------------

2. : How to execute Analysis with a .lrr or .lra file from DOS

http://kb-web.mercury.com/KBA/KBAview.asp?Conceptid=9241&Product=LR

How to execute the Analysis from command line with a .lra or .lrr file as a parameter.

Solution: Executing Analysis from the command line

Here is the command line that you need to execute to run Analysis from the command prompt:

<LoadRunner>\bin\analysisui.exe -RESULTPATH <path to lrr/.lra file>
You can as use the flag –TEMPLATENAME templatename to specify the template you want to use.

NOTE: templatename should only contain the name of the template to be used. The full path is hard coded in a configuration file.

  ----------------------------------------------------------------------------

3. Problem Description: How to create an HTML report without user intervention using Analysis

 Solution: Use an Analysis template

http://kb-web.mercury.com/KBA/KBAview.asp?Conceptid=38562&Product=LR 

a. Open an Analysis session with all the graphs that you are interested in and save this as a template. When saving this template, make sure that the option "Automatically apply this template to a new session" is checked. Also select the option "Generate the following Automatic HTML Report" and specify the location for where you want to save your reports.

Note:
Make sure that there are no folders with the name Report and no files called Report.html at that location.

b. Close Analysis and invoke it through the command line in a new lrr file using the direction from Problem ID 9241 - How to execute Analysis with a .lrr or .lra file from DOS.


c. This will first analyse the result and create a session file. Then, Analysis will apply the template and create an HTML report at the location selected in the template.

 ----------------------------------------------------------------------------

4. The Mercury Controller API

http://kb-web.mercury.com/KBA/KBAview.asp?Conceptid=15334&Product=LR 

Solution: LoadRunner Automation libraries / Controller's API

To find out more about Controller API/Automation Library

1. Bring up VuGen
2. Go to Help -> Contents and Index
3. Expand Books Online
4. Refer to LoadRunner Automation References

______________________________________________

Problem Description: How to set the Run-Time Settings programmatically instead of using the Run-Time Settings dialog box

Is it possible to programmatically set the Run-Time Settings through VuGen scripts instead of using the Run-Time Settings dialog box?

Solution: The Run-Time Settings can be set using the LoadRunner API  

http://kb-web.mercury.com/KBA/KBAview.asp?Conceptid=37690&Product=LR 

Generic functions:


lr_set_debug_message

Run-Time Settings -> Log

lr_think_time

Run-Time Settings -> Think time

lr_continue_on_error

Run-Time Settings -> Miscellaneous -> Error handling -> Continue on error

Web Vuser:


web_set_timeout

Run-Time Settings -> Preferences -> Option -> Connect/Receive/Step Download timeout

web_enable_keep_alive

Run-Time Settings -> Preferences -> Option -> Keep-Alive HTTP connection

web_set_max_retries

Run-Time Settings -> Miscellaneous -> Error handling -> Run-Time Settings -> Preferences -> Option -> Max number of <META refresh> to the same page

Citrix Vuser:


ctrx_set_waiting_time

Run-Time Settings -> Timing -> Connect timeout

Some additional Run-Time Settings:


lr_abort

Aborts Vuser script execution.

lr_disable_ip_spoofing

Disables IP Spoofing.

lr_enable_ip_spoofing

Enables IP Spoofing.

lr_exit

Exits from the script, action, or iteration.

lr_rendezvous

Sets a rendezvous point in a Vuser script.

lr_rendezvous_ex

Sets a rendezvous point in a Vuser script.

Refer to the Function Reference for details about all these functions.   

Automating LoadRunner