Friday, June 6, 2008

How to run the batch file through Script

I have taken 3 tests as a example for doing batch run. They are

1. Display -It will display a message in a word doc.
2. DisplayDate - It will display a date and time in a Notepad
3. Multiplication - It will display a mathematical table in Notepad

I converted them in respective funcitons and saved in notepad as a .vbs file.
(in C:\VBLibraryFiles\)
And i wrote a VBS Finction that is called above 3 functions and saved as a callAll.vbs
(in C:\VBLibraryFiles\)
Before running the test I loaded all files into resource tab

callAll() 'Here i am just calling callAll function which is defined in callAll.vbs file

**********************

Display.vbs -

public funciton display()

set WordObj = CreateObject("Word.Application")
WordObj.visible = true
Set wordDoc = WordObj.Documents.Add
WordDoc.Range.InsertBefore "Hi Good Morning"
WordDoc.SaveAs "C:\Greetings.doc"
WordDoc.quit
Set wordObj = Nothing

End Function

***********************

DisplayDate.Vbs -

Public Function displayDate()

Set fso = createObject("Scripting.filesystemObject")
Set fptr = fso.createTextfile("C:\Sample.txt")
a = FormatDateTime(Date,1)
fptr.writeLine a

End Function

*******************************

Multiplication.Vbs -

Public Function multiplication()

Set obj = createObject("Scripting.filesystemObject")
Set of = obj.createTextFile("C:\mat.txt")
For i=1 to 10
x=5*1
of.writeLine "5 * "&i&" = "&x
Next

End Function

*****************************

CallAll.Vbs -

Public Function callAll()

display()
msgbox "Test 1 is pass"
displayDate()
msgbox "Test 2 is pass"
multiplication()
msgbox "Test 3 is pass"

End Function

No comments:

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.