Showing posts with label QTP.. Show all posts
Showing posts with label QTP.. Show all posts

Tuesday, January 5, 2010

Working with Hashtable using QTP DOT Net Factory

Hashtable is similar to a Dictionary object. It stores values in key-item pairs. Hashtable can be implemented in QTP using DOT Net factory with .net framework mscorlib assembly.

The below line creates an instance of the Hashtable.

Set oHash=DotNetFactory.CreateInstance("System.Collections.Hashtable","mscorlib")

Now we are ready to work with Hashtable methods and properties in QTP.


Adding an element:
Syntax: Object.Add key, value

Example:
Set oHash=DotNetFactory.CreateInstance("System.Collections.Hashtable","mscorlib")
oHash.Add 1,"QTP"


Removing all elements:
Syntax: Object.Clear
Example: oHash.Clear
'This line clears all the elements in the Hashtable object

Counting Property:
The count property returns number of items in the hastable.
Msgbox oHash.Count


For more information about Hashtable, please navigate the below links,
http://msdn.microsoft.com/en-us/library/4yh14awz(VS.80).aspx
http://en.wikipedia.org/wiki/Hash_table
http://www.itl.nist.gov/div897/sqg/dads/HTML/hashtab.html

Thursday, December 31, 2009

Browser Control in QTP using DOT Net Factory

Create browser control instance in QTP using DOT Net factory, then you are able to browse any web pages without browsers. Execute the below code,


Set obj = DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
Set objBrwsr = DotNetFactory.CreateInstance("System.Windows.Forms.WebBrowser","System.Windows.Forms")

With objBrwsr
.Width=800
.Height=800
.AllowNavigation=True
.AllowWebBrowserDrop=True
.IsWebBrowserContextMenuEnabled=True
End With

With obj .Controls.Add objBrwsrEnd with
objBrwsr.Navigate("
www.google.com")
obj.showdialog

Set obj =Nothing
Set objBrwsr=Nothing


You will get DOT Net Dialog with browser control as same as below,



Thanks and regards,

Asiq Ahamed

Masking Password Using DotNet Factory

If you want to mask your password instead of placing in datatable or encrypting it, then use the below code.

Set oForm=DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
Set oTextBox=DotNetFactory.CreateInstance("System.Windows.Forms.TextBox","System.Windows.Forms")Set oButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set oPoint = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", x, y)

With oPoint
.x = 120
.y = 20
End With

With oButton
.Location = oPoint
.Width = 100
.Text = "OK"
End with

With oPoint

.x = 0
.y = 20
End With

With oTextBox

.Location = oPoint
.UseSystemPasswordChar=True
End with

'Add Controls

With oForm
.CancelButton = oButton
.Controls.Add oButton
.Controls.Add oTextBox
End with

oForm.ShowDialog
Msgbox oTextBox.Text



Set oForm=Nothing
Set oTextBox=Nothing
Set oButton=Nothing
Set oPoint=Nothing
Run the above code you will get a DOT Net dialog like below.


Enter your password and click on OK button. The entered password will be displayed in a message box.
For more information about DOT Net controls, please refer the below link.