SystemUtil.Run is an inbuilt QTP command that lets you run a file or an application. Mostly SystemUtil.Run command is used to open browser with a specific URL. But there is much more that can be done with it. Here in this article, you’ll see various examples on how to use SystemUtil.Run for different purposes. Let’s first go through the syntax of SystemUtil.Run method –
SystemUtil.Run file, [params], [dir], [op], [mode]
Argument | Description | ||||||||||||||||||||||||
file | String Value [Mandatory]. The name of the file you want to run. | ||||||||||||||||||||||||
params | String Value [Optional]. If the specified file argument is an executable file, use the params argument to specify any parameters to be passed to the application. | ||||||||||||||||||||||||
dir | String Value [Optional]. The default directory of the application or file. | ||||||||||||||||||||||||
op | String Value [Optional]. The action to be performed – open, edit, explore, find & print.If this argument is blank (“”), the open operation is performed.
|
||||||||||||||||||||||||
mode | Integer Value [Optional]. Specifies how the application is displayed when it opens. Default : 1
|
Examples : SystemUtil.Run
1. Using file argument:
SystemUtil.Run "iexplore.exe" 'opens internet explorer with default page SystemUtil.Run "notepad.exe" 'opens blank notepad window SystemUtil.Run "notepad" 'opens blank notepad window SystemUtil.Run "D:\AutomationRepository.txt" 'since this is a non executable file, the file opens in the associated application i.e. notepad in this case
2. Using params argument
'If 'file' argument is an executable file, then 'params' can be used to specify the arguments to the application SystemUtil.Run "iexplore.exe", "http://www.automationrepository.com" 'opens Automation Repository in Internet Explorer browser SystemUtil.Run "notepad.exe", "D:\SomeTextFile.txt" 'opens the text file in notepad
3. Using dir argument
'dir argument can be used to specify the default location of the application SystemUtil.Run "iexplore.exe", "", "C:\Program Files\Internet Explorer\"
4. Using op argument
SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "open" 'open a file SystemUtil.Run "D:\AutomationRepository.txt", "", "", "edit" 'open file in edit mode 'Explore the folder specified by 'file' argument. Refer figure-1 SystemUtil.Run "My Computer", "", "", "explore" 'Initiate a search starting from the specified folder path. Refer figure-2 SystemUtil.Run "D:\", "", "", "find" SystemUtil.Run "D:\AutomationRepository.txt", "", "", "print" 'prints a document specified by 'file' argument
5.Using mode argument
SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "", 0 'the file is opened in hidden mode SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "", 1 'activates and displays the window SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "", 2 'opens the window in minimized state
If you liked this article, you can join our blog to get free email updates directly in your inbox.