Thursday, May 16, 2013

Simple VB Script code to prevent my system from locking

This is common problem that we encounter that we have automate our suite and run the same at any given time.

However we can schedule the scripts using windows scheduler or other alternative but problem arises when we need to run the scripts unattended.

For that i have developed and tested a vb script that will not attack on existing running functionality and also prevent the system from locking.

'Step 1:Create WScript Object
set wscrpt = CreateObject("WScript.Shell")

'Step 2:Run the Loop so that system repeated again and again.

WScript.Sleep (10*1000)  'Set the timer for number of seconds.Here i am setting 10 seconds.

wsc.SendKeys ("{SCROLLLOCK 2}") 'Use Send Keys to press the keyboard control.

Loop  ' End Loop

Steps To run above Code

Step 1:Copy the above code into notepad file as it is.

Step 2:Save the file with any logical name you want but with .vbs extension to convert the notepad file into vb script executable file.

Step 3:Double click the the file it will start running.

Sunday, May 12, 2013

Simple Way of Adding Defects to Quality Center

Below is the Simple and working code that will log defect in Quality whenever encountered by your scripts.

Connects to Quality Center from a Quick Test test and adds a bug to the database. 

Dim TDConnection
Set TDConnection = CreateObject("TDApiOle.TDConnection")

TDConnection.InitConnection "http://yovav/tdbin" ' URL for the DB 'Enter the URL as per your server.

TDConnection.ConnectProject "TD76","bella","pino"  ' Valid login information.Change Parameter like User Name and Password.
If TDConnection.Connected Then
    MsgBox("Connected to " + chr (13) + "Server " + TDConnection.ServerName _
    + chr (13) +"Project " + TDConnection.ProjectName )
    MsgBox("Not Connected")
End If

'Get the IBugFactory
 Set BugFactory = TDConnection.BugFactory

'Add a new empty bug

Set Bug = BugFactory.AddItem (Nothing) 

'Fill the bug with relevant parameters

Bug.Status = "New"

Bug.Summary = "Connecting to TD"

Bug.Priority = "4-Very High" ' depends on the DB

Bug.AssignedTo = "admin" ' user that must exist in the DB's users list'

Bug.DetectedBy = "admin" ' user that must exist in the DB's users list
'Post the bug to database (commit)

Sending Keyboard Input to an Application

While using the QTP I came across the scenario where i need to press my keyboard keys and for that i found Device replay more suitable.

The Code lines that can be used to press keyboard keys are :

Set obj = CreateObject("Mercury.DeviceReplay")


obj.PressKey 63 

The PressKey method uses the ASCII value for the key.
63 is the ASCII value for F5.
ASCII values for other keys:
F1 - 59
F2 - 60
F3 - 61
F4 - 62
F5 - 63
F6 - 64
F7 - 65
F8 - 66
F9 - 67
F10 - 68
F11 - 87
F12 - 88

QTP Normalize String - Convert a String into Regular Expression using VB Script

'This function will convert a Normal String into Regular expression that can be easily utilized with your QTP 'Script.Hence the name of the function provided as Normalize String.
'It is Reusable code can be utilized as it is.

Function NormalizeString(OrgStr)

    Dim TempStr

    TempStr = Replace(OrgStr, "\", "\\")

    TempStr = Replace(TempStr, "*", "\*")

    TempStr = Replace(TempStr, "+", "\+")

    TempStr = Replace(TempStr, ".", "\.")

    NormalizeString = Replace(TempStr, "?", "\?")

End function

msgbox NormalizeString ("a+b*c.d?e")

'If anyone have any question in this kindly post them, I would be happy to resolve them.