Thursday, July 14, 2011

Retrive value from NotePad using QTP

Hey folks,

I tried to write function for retrive value from notepad and get particular data from it.
Precondition: Notepad line format should be same with some pattern like comma sepearted.

call opennotepad()
public function opennotepad()
Dim objFSO, fileName, objFile, strContents, str, position

Set objFSO = CreateObject("Scripting.FileSystemObject")
fileName = "D:\Trupti \folder\Automation\filename.txt"
Set objFile = objFSO.OpenTextFile(fileName,1,true)
reporter.ReportEvent micPass,"File open","File open successfully"
strContents1 = objFile.ReadLine
For I = 0 to 13 '13 is line count, we can write variable if it dynemic

strContents = objFile.ReadLine
DataTable.SetCurrentRow(I)
Call StoringValues(strContents)
field1=Trim(locfield1)
field2=Trim(locfield2)
Next

objFile.Close
Set objFile = nothing
Set objFSO = nothing
End Function

Public Function StoringValues(strContents)
locfield1=mid(strContents,2,22) ' in mid function-strcontent is string, 2 is start value, and 22 is upto 22 length of char data will retrive
localfield2=mid(strContents,87,5)
Endfunction

Saturday, June 11, 2011

About Scripts

Scripting Language
A scripting language is a particular syntax used to execute commands on a computer. A program composed of commands from a particular scripting language is referred to as script.

Difference between Client Side Scripting & Server Side scripting
Client side Scripting
  1. Client side scripting is programmatic code in an HTML file that runs on the browser.
  2. Client side scripting is commonly written using java script language.
  3. A client side script is not processed at all by the web server, only by the client. It is the client’s responsibility to execute any and all client side scripts.
Server Side Scripting
  1. Server side scripts are scripts that execute on the web server. These scripts are processed and their output is sent to the client.
  2. The client does not receive any code from server side scripts; rather the client receives just the output of the server side scripts. Client side scripts and server side scripts cannot interact with one another because the client side scripts are executed on the client after the server side scripts have finished processing completely.
  3. Vbscript is example of server side script
Difference between Java script and VB Script
Javascript -
  1. It is client side scripting language, developed by Netscape.
  2. It is case sensitive.
  3. File extension is .js.

VBscript -
  1. It is both Client and server side scripting language,developed by Microsoft.
  2. It is not case sensitive.
  3. File extension is .vbs and .vba.

Wednesday, May 25, 2011

QTP-File Extensions

Hi Folks,

Following are type of file extensions used in QTP.
  1. function library files = .vbs, .qfl and .txt
  2. local object repository file = .mtr
  3. shared object repository file = .tsr
  4. recovery scenory file = .qrs
  5. Default.cfg :- "Microsoft Office Outlook Configuration File"
  6. Default.xls :- "This is the copy of the internal datatable which is there by default. 1 sheet is Global, other sheets are as per the Action names"
  7. Login.usr :- "It is a kind of default constant file where all the inbuilt vaialbles are assigned some values or otherwise"
  8. Script.mts :- "This is just the scripts as per each action. Whatever you write in each action will be saved here"
  9. thick_usr.dat :- "It is a kind of default constant file where all the inbuilt vaialbles are assigned some values or otherwise"
  10. thin_usr.dat :- "It is a kind of default constant file where all the inbuilt vaialbles are assigned some values or otherwise. It consists of less no. is variables than thick_usr.dat"

Wednesday, May 18, 2011

QTP-How to use Parameter using QC

How to use Parameter in QTP

To use parameter in QTP, first we need to declare it in QC under parameter tab. If you want to define Input parameter then, you have to define it in input section. If you want to define output parameter then you have to define it in output section. Parameter name should be same in QC and QTP script.

Steps
  1. Create first component
  2. Define input and output parameter in QC
  3. Declare parameter value in QTP script
  4. Assign value for input parameter in QTP, example parameter(“SearchStr”)=”string for search value”
  5. Use the input parameter in control
  6. Use run time value and assign it to output parameter for use in QTP, example parameter(“outurl”)=”www.google.com”
  7. Now, make second component
  8. Use first component’s output parameter as input value in second parameter.
  9. Follow same steps as mentioned in first component.
  10. Now to run the QC and use parameter create test case in test plan module.
  11. Pull the first and second component in test case.
  12. Give input value in first component for run.
  13. Check use output value of previous component checkbox in second component.
  14. Integrate test case with test lab.
  15. Run the test case from QC.
  16. It will take input search string from first component and output value of first component is used as input of second component and execute whole test combine.
 Sample script1

Dim browsernm,pagenm
browsernm="Google"
pagenm="Google"
URL=http://www.google.com/
SystemUtil.Run "iexplore.exe",URL
reporter.ReportEvent micPass,"IEopen","Google open"

‘code for debug and error handling purpose
On Error Resume Next
Err.Clear
Dim testset, n
Set testset = QCUtil.CurrentTestSet
n = testset.name
If Err.Number <> 0 Then
Errr.Clear
End If

'Debug Declaration

If n = "" Then
Parameter("Searchstr")="Parameter Test in QTP"
End If
Parameter("OutURL")=""
Set Currobj=Browser("title:="&browsernm,"CreationTime:=0").Page("title:="&pagenm)

If parameter("Searchstr")<>"" Then
If Currobj.WebEdit("name:=q").exist Then
Currobj.WebEdit("name:=q").Set Parameter("Searchstr")
reporter.ReportEvent micPass,"searchvalue","search value set successfully"

Parameter("OutURL")=Currobj.WebElement("innertext:=qtp.blogspot.com/2007/11/qtp-test-parameters_11.html").GetROProperty("innertext")
reporter.ReportEvent micPass,"linkvalue","Link value set properly"
else
reporter.ReportEvent micFail, "searchvalue","search value not set successfully"
End If
End If

Sample Script2

Dim browsernm,pagenm
On Error Resume Next
Err.Clear
Dim testset, n
Set testset = QCUtil.CurrentTestSet
n = testset.name
If Err.Number <> 0 Then
Errr.Clear
End If

'Debug Declaration
If n = "" Then
Parameter("InURL")=""
end if

If parameter("InURL")<>"" Then
SystemUtil.Run "iexplore.exe",Parameter("InURL") reporter.ReportEvent micPass,"IEopen","Google open"
End If