Thursday, September 20, 2012

DotNetFactory in QTP

*******************************************************************************************
DotNetFactory :
*******************************************************************************************

DotNetFactory is a new utility object of QTP , which enables QTP scripting to directly access methods and properties of a .NET object by creating an instance of this object.

To use DotNetFactory, you will first need to create the object instance. To create the object instance use ‘CreateInstance’ method.



Syntax : DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])


********************************************************************************************
Below is the example to create the simple userfrom using  DotNetFactory:
********************************************************************************************

function UserLoginForm()

Set objForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set objBtn1 = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set objLbl = DotNetFactory.CreateInstance("System.Windows.Forms.Label", "System.Windows.Forms")
Set objPassword = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set objLbl2 = DotNetFactory.CreateInstance("System.Windows.Forms.Label", "System.Windows.Forms")
Set objUserName = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set objRegion = DotNetFactory.CreateInstance("System.Windows.Forms.ComboBox", "System.Windows.Forms")
objForm.Left=500
objForm.Top=250
objForm.Height=275
objUserName.Top=40
objUserName.Left=100
objPassword.Top=70
objPassword.Left=100
objPassword.UseSystemPasswordChar=True
objForm.CancelButton = objBtn1
objLbl.text = "User Name"
objLbl.Top=40
objLbl.Width=80
objLbl.left=20
objLbl2.text="Password"
objLbl2.Top=70
objLbl2.Left=20
objLbl2.Width=80
objRegion.Items.add "DEV"
objRegion.Items.add "QA"
objRegion.Items.add "PROD"
objBtn1.text = "OK"
objBtn1.Top=170
objBtn1.Left=95
objBtn1.Width=120
objBtn1.Height=30
objUserName.TabIndex=1
objPassword.TabIndex=2
objRegion.TabIndex=3
objBtn1.TabIndex=4
objForm.controls.add(objLbl)
objForm.controls.add(objLbl2)
objForm.controls.add(objUserName)
objForm.controls.add(objBtn1)
objForm.controls.add(objPassword)
objForm.controls.add(objRegion)

objForm.StartPosition = CenterScreen

objForm.Text = "Regression Testing"
objForm.showDialog

Environment.Value("vUserName") =objUserName.text
Environment.Value("vPassword")=objUserName.text
Environment.Value("vRegion")=objRegion.Text

end function

Dictionary Object in QTP

Dictionary Object :

***************************************************************************************************************
Dictionary object is similar to an associative array. Every unique key presnt in the dictionary object has a corresponding value.

**************************************************************************************************************
Advantages of using the “Dictionary Object”:
***************************************************************************************************************
1) One advantage of using a dictionary object is that the values assigned to the variables can be accessed from all actions (local and external).
2) Any amount of run time values can be stored to and retrieved from the dictionary object.
3) We can use this as one of the parameterization techniques to pass values in QTP.
 4)We can return multiple values from functions

***************************************************************************************************************
Simple example is shown below to illustrate the usage of the dictionary object.
***************************************************************************************************************

 Set dictObj = CreateObject(“Scripting.Dictionary”)
 dictObj.Add “a”, 1
 msgBox dictObj(“a”)
*****************************************************************************************************************
Note : This would display the value “1” in the message box. The first 2 statements can be present in one action say Action 1. If the 3rd statement is executed from another action say Action 2, it would still work as dictionary objects are accessible from all actions.

***************************************************************************************************************
Some of the methods associated with the dictionary object are:

***************************************************************************************************************
 Items Method (object.Items( ) )
**************************************************************************************************************
        Returns an array containing all items in the dictionary object.

**************************************************************************************************************
Exists Method (object.Exists(key))
**************************************************************************************************************                  Returns true if a specified key exists in the Dictionary object, false if it does not.

**************************************************************************************************************
Keys Method (object.Keys( ))
***************************************************************************************************************
          Returns an array containing all existing keys in a Dictionary object.

**************************************************************************************************************
 Remove Method (object.Remove(key))
**************************************************************************************************************          Removes a key, item pair from a Dictionary object.

**************************************************************************************************************
 RemoveAll Mthod (object.RemoveAll))
**************************************************************************************************************
          The RemoveAll method removes all key, item pairs from a Dictionary object.
**************************************************************************************************************






Tuesday, September 4, 2012

SQL Commands

SQL Commands:


SQL commands are instructions used to communicate with the database to perform specific task that work with data. SQL commands can be used not only for searching the database but also to perform various other functions like, for example, you can create tables, add data to tables, or modify data, drop the table, set permissions for users. SQL commands are grouped into four major categories depending on their functionality:

 Data Definition Language (DDL) - These SQL commands are used for creating, modifying, and dropping the structure of database objects. The commands are CREATE, ALTER, DROP, RENAME, and TRUNCATE.

 Data Manipulation Language (DML) - These SQL commands are used for storing, retrieving, modifying, and deleting data. These commands are SELECT, INSERT, UPDATE, and DELETE.

 Transaction Control Language (TCL) - These SQL commands are used for managing changes affecting the data. These commands are COMMIT, ROLLBACK, and SAVEPOINT.

 Data Control Language (DCL) - These SQL commands are used for providing security to database objects. These commands are GRANT and REVOKE.