Monday, February 11, 2013

Working With Word Document

*****************************************************************************************************
Working with Word Docuument:
*****************************************************************************************************
 Create a word Document:
*****************************************************************************************************
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
'Documents collection includes all of the open documents.
'Add method is used to create a blank document.
'Document object returned by Add method is assigned to a variable, objDoc.
Set objDoc = objWord.Documents.Add()
*****************************************************************************************************
Open a word Document file:
*****************************************************************************************************
Set wrd = CreateObject("Word.Application")
wrd.Visible = True
wrd.Documents.Open "D:\Temp.doc"
Set wrd.Nothing
*****************************************************************************************************
Writting a Text in Word Application:
*****************************************************************************************************
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oDoc = oWord.Documents.Add()
Set oSelection = oWord.Selection
'Selection property represents selected area in a document or an insertion point
oSelection.TypeText = "Sample Text"
*****************************************************************************************************
Formatting the text in the word document:
*****************************************************************************************************
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oDoc = oWord.Documents.Add()
Set oSelection = oWord.Selection
'Setting the Font Name
oSelection.Font.Name = "Arial"
'Setting the Font Size
oSelection.Font.Size = "20"
'Setting the type face to Bold
oSelection.Font.Bold = True
oSelection. ParagraphFont.Alignment = 1
'0 - Aligns text to Left, 1- Aligns text to center
'2 - Aligns text to Right, 3 - Justify the text
oSelection.TypeText = "Add your text here"
*****************************************************************************************************
Replacing a Word in Word Document:
*****************************************************************************************************
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.documents.Open("C:\WordDocument.docx")
Set oWords = oDoc.Words
For word = 1 to oWords.Count
oWords.Item(word).Text = Replace(oWords.Item(word).Text, "sample","New word")
Next
oDoc.Save
oDoc.Close
oWord.Quit
Set oDoc = Nothing
Set oWords = Nothing
Set oWord = Nothing
*****************************************************************************************************
Saving the Word Document:
*****************************************************************************************************
To save a single doucument use the Save method with the Document object. The following insturction saves the document named "Sales.doc"
Documents("Sales.doc")Save
You can save all open documents by applying Save method to the Documents collection. The following instruction saves all open documents.
Documents.Save
'To save to a new location use "SaveAs" else use "Save" method to save it on default location
oDoc.SaveAs("c:\MyDoc.doc")
*****************************************************************************************************
Closing the Word Document:
*****************************************************************************************************
oWord.Quit
 *****************************************************************************************************
Working with Tables:
*****************************************************************************************************
Set oWord = CreateObject("Word.Application")
oWord.visible = True
Set oDoc = oWord.Documents.Add()
Set oRange = oDoc.Range()
oDoc.Tables.Add oRange,3,3
Set oTable = oDoc.Tables(1)
For Row = 1 to 3
For Column = 1 to 3
oTable.Cell(Row,Column).Range.Text = Row&" Row, "&Column&" Column"
Next
Next
'Make the First Row Data to Bold
oTable.Rows.Item(1).Range.Font.Bold = True
'Makes the First Row Data to Italic
oTable.Rows.Item(1).Range.Font.Italic = True
'Changes the font size
oTable.Rows.Item(1).Range.Font.Size = 12
'Sets the width of the Column
oTable.Columns.Item(1).SetWidth 100,0
*****************************************************************************************************
Open and Append Text to a Document:
*****************************************************************************************************
Dim oWord
Set oWord = CreateObject("Word.Application")
oWord.Documents.Open "c:\text.doc"
oWord.Selection.TypeText "Text which is appended to existing document"
oWord.ActiveDocument.Save
oWord.Quit
Set oWord = Nothing
Selection property by default appends the text at the beginning only. To put the statements for selection at the end before entering the text, use the below cose.
Dim oWord
Set oWord = CreateObject("Word.Application")
oWord.Documents.Open "c:\text.doc"
oWord.Selection.EndKey 6,0
oWord.Selection.TypeText "Text which is appended to existing document"
oWord.ActiveDocument.Save
oWord.Quit
Set oWord = Nothing
*****************************************************************************************************
Prints the word document:
*****************************************************************************************************
Dim oWord
Set oWord = CreateObject("Word.Application")
oWord.Documents.Open "c:\test.docx"
oWord.Activedocument.PrintOut
oWord.Quit
Set oWord = Nothing

QTP Framework

************************************************************************************************
Framework:
************************************************************************************************
A set of guidelines like coding standards , test-data handling , object repository treatment etc... which when followed during automation scripting produce beneficial outcomes like increase code re-usage , higher portability , reduced script maintenance cost etc. Mind you these are just guidelines and not rules; they are not mandatory and you can still script without following the guidelines


Basically QTP supports three kind of framework i
1)     Linear Framework
2)     Modular driven framework
3)     Keyword Driven Framework.
************************************************************************************************
Linear Framework
************************************************************************************************
                It deals with individual script which is recorded under one Action and running individual. I think we all done this thing in very first when we get the QTP but I’m very sure, not all one know that we created and executed the test under Linear Framework. Anyway this is not big deal. I was also not aware when I get the QTP first time. So this is very simple and easy way to create the test by navigating through the application. But by using this method there are some limitations which we can not cross. Sometime when we test some business processes in one application, we may feel that some operations we repeat in all Linear Framework Script. To handle this situation we go with Modular Framework which solves this kind of problem by dividing the single test in multiple part or module.
************************************************************************************************
In modular framework
************************************************************************************************
                  Tester basically divides the test in different parts which give the facility to use the different part of scripts in any tests. That solves the many problem of repeataion of test and gives the facility to make the script reusable? So in one sentence, Division of Linear Framework script in different parts called Modular Framework.
************************************************************************************************
keyword driven framework
************************************************************************************************
           Tester should know the basic of programming because it deals with function. In programming, Function is an important part of programming as they allow you to create chunks of code that performs a specific task. Basically we create the functions in the one test and calling these functions as keyword in other tests therefore we are calling keyword driven framework. This is very important and useful framework to deal and handle many critical tasks in testing through QTP.