Spread the love

SystemUtil.Run method in UFT Learn Here for Free

Spread the love

Be watchful while utilizing SystemUtil.Run technique

Do you know SystemUtil.Run method in UFT? If your answer is no, Please stick to the post to know more about “Be careful while using SystemUtil.Run” while opening your application.

Methods to Open an Application in QTP or VB Script

A lot of times we the automation test engineers need to face this situation that we need to open an application through our script. It is a sophisticated approach to open the application during run time. This is also a very important concept while building a complex framework. This one of the major challenges in Test solution design.

This post talks about different methods to launch our application :

SystemUtil.Run

Syntax:

SystemUtil.Run ( the file to open, arguments, path, operation )

Argument Details:

the file to open – the target file to open
Parameters – Predetermined File Name (may a .exe file), this is used in case the application takes any.
path- The catalogue of the files or application.
Operations – The activities can be done.

Here is a list of operations that can be done:

OperationDescription
OpenThis command is responsible for opening the executable or non-executable file/application or something. It is the default.
editThis command is responsible for opening the executable or non-executable file/application or something in the default editor.
exploreThis command is responsible for exploring the file folder
findThis command is responsible for starting a file search operation of the windows
printThis command is responsible for printing a file

code:


SystemUtil.Run "E:My DocumentTest.txt","","E:My DocumentDetails","open"

We can create variables to pass this information as well. Also, check out here for common issues with SystemUtil.Run method.

InvokeApplication

This command is used with the older versions of QTP to support backward compatibility. This is a great alternative to SystemUtil.Run method in UFT.

Syntax:

InvokeApplication(“Full path of the app”,”full URL of the target”).
While the first argument is mandatory, the second argument is optional.

Example:


InvokeApplication "E:Program FilesInternet ExplorerIEXPLORE.EXE google.com" 

shell object  or VBscript way to invoke applications:

Once shell object is created we can utilize the run method in order to launch the exe or application. we need to further utilize Chr(34) in case we have space in the path. finally, release the memory held by the object.

READ  Learn Dictionary Object in UFT or QTP Quickly

This is a great alternative to SystemUtil.Run method in UFT.
Example:


Dim oMyShell
oMyShell=CreateObject("WScript.shell")
//Create a "WScript.shell" object.
oMyShell.run "notepad.exe"

4.Manual Process:

Physically enter the lines to enter the data to run the application, and click on the “OK” button. This is a great alternative to SystemUtil.Run method in UFT.
Code:


Dialog("Run").WinEdit("Open:").Type "C:Windowsnotepad.exe"
Dialog("Run").WinButton("OK").Click

This post also talks about how to open a URL. For projects, Tester, by and large, use SystemUtil – an inbuilt object of QTP/UFT-to dispatch the application. The miserable piece of this strategy is that it can not separate among explorers and iexplorer. Accordingly, we, by and large, get the beneath composed Error tossed from QTP/UFT.

READ  How To Bypass SSO in Automation Testing?

“Can’t recognize the article parent. Ensure that… … ”

I kept an eye on the program bar uncovered that it was being perceived as a window rather than the program! Some more R and D and It was found that the issue lies with the SystemUtil.Run strategy. I was utilizing

SystemUtil.Run “explorer” URL When I changed that to

SystemUtil.Run “iexplore”, [url] content began running fine. I surmise while utilizing wayfarer, QTP/UFT anticipates a record way and not an HTTP way on it. To dispatch an application, I figure a superior option is to make a shell item and dispatch applications utilizing its Run strategy. It will take around 4 lines of code. (counting revelation and decimation of shell object)

It is prescribed that as opposed to utilizing System. Util .or run technique. It is smarter to utilize the “cmd” that is the order arrange (straightforward dos)Type way through QTP/UFT and run the document u want. This is the most solid methodology.

90% of the time SystemUtil.Run command works fine. 10% of the time, UFT throws “Can not identify the parent…” error.

The Issue

SystemUtil.Run method tends to identify the browser like window.

Quick Fix to this issue

The Syntax for SystemUtil.Run is SystemUtil.Run “explorer”, <URL> instead of “explorer” if we use <iexplorer>, the script runs fine. But this is not a proper solution on which we can depend during DevOps or unmonitored execution. This is a great way to solve the issues of SystemUtil.Run method in UFT.

SystemUtil.Run is an inbuilt UFT method /command that allows users to open some applications (including some URLs).

The Syntax of SystemUtil.Run –

SystemUtil.Run file,[parameter],[dir],[operations],[mode]

Where

  • the file is a mandatory argument. It represents a file or an application to run. It can be a shortcut or a soft link that points an application.
  • The parameter argument is optional. It is only required if the application (.EXE) needs some values while startup.
  • the dir is also another optional argument. It indicates the default directory of the application.
  • Operations are also optional. It signifies the operations like- Open- default operation. If the operation’s argument passed as blank, Open gets executed. In case our target application is a nonexecutable link a file, a folder, then it will be opened in a new window. Other operations are Explore- that opens the folder in the explorer view of the file specified. Find- that starts a search operation. It starts from the  specified folder path, print- it starts printing the file specified
  • Mode- It takes an integer value. Depending on the integer value, it opens in that mode.
READ  Regular Expressions in VBScript or QTP or UFT

StackOverflow has several discussion on this:

