Friday, February 4, 2011

Playing with array

WScript.echo "-------------------------------------------------------"
WScript.echo "Playing with array"
wscript.echo "-------------------------------------------------------"

Dim arrArray
Dim i
Dim sTmp
arrArray = Array(81,117,105,99,107,84,101,115,116,45,80,114,111)

'--- Checking if variable is an array.
If IsArray(arrArray) Then
For i = LBound(arrArray) To UBound(arrArray)
WScript.Echo (arrArray(i))
arrArray(i) = Chr(arrArray(i))
WScript.Echo (arrArray(i))
Next
End If

If IsArray(arrArray) Then
sTmp = Join(arrArray, vbNullString)
MsgBox sTmp
MsgBox vbNullString
MsgBox vbNull
End If

Erase arrArray
MsgBox vbArray
MsgBox vbByte

WScript.echo "-------------------------------------------------------"
WScript.echo "Split to make array n filtering"
wscript.echo "-------------------------------------------------------"


a=Split("Sunday Monday Tuesday WEDNES DAY T h urs dayF r iday Satu r day"," ",-1,1)
a=Split("Sunday Monday Tuesday WEDNES DAY T h urs dayF r iday Satu r day")
for each x in a
WScript.Echo(x)
Next

WScript.Echo
WScript.Echo "Filter Function"
WScript.Echo


WScript.Echo
WScript.Echo "True Function"
WScript.Echo

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
WScript.Echo (x)
Next

WScript.Echo
WScript.Echo "True Function"
WScript.Echo

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,0)
for each x in b
WScript.Echo (x)
next

WScript.Echo "True Function"

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True)
for each x in b
WScript.Echo (x)
next



WScript.Echo
WScript.Echo "False"
WScript.Echo


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False,1)
for each x in b
WScript.Echo (x)
next

WScript.Echo
WScript.Echo "False"
WScript.Echo


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False,0)
for each x in b
WScript.Echo (x)
next

Monday, July 26, 2010

Script conversion from Winrunner to QTP

 
Tools available to convert WR script to QTP are as follow

1.       Win Quick    (WinQuick is the only HP validated.)
2.       QTP Genie
3.       Test House
4.       Zapit
5.       Interoperate

Note:
·         All tools are licensed version  (Need to confirm for Win Quick )
·         100 % automated conversion is not possible. There would be approx 20% of manual conversion. (Ultimately we have to go through the whole code)

Tuesday, June 29, 2010

Vbscripting with Classes

Classess in VB script

Class Customer

     Private m_CustomerName
     Private m_OrderCount
    
Private Sub Class_Initialize
     m_CustomerName = ""
     m_OrderCount = 0
End Sub



' CustomerName property.

Public Property Get CustomerName
      CustomerName = m_CustomerName
End Property

Public Property Let CustomerName(custname)
     m_CustomerName = custname
End Property

' OrderCount property (read only).

Public Property Get OrderCount
     OrderCount = m_OrderCount
End Property

' Methods.

Public Sub IncreaseOrders(valuetoincrease)
     m_OrderCount = m_OrderCount + valuetoincrease
End Sub

End Class

Dim c

Set c = New Customer
c.CustomerName = "Fabrikam, Inc."
MsgBox (c.CustomerName)
c.IncreaseOrders(5)
c.IncreaseOrders(3)
MsgBox (c.OrderCount)

Property in Class

Class User
' declare private class variable

     Private m_userName
     Private m_Test
' declare the property

Public Property Get UserName
     UserName = m_userName
End Property

Public Property Let UserName (strUserName)
     m_userName = strUserName
End Property

Public Property Get Test
     Test = m_Test
End Property

Public Property Let Test (sTest)
     m_Test = srTest
End Property

' declare and define the method

Sub DisplayUserName
     WScript.Echo UserName
     WScript.Echo Test
End Sub

End Class

Dim objUser
Set objUser = New User
' set the UserName property
objUser.UserName = "The Guru"
objUser.Test = "Test value"
' call the DisplayUserName method to print the user name
objUser.DisplayUserName


Shared Class

Class Test
     Public InstanceValue As String
     Public Shared SharedValue As String
Public Shared

Sub ShareMethod()
     MsgBox("This is a shared method.")
End Sub

End Class


