Thursday, March 21, 2013

Access XML>>>>>>>>>>>>>>>>>

<bookstore>
    <book>
    <title published="2001">book1</title>
    <author>author1</author>
    </book>
    <book>
    <title published="2002">book2</title>
    <author>author2</author>
    </book>
    <book>
    <title published="2003">book3</title>
    <author>author3</author>
    </book>
</bookstore>


Set ObjXML=CreateObject("Microsoft.XMLDOM")
ObjXML.Async=False
ObjXML.Load("C:\Users\SATHISH\Desktop\test01.xml")

Set ObjNodes=ObjXML.SelectNodes("bookstore/book/title[../author = 'author3']/text()")
MsgBox "Total books : "&ObjNodes.Length

For i=0 to (ObjNodes.Length-1)
    MsgBox ObjNodes(i).NodeValue

Next

Sunday, February 17, 2013

Relative Path using VBS


Dim ObjQTP
Dim ObjTest
Dim ObjResult

Set ObjQTP=CreateObject("QuickTest.Application") 'Create QTP Object
ObjQTP.Visible=True
If ObjQTP.Launched <> True Then
ObjQTP.Launch 'Launch QTP
End If

ObjQTP.Options.Run.CaptureForTestResults = "OnError" 'Tool -> Options -> Run Tab
ObjQTP.Options.Run.RunMode= "Fast"
ObjQTP.Options.Run.ViewResults = False


Set WshShell = WScript.CreateObject("WScript.Shell")
MsgBox WshShell.CurrentDirectory&"\"&"Test1"
ObjQTP.Open WshShell.CurrentDirectory&"\"&"Test1", True

Thursday, February 14, 2013

Understanding SystemUtil.Run syntax with examples


Understanding SystemUtil.Run syntax with examples


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.
Operation
Description
open
Opens the file specified by the file parameter. The file can be an executable file, a document file, or a folder. Non-executable files are open in the associated application.
edit
Launches an editor and opens the document for editing. If the file argument does not specify an editable document file, the statement fails.
explore
Explores the folder specified by the file argument.
find
Initiates a search starting from the specified folder path.
print
Prints the document file specified by the file argument. If the specified file is not a printable document file, the statement fails.
mode
Integer Value [Optional]. Specifies how the application is displayed when it opens. Default : 1
Mode
Description
0
Hides the window and activates another window.
1
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. Specify this flag when displaying the window for the first time.
2
Activates the window and displays it as a minimized window.
3
Activates the window and displays it as a maximized window.
4
Displays the window in its most recent size and position. The active window remains active.
5
Activates the window and displays it in its current size and position.
6
Minimizes the specified window and activates the next top-level window in the Z order.
7
Displays the window as a minimized window. The active window remains active.
8
Displays the window in its current state. The active window remains active.
9
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. Specify this flag when restoring a minimized window.
10
Sets the show-state based on the state of the program that started the application.
Examples : SystemUtil.Run
1. Using file argument:
1
2
3
4
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
1
2
3
'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
1
2
'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
1
2
3
4
5
6
7
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
1
2
3
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

Saturday, February 9, 2013


Environment Variables in QTP

        Environment variables are similar to Global variables to store values. Environment variables can be accessed at any place in the script and the values will be the same. Also, we can modify the values at any place and the modified values will be retrieved on further use.
Environment variables are very useful when we want to share a variable across actions in a test.
There are two types of Environment variables.
1. Built-In
2. User Defined

1. Built-In:
     There are some predefined Environment variables provided by QTP. We can use these environment variables without having assigned any values manually. Built-In environment variables contains values such as test path, OS version, Current Action,Current Action Iteration, User name etc.,

For Ex: If you want to get the path where the test is saved then you can use "TestDir" Environment variable.

How to Read environment variable from QTP Script?
Syntax: Environment.value("Variable Name")
Msgbox Environment.value("OS")

This will print the Operating System of the machine on which QTP is installed.

Below are some other Built-In Environment Varaibles:
1. Action Iteration: Indicates which action iteration is currently running. The value will be displayed or valid only during the test run.
2. Action Name: Displays or indicates which action is currently running. The current value is valid only during test run.
3. ControllerHostName: The name of the computer that serves as the controller. Used when Load runner is running. The current value is valid only during test run under Load.
4. GroupName: This is w.r.t. Load Runner. It is the scenario identification number. The current value is valid only during test run under Load.
5. LocalHostname: Gives the Local Host Name on which QTP is Installed. The current value displayed is WINDOWS XP.
6. OS: Displays the operating system on which QTP is installed. The current value os Microsoft Windows XP Work Station.
7. OS Version: Displays the version of the Operating System.
8. ProductDir: Displays the folder path where the product (QTP) is installed.
9. ProductName: Gives the name of the Product.
10. ProductVersion: Gives the product version.
11. ResultDir: Displays the folder path where the current test results are saved.
12. SceanrioId: This is w.r.t. LoadRunner. Displays the scenario identification number.
13. SystemTempDir: Displays the system temporary directory.
14. TestDir: This is the path of the folder in which the test is located.
15. TestIteration: Indicates which test iteration is currently running.
16. TestName: Displays the name of the test.
17. UpdatingActiveScreen: Indicates whether the active screen images and values are being updated.
18. UpdatingCheckPoints: Indicates whether the checkpoint properties are being updated.
19. UpdatingToDescriptions: Indicates whether test object descriptions are being updated.
20. UserName: Displays the windows login user name.
21. VUserId: This is w.r.t. Load Runner. Indicates the virtual user identification number.


