Thursday 19 April 2012

Systemutil.Run and Option Explicit in QTP

Systemutil.Run:

Systemutil is an object which is used to control application and processes a run session. Run is one of the methods of systemutil object.

SystemUtil.Run ( FileName, Parameters, Path, Operation )

FileName - The name of the file you want to run.

Parameters - If the specified FileName is an executable file, use the Parameters argument to specify any parameters to be passed to the application.

Path - The default directory of the application or file.

Operation - The action to be performed. If this argument is blank (""), the open operation is performed.

Example using all arguments except parameters:

Systemutil.Run “mann.txt” , “” , “C:\documents\mann” , “1”

Wait 2

This above example open the txt file mann which is saved in C:\documents drive and wait for 2 seconds.

Example using parameters:

Systemutil.Run “iexplore.exe” , “ http://www.gmail.com”

Above example with run .exe file and open the gmail.com browser.

SystemUtil.Run opens any kind of application window based or web based.


Option Explicit:

Option explicit we declare at the top of the script so that we can declare every variable as Dim or other data types. Sometimes we do not declare variables, in that situation it shows error if 'option explicit' is on in the script.

If we are using Option Explicit, then variable declaration in VBscript becomes compulsory/mandatory to declare. But it is not mandatory in VBscript.

If you don’t use 'Option Explicit' then no need of declaring the variables.

However, Option Explicit method is a good practice, because it is easy to find errors. If you don’t use Option Explicit and when you misspell the variable name later in your script, and that can cause strange results when your script is running.

No comments:

Post a Comment