Sub TestShared()
     Dim Shared1 As New Test() ' Create an instance of the class.
     Dim Shared2 As New Test() ' Create an instance of the class.
     Shared1.SharedValue = "Share Value 1" ' Set the value of a shared field.
     Shared2.SharedValue = "Share Value 2" ' Overwrite the first value.
     MsgBox("The value of the shared field in the first instance" & _
      "is: " & Shared1.SharedValue)
     MsgBox("The value of the shared field in the second instance" & _
      is: " & Shared2.SharedValue)
'    Call a method on the class without creating an instance.
     Test.ShareMethod()
End Sub

Object Drive using Class

Dim filesys
set filesys = CreateObject("Scripting.FileSystemObject")
Set drv = filesys.GetDrive("e")

select case drv.DriveType
     Case 0: drtype = "Unknown"
     Case 1: drtype = "Removable"
     Case 2: drtype = "Fixed"
     Case 3: drtype = "Network"
     Case 4: drtype = "CD-ROM"
    Case 5: drtype = "RAM Disk"
End Select

WScript.Echo "The specified drive is a " & drtype & " type disk."
WScript.Echo " "
WScript.Echo "Total size is " & drv.TotalSize & ". "
WScript.Echo "Available space is " & drv.AvailableSpace & ". "
WScript.Echo "Type is " & drv.DriveType & " "
WScript.Echo "Path is " & drv.Path & " "

Dim filesyst, drive
Set filesyst = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Before Condtion"
drive = filesyst.DriveExists("z")
WScript.Echo drive

If filesyst.DriveExists("z") Then
     WScript.Echo("The specified drive does exist.")
Else
     WScript.Echo("The specified drive does not exist.")
End If

WScript.Echo "After Condtion"

Sunday, June 27, 2010

Time and date function in Vbscript

Time and date in Vbscript

'MsgBox (Date ())

WScript.Echo (Date ())
WScript.Echo (Time ())
WScript.Echo Now ()
WScript.Echo Hour (Time)
WScript.Echo Month (Date)
WScript.Echo (Time ())
WScript.Echo MonthName (1)
WScript.Echo MonthName (12)
WScript.Echo second (time)
WScript.Echo Timer ()
WScript.Echo TimeSerial (13,56,8)
WScript.Echo Timevalue (Time)
WScript.Echo Weekday (Date)
WScript.Echo WeekdayName(Weekday(2))
WScript.Echo





Playing with string in Vbscript

Manipulating String

Dim var
var = " hello Word "
MsgBox var
temp = Trim (var)
MsgBox temp
MsgBox var
temp1 = UCase(Trim (var))
MsgBox temp1
temp2 = LCase(temp1)
MsgBox temp2


Few more function for string

Dim temp
temp = "12 3456781 "

MsgBox (temp)
MsgBox (Len (temp))
MsgBox (Left (temp, 3))
MsgBox (right (temp, 3))
MsgBox (Mid (temp,2,3))
MsgBox (Mid (temp,1,3))
MsgBox (Mid (temp,5,2))
MsgBox (Trim (temp))
MsgBox (StrComp ("YES","yes",(0))) ' 0 is a case sensitive option
MsgBox (StrComp ("yes","ye",(1)))
MsgBox (String (34,"*"))
WScript.Echo (String (34,"*")) ' Run with both wscript n script option in CMD '
MsgBox (StrReverse ("HEllo"))

Thursday, June 24, 2010

Debug vbscript & Jscript from Command prompt

How to debug Windows Script Host (WSH) scripts, which can be written in any ActiveX script language (as long as the proper language engine is installed), but which, by default, are written in VBScript and JScript.
There are certain flags in the registry and, depending on the debugger used, certain required procedures to enable debugging.
To debug WSH scripts in Microsoft Visual InterDev, the Microsoft Script Debugger, or any other debugger, use the following command-line syntax to start the script:

               wscript.exe //d

This code informs the user when a runtime error has occurred and gives the user a choice to debug the application. Also, the //x flag can be used, as follows, to throw an immediate exception, which starts the debugger immediately after the script starts running:
               wscript.exe //d //x 

After a debug condition exists, the following registry key determines which debugger will be used:

HKEY_CLASSES_ROOT\CLSID\{834128A2-51F4-11D0-8F20-00805F2CD064}\LocalServer32

The script debugger should be Msscrdbg.exe, and the Visual InterDev debugger should be Mdm.exe.

If Visual InterDev is the default debugger, make sure that just-in-time (JIT) functionality is enabled. To do this, follow these steps:
  1. Start Visual InterDev.
  2. On the Tools menu, click Options.
  3. Click Debugger, and then ensure that the Just-In-Time options are selected for both the General and Script categories.
Additionally, if you are trying to debug a .wsf file, make sure that the following registry key is set to 1:

HKEY_CURRENT_USER\Software\Microsoft\Windows Script\Settings\JITDebug

Thursday, June 17, 2010

Structure outline of Automation Framework


Hi All,

Generic structure for Keyword Driven Framework:

·         Test case                                                             (Excel OR XML OR ELSE)
·         Driver script
·         Data script                                                           ( To collect & Validate the test data & Keyword from test case excel )
·         Common Functional Library                        (Common for all the test)
·         Business function & procedure                  (Can be specific to test)
·         Supportive library                                           (Application Independent)
·         Scripts                                                                   ( Specific to test  - only if required)
·         Test result
Configuration files which contain following thing: 

1.       File 1:  Contain the variable to make debug mode enable/disable.
a.       Can also include flag to install\Uninstall application.
b.      Point to re-configure the test environment.
c.       Flag to make different level of validation\Check point before executing test.
2.       File 2 :  Which contain all the required path of files. (Application, result, etc)
3.       File 3 : which contain global variable & QTP environment variable  used as reference for validation,  to invoke QTP & set the test environment.
Optional Feature:

1.       Maintaining result history separately, which can be maintain in such way that we can extract history detail of each test/module.
2.       Generating mail at completion of each scheduled run with result & important messages of failure.
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons