Friday, June 26, 2015

Training notes


-          Share Repository file extension is  - .tsr

-          Use objects and write code. Drag objects you will be able to use the objects to write the scripts. View- >Available Keywords.

Associate Repository to the scripts. This is nothing but sharing repository.

-          Shared Repository – objects get changed, will get impacted?

-          To report each and every step in test case, do the following:

If Browser("Browser").Page("Page").WebEdit("lastname").Exist(2) Then

Reporter.ReportEvent micPass,"The Edit box should be displayed","The Edit box is displayed"

Else

Reporter.ReportEvent micFail,"The Edit box should be displayed","The Edit box is not isplayed"

End If

-          Create object to reuse the path

Object variable

Set Obj1 = Browser(“dsf”).Page(“dfd”)

Obj1.WebEdit(“df”).set = “Srikanth”


Here you can use the Obj1 instead of Browser……


-          Desktop.Capturebitman(“<path>”) ----provision to capture screenshot

Ex:

If (obj1.Exist(2)) then

Desktop.Capturebitman(“<path>”)

Else

Desktop.Capturebitman(“<path>”)

End if

-          Tools Options -> Run->Screen Capture ---- through this also you can save the test case screen print or video

-          Check Syntax --- Icon on the menu bar will help you fix the syntax error

-          WebTable  --- 4 Important methods are RowCount, ColumnCount, GetCellData, ChildItem

-          WebTable is used where you cannot store too many objects in objectrepository

Set obj = Browser(“a”).Page(“a”).WebTable(“Passengers”).ChildItem(“<row>”,”<col>”, WebEdit, )

Obj.


Real time: Sometimes when you try to add objects using object spy from a portal where you have to select an object which you need to dig a lot, during that process too many objects get added to the object repository. To avoid that set a obj for a webtable child, that way you need not add that object in webtable to object respository, but just add childitem to the created object.

rc = Browser("Browser").Page("Page").WebTable("Emergency Contact").RowCount

 rownum=1

     For i = 2 to rc

         cc =  Browser("Browser").Page("Page").WebTable("Emergency Contact").ColumnCount(i)

         DataTable.SetCurrentRow(rownum)

        For  j = 1 to cc

                If j =1 Then

                   Set obj = Browser("Browser").Page("Page").WebTable("Emergency Contact").ChildItem(i,j,"WebEdit",0)

                    obj.set DataTable.Value("EmergencyContact")

                End If

                  If j =2 Then

                   Set obj = Browser("Browser").Page("Page").WebTable("Emergency Contact").ChildItem(i,j,"WebEdit",0)

                    obj.set DataTable.Value("Telephone")

                End If

                        If j =3 Then

                   Set obj = Browser("Browser").Page("Page").WebTable("Emergency Contact").ChildItem(i,j,"WebList",0)

                    obj.Select "sibling"

               

                End If

        Next

        rownum =rownum+1

    Next

-          Changing the object property in runtime---- using SetToProperty(“<object>”, “<value>”)



-          'Use calculator, write a function to evaluate the following expression (Just use one object)

'71+29=


http://www.tutorialspoint.com/qtp/

-          Descripting programming is writing code without building object Repository

Browser(“name=”<name>”)).Page…..


Completely avoiding object Repository

-          Two types of Descriptive programming  -- Descriptive Objects and Descriptive Strings.


   Descriptive.Strings

Descriptive.Objects ---- Descriptive.Create



-          Descriptive.Create --- is used to create object for a web object

-           

'1. Descriptive Programming:

'1. Descriptive Strings

 Browser("title:=Sample.html").Page("name:=.*").WebEdit("name:=firstname").Set "Hello"

2. '. 2. Description Objects

Set oDesc = Description.Create()

oDesc("micClass").Value = "Browser"

oDesc("title").Value = "Sample.html"

Set pDesc = Description.Create

pDesc("micClass").Value = "Page"

pDesc("title").Value = ".*"

Set eDesc = Description.Create

eDesc("micClass").Value = "WebEdit"

eDesc("name").Value = "firstname"

 Browser(oDesc).Page(pDesc).WebEdit(eDesc).Set "GDGSGSG"


-          Finding objects on desktop like Calculator ?


CTSC0192



-          Set oDesc = Description.Create()

-oDesc("micClass").Value = "Browser"

-oDesc("title").Value = "Sample.html"

-Set pDesc = Description.Create

-pDesc("micClass").Value = "Page"

-pDesc("title").Value = ".*"

-Set eDesc = Description.Create

-eDesc("micClass").Value = "WebEdit"

-Set objColl = Browser(oDesc).Page(pDesc).ChildObjects(eDesc)

-For i = 0 to objColl.Count-1

-objColl(i).Set "Hello Programming"

