Ad
Ad
Ad
Spread the love
  • 11
  • 12
  • 24
  • 11
  •  
  •  
  •  
  •  
  •  
  •  
    58
    Shares

Be watchful while utilizing SystemUtil.Run technique

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.

“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 has a tendency 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.

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.
ValueMeaning
0Hides 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.
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.

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. In the event that 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.

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
0Hides 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.

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.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 11
  • 12
  • 24
  • 11
  •  
  •  
  •  
  •  
  •  
  •  
    58
    Shares

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 [email protected]

2 Comments

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

    can be used..

  2. 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.

Write A Comment