2. User Defined
     These are all the environment variables defined by the user. User can store the run time values or any other own values for further access in the script.
     There are two types to User Defined Environment variables.
      a. Internal
      b. External
a. Internal:
     Internal Environment variables are the one created by the user with in the test. These variables can be used only with in the test in which it is created. Internal environment variables can be created in two ways.
   Method 1:
         1. Go to File->setting->environment tab. 
         2. Select variable type as User defined
         3. Click on “+” sign.
         4. Add name for e.g qtp
         5. Add value for e.g. http://testeverything-qtp.blogspot.com
         Click on apply and ok. 

  Method 2:
  Environment.value("<variable name>") = <Value>
  Environment.value("qtp") = "http://testeverything-qtp.blogspot.com"

These Environment variables also can be accessed as below
Msgbox Environment.value("qtp")
"http://testeverything-qtp.blogspot.com"  will be displayed in the msgbox.

b. External:
External environment variables that you pre-defined in the active external
environment variables file.These external file contains the name & value pair in XML format. You can create as many files as you want and select an appropriate file for each test. Note that external environment 
variable values are designated as read-only within the test.

To create an external environment variables file:
 1 Open any text editor.
 2 Type [Environment] on the first line.
 3 Type one variable-value pair on each line in the format—variable=value.
 4 Save the file in a location that is accessible from the QuickTest machine. The 
file must be a text file, but you can use any file name extension (usually, it will be saved in XML Format).
For example:
[Environment]
MyParam1=10
MyParam2=20
MyParam3=http://testeverything-qtp.blogspot.com

To select the active external environment-variables file:
 1 Choose Test > Settings to open the Test Settings dialog box.
 2 Click the Environment tab.
 3 Select the Load variables and values from external file (reloaded each test run) check box.
 4 Use the browse button or enter the full path of the external environment-variables file you want to use with your test.

Open QTP and Connect to Quality Center and run QC script:


Dim qtApp ' Declare the Application object variable

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True
If Not qtApp.TDConnection.IsConnected Then

' Make changes in a test on Quality Center with version control
qtApp.TDConnection.Connect "QC URL","DOMAIN Name","Project Name","User Name","Password",False

'QC URL = QC Server path
'DOMAIN Name = Domain name that contains QC project
'Project Name =Project Name in QC you want to connect to
'Username = Username to connect to Project
'Password = Password to connect to project
'False or True = Whether ‘password is entered in encrypted or normal. 
'Value is True for encrypted and FALSE for normal

'Example : qtApp.TDConnection.Connect
'"http://200.168.1.1:8080/qcbin","Default","proj1","qtpworld","qtp",false

End If

'Make Sure about your script path  and script name in QC
qtApp.Open "[QualityCenter] Subject\QCScriptPath\ScriptName", False
qtApp.Test.Run
qtApp.TDConnection.Disconnect

'Close QTP
qtApp.quit

'Release Object
Set qtApp = Nothing

4 Different Ways to Associate Function Libraries to your QTP Scripts

1. Using AOM (Automation Object Model)
QTP AOM is a mechanism using which you can control various QTP operations using another application. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.

'Open a test and associate a function library to the test
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries
'If the library is not already associated with the test case, associate it..
If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added
objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case
End

2. Using ExecuteFile Method

ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.

'Action begins
ExecuteFile "C:\YourFunctionLibrary.vbs"
'Other logic for your action would come here
'.....

3. Using LoadFunctionLibrary Method

LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.

'Some code from the action
'.....
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs", "C:\YourFunctionLibrary_2.vbs"
'Other logic for your action would come here
'.....


4. Using ‘File > Settings > Resources > Associate Function Library’ option from the Menu bar

This is one of the most common methods used to associate a function library to a test case. To use this method, select File > Settings option from the Menu bar. This will display the ‘Test Settings’ window. Click on Resources from the left hand side pane. From the right hand side pane, click on the ‘+’ button and select the function library that needs to be associated with the test case.
LoadAndRunAction Call one test from another test >>>>>>>>



LoadAndRunAction test_path, action_in_test