-Next

-

-          Write a Program to print the number of

-1. Text boxes

-2. Radio Group

-3. Links

-4. WebElements

-5.Check Box

-2. Write a Program to select  third drop down value from all the Listboxes present in a page

-Hint:

-Browser("Browser").Page("Page").WebList("cars").Select "#1"

-          Using xml in QTP:

QTPworld.com

Load --- to load the xml

Ø  http://www.qtpworld.com/index.php?cid=86    ----- reading xml

-          Connecting to DB:


‘MS Access DB

strDBPath = "C:\Users\sarathi\Desktop\Training\Sample.accdb"   

Set ObjConnection1 = CreateObject("ADODB.Connection")

    ObjConnection1.ConnectionString = _

        "Provider=Microsoft.ACE.OLEDB.12.0;" & _

        "Data Source=" & StrDBPath & ";" & _

        "Persist Security Info=False"

    ObjConnection1.Open

    StrQuery = "SELECT * FROM Table1 ORDER BY 1 ASC"

    Set objRecordSet1 = ObjConnection1.Execute(StrQuery)

    Do Until objRecordSet1.EOF

   

        For LngField = 0 To objRecordSet1.Fields.Count - 1

            Msgbox objRecordSet1.Fields.Item(LngField).Value

         

        Next 

        objRecordSet1.MoveNext

    Loop



-          Dis adv  of Des programming – too much coding.

-          Adv of Des programming – childobjects

-          Descriptive Programming:

Ø  Static

Ø  Dynamic

-          Childobjects – To retrieve all objects present under a parent

-          Descriptive Programmin'g
'1. Static
'2. Dynamic

'Static :

'Browser("title:=Sample.html").Page("title:=.*").WebEdit("name:=firstname").Set "Hello"

'Set bdesc = Description.Create

'bdesc("micClass").Value = "Browser"
'bdesc("title").Value = "Sample.html"

'Msgbox Browser(bdesc).Exist

'Child Objects:

Set textdesc = Description.Create

textdesc("micClass").Value = "WebEdit"

set ocoll = Browser("title:=Sample.html").Page("title:=.*").ChildObjects(textdesc)


For i = 0 to ocoll.count-1

If i = 4 Then
oColl(i).Set "This is 4th text box"
End If

Next

-          Lbound() and UBound() for finding size of an array

-          Conversion functions – to connver one data type to another

-          Dim will help variables to change the its data type as per the data you feed into it.

-          LTRIM(), RTRIM(), LEN(), TRIM(), MID(), SPLIT() --- important functions

-          Description Properties

-          Disable smart identification  in object repository. Its always better to define object instead totally depend on QTP

-          Index – 0 – will select first test box

-          Save repository -> Manage repository- > Add repository -> add actions to link to use that repository

-          Resouce-> Add library to use the function library

-          Connecting MSAccess, design script. Pick the data from excel and post in MSAccess DB

-          Library function – includes – Business flow(login page) functions, Report functions, Framework related – folder creation

-          Framework – Library folder, Object repository, Results

-          Environment variables are for library functions?

-          Environment variables are declared using double quotes?

Ex: Environment. Value(“Name”) = “value1”

-          Starttime = Timer()

Lines of code

Endtime = Timer()

Total time = Endtime- Starttime

Timer - Timer returns the number of seconds from 12:00a.m. This function is very useful for evaluating time spent in performing an activity by taking timer at the start and end of the activity and subtracting the time between two.

-          Watch View ---- helps to findout the values of functions and variables during run time????

-          You can also do Add to Watch --- by right clicking on Function or variable to add to Add to watch

-          Use F11 --- while running the script this will help you to identify the functions tagged to the script

-          Click method when you used, one need not use Wait method because it automatically includes that feature?

-          For Iterator = 1 To 1 Step 1
  
Next


The Step Keyword

With the Step keyword, you can increase or decrease the counter variable by the value you specify.

In the example below, the counter variable (i) is INCREASED by two, each time the loop repeats.

For i=2 To 10 Step 2
some code
Next

To decrease the counter variable, you must use a negative Step value. You must specify an end value that is less than the start value.

In the example below, the counter variable (i) is DECREASED by two, each time the loop repeats.

For i=10 To 2 Step -2
some code
Next


-          Apparently there is no direct method to determine the length of an array in VBScript. The best way I could find is to use UBound(ArrayName). This will return the upper limit of the array. Unfortunately, it doesn’t account for empty items in the array.

-          I am unable to stop QTP script, it is running uninterruptedly even after I click the stop button.

-          Do Until i=10
some code
Loop

1 comment:

  1. Thanks for sharing these, I am doing qtp trainings it is very helpful me. Keep it up!

    ReplyDelete