ValueMeaning
Hides the current window and activates the other window.
1It is the default value. It activates and brings to the front for display. (Even if it is minimized or maximized).
After restoring to its original size and position. It is used when we use the window the first time.
2Activates the window and brings it to the front as a minimized one.
3Activates the window and brings it to the front as a maximized one.
4Most recent size and position display the window, The currently activated window remains activated.
5Activates the window and displays it in its current size and position.
6It minimizes the specified window but activates the next top-level window in the Z-order.
7It displays the window as a minimized window. The currently active window remains active.
8This value displays the window in its current date. The currently active window remains active.
9This value activates and displays the window from any other state. If it is minimized or maximized, the system restores it to its original size and position. It is used when restoring a minimized window.
10Sets the show state based on the state of the program that started the application.
READ  How To Convert JSON File To XML format In UFT in VBScript way

Use of a SystemUtil.Run

SystemUtil.Run "explorer.exe" //opens explorer
SystemUtil.Run "iexplorer.exe" // Opens internet explorer with default page
SystemUtil.Run "notepad" // this is a softlink pointing to notepad.exe
SystemUtil.Run "Notepad.exe" //this opens a blank notepad

Use of a SystemUtil.Run with Parameter

SystemUtil.Run "iexplorer.exe","https://www.techtravelhub.com/" // Opens internet
// explorer with https://www.techtravelhub.com/
SystemUtil.Run "Notepad.exe" ,"c:\Mytest.txt"//this opens Mytest.txt in  notepad

Use of a SystemUtil.Run with dir argument

SystemUtil.Run "iexplorer.exe","","C:\Program Files/Internet Explorer/"
SystemUtil.Run "Notepad.exe","","C:\windows/System32"

Use of a SystemUtil.Run with operation argument

SystemUtil.Run "C:\MyTest.txt","","","Edit" //opens the file in Edit mode, alternatively you can use Open and Print

Use of a SystemUtil.Run with a mode argument

SystemUtil.Run "notepad.exe","C:\MyTest.txt","","",0
//opens the notepad in hidden mode, we can use the mode as per the above chart.

What is the Best Way to Invoke Applications in UFT/QTP?

VBscript to summon application. Make a “WScript.shell” object. Utilize the “run” method to dispatch the application. If the way to your executable contains spaces, use Chr(34) to guarantee the way is contained inside a double quote. Whenever done, set the shell item to nothing to discharge it.

READ  How to Delete Cookie in VBScript?

WSH enables us to execute any windows command or command-line utility using the WSHShell’s Run() method.

Syntax:

WSHShell.Run(Command),[windowStyle],[waitState]

Where Command- the actual command or command-line utility that needs to be executed.

WindowStyle is an optional parameter that controls the visual appearance of the window.

ValueMeaning
Hides and deactivates the window
1It is the default value. It activates and brings to the front for display. (Even if it is minimized or maximized).
After restoring to its original size and position. It is used when we use the window the first time.
2Activates the window and brings it to the front as a minimized one.
3Activates the window and brings it to the front as a maximized one.
4Most recent size and position display the window, The currently activated window remains activated.
5Activates the window and displays it in its current size and position.
6It minimizes the specified window but activates the next top-level window in the Z-order.
7It displays the window as a minimized window. The currently active window remains active.
8It displays the window in its current date. The currently active window remains active.
9Activates and displays the window. If it is minimized or maximized, the system restores it to its original size and position. It is used when restoring a minimized window.
10Sets the show state based on the state of the program that started the application.

WaitState- is another optional argument that takes the boolean parameter to specify if the script will wait on the command or command-line utility to finish executing before continuing to run. If we set waitState as True, it will pause script execution.

READ  Learn Dictionary Object in UFT or QTP Quickly

When we run WSHScript manually, it uses local security privileges and permission. But when the task scheduler executes some script, it uses super level privileges.


Model:
Dimi oMyShell
Set oMyShell= CreateObject ("Wscript.shell")
'Model 1 - run a group record:
oMyShell.run "<<pathof the bat file>>.bat"
'Model 2 - run a Java container document(jar):
oMyShell.run "java - jar <<path of jar>>.jar"
'Model 3 - dispatch Internet Explorer:
oMyShell.Run Chr(34) and "C://Program Files/Internet Explorer/IEXPLORE.EXE" and Chr(34)
'Model 4 - dispatch Firefox:
oMyShell.Run Chr(34) and "C://Program Files/Firefox/Firefox.exe" and Chr(34)
'Model 4 - dispatch Notepad:
oMyShell.Run Chr(34) and "<<path of notepad>>Notepad.exe" and Chr(34)
Set oMyShell= Nothing
 

Read also here for 6 different types of invoking methods.

There is another method in UFT which supports opening an application is InvokeApplication.

InvokeApplication "C:\Program Files\Internet Explorer\IEXPLORER.EXE","https://www.techtravelhub.com/"

 

This is very important for the framework developer to make a generic function to open an application.

Other references:




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn File System Object(FSO) in UFT or QTP or VBScript Free

This post will cover the File System Object(FSO) in UFT. File...

Comments

  1. You gave the code for running it from 'cmd' as

    Dim oShell
    Set oShell = CreateObject ("WSCript.shell")
    oShell.run "cmd /K CD C: & Dir"
    Set oShell = Nothing

    Is that the one?? Please let me know.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Learn Quickly About DevOps Tools in a Fast and Efficient Manner

Introduction to DevOps tools DevOps tools are a collection of...

How to Collaborate between Development and Operations Team Fast and Effectively

Collaborate between Development and Operations Teams are the key...

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis...

EDITOR PICKS


Spread the love