Wednesday, October 25, 2017

Description Programming

'==Descriptive Programming language
'creating the common browser and page object 
Set myPage= browser("creationtime:=0").page("title:=.*")
'creating ll Description objects 
'it contacins all th eobjects present in webpage
Set desc=Description.Create


' getting all childobjects 
set allPageObjects=myPage.ChildObjects(desc)
'priting all the objects from the page.//total count
print allPageObjects.count

'here we use micclass to get the property of classname'micclass

For i = 0 To allPageObjects.count-1 Step 1
    print "object *****"&i
    print allPageObjects(i).getroproperty("micclass")&"-----"&allPageObjects(i).getroproperty("visible")
Next
'print allPageObjects(0).getroproperty("micclass")
'-----------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


'==Descriptiv language
'creating the common browser and page object
Set myPage= browser("creationtime:=0").page("title:=.*")
'creating ll Description objects
'it contacins all th eobjects present in webpage
Set desc=Description.Create


'filter TO GET PARTICULAT WEB ELEMENT


' to display the objects of only webedits
'desc("micclass").value="WebEdit"

'to get the complete Links
'desc("micclass").value="Link"

'to get the complete Links
desc("micclass").value="WebList"

' getting all childobjects
set allPageObjects=myPage.ChildObjects(desc)
'priting all the objects from the page.//total count
print "Totol number of objects are :-"&allPageObjects.count


'specific object from the page*******
'print allPageObjects(0).getroproperty("micclass")



'here we use micclass to get the property of classname'micclass

For i = 0 To allPageObjects.count-1 Step 1
    'print "object *****"&i
    print allPageObjects(i).getroproperty("micclass")&"-----"&allPageObjects(i).getroproperty("innertext")
Next



allPageObjects(0).SELECT ("Jan")

'Calling the function to get links
WebelementCount "Link"

Function WebelementCount(webelement)

    Set myPage= browser("creationtime:=0").page("title:=.*")
    Set desc=Description.Create
    desc("micclass").value=webelement
    set allPageObjects=myPage.ChildObjects(desc)

print "Totol number of objects are :-"&allPageObjects.count
For i = 0 To allPageObjects.count-1 Step 1
    print allPageObjects(i).getroproperty("micclass")&"-----"&allPageObjects(i).getroproperty("innertext")
Next
End Function


'-------------------------------------------------------------------------------------------------------------


'google links
Set myPage= Browser("creationtime:=0").Page("title:=.*")
set desc=Description.Create
desc("micclass").value="Link"
desc("height").value=21
set objLink=myPage.ChildObjects(desc)
print objLink.count

For i = 1 To objLink.count Step 1
    print objLink(i).getroproperty("innertext")
Next


'-----https://demo2.odoo.com/web#view_type=list&model=sale.order&menu_id=487&action=719
'demo2.
Set myPage=Browser("creationtime:=0").Page("title:=.*")
Set desc=Description.Create
desc("micclass").value="WebCheckBox"
desc("height").value=15
set ObjWebCheckBox=myPage.ChildObjects(desc)
print ObjWebCheckBox.count
ObjWebCheckBox(0).click



'---------**********************************************************************

'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select
'Weblist
Set desc= Description.Create
desc("micclass").value="WebList"
desc("height").value=21

Set myPage=Browser("creationtime:=0").Page("title:=.*").ChildObjects(desc)

myPage.count
myPage(0).CaptureBitmap "f:\list.png",true
myPage(0).select(1)
'or
myPage(0).GetItem(3)


'*******************************************************************************88


Set box = Browser("creationtime:=0").Page("title:=.*").WebElement("class:=signin-box")

Set desc = description.Create
desc("micclass").value="WebEdit"

Set objEdits = box.ChildObjects(desc)
print " Total edit boxes -> "& objEdits.count
objEdits(0).set "username"
objEdits(1).set "password"



desc("micclass").value="WebButton"
Set objButton = box.ChildObjects(desc)
print "Total buttons -> " & objButton.count
print objButton(0).getroproperty("value")
'objButton(0).click


desc("micclass").value="WebCheckBox"
Set objCheckBox = box.ChildObjects(desc)
If  objCheckBox(0).getROProperty("checked") = 0 Then
objCheckBox(0).click
End If


'------
********************************************************************



'rediff mail 

Set desc =Description.Create
Set myPage=Browser("creationtime:=0").Page("title:=.*").WebElement("class:=login-form")
Set desc =Description.Create
desc("micclass").value="WebEdit"
Set objectWebEdit=myPage.ChildObjects(desc)
print "the total number of edit fields are:-"&objectWebEdit.count

'*********************************************************************
' entering values into username and password


objectWebEdit(0).set "sud3eer@rediffmail.com"
objectWebEdit(1).set "Kewl@080288"

'************************************************************************
'click on button now:-

desc("micclass").value="WebButton"
Set objectWebbutton=myPage.ChildObjects(desc)
print objectWebbutton(0).getroproperty("value")
objectWebbutton(0).click



'******************************************************************
'https://www.quikr.com/
' extracting from the boxes

Set myPage= Browser("creationtime:=0").page("title:=.*")
Set desc=description.Create
desc("micclass").value="WebElement"
desc("class").value="col-sm-4 col-md-4"

set categories=myPage.ChildObjects(desc)
print categories.count

Set desc_link= description.Create
desc_link("micclass").value="Link"



For j = 0 To categories.count-1
print"**********************"
set chilobj=categories(j).childObjects(desc_link)
'print "total links are -->"&chilobj.count
For k = 0 To chilobj.count-1
'extracting links from a box
'print chilobj.count
    print chilobj(k).GetRoProperty("innertext")
Next
   
Next

'************************************************************************
'  Working with object with in the object
'Exporting 
 datatable.AddSheet "quikr"'---adding excel sheet quikr
set myPage = Browser("creationtime:=0").Page("title:=.*")
Set descCategories = description.Create
descCategories("micclass").value="WebElement"
descCategories("html id").value = "cats"
Set categories= myPage.ChildObjects(descCategories)
print categories.count
Set desc_link = description.Create
desc_link("micclass").value= "Link"
Dim col_name
' category
For i=0 to categories.count-1
    col_name = "Category_"& i

' adding column wise i.e boxes
datatable.GetSheet("quikr").AddParameter col_name,""
    print "***********************************************"
Set objLink = categories(i).childObjects(desc_link)
' links
print "Total Links -> " & objLink.count
    For j=0 to objLink.count-1
        datatable.GetSheet("quikr").SetCurrentRow(j+1)
        linktext= objLink(j).getROProperty("innertext")   
        print linktext
        datatable(col_name,"quikr")=linktext
    Next
Next
datatable.ExportSheet "C:\quikr.xls","quikr"

'-----------------------------------------------------------------------------------------------------------





Tuesday, October 24, 2017

Actions:


 browser("Rediffmail").Navigate("https://mail.rediff.com/cgi-bin/login.cgi")
Browser("Rediffmail").Page("Rediffmail").WebEdit("login").Set "sud3eer@rediffmail.com"
Browser("Rediffmail").Page("Rediffmail").WebEdit("passwd").Set "Kewl@080288"
Browser("Rediffmail").Page("Rediffmail").WebButton("Go").Click
1. Save a test--reusableaction
2. Save again test as reusableaction_test
3.call in script:call to existing action.(it is not editable)-it cn be open when u call direct test.
run the below one it will execute complete login.
 RunAction "Action1 [ReusableActions_test]", oneIteration

Monday, October 23, 2017

Compare rows from sheets

' adding T1 and T2 sheets to datatable

datatable.AddSheet "T1"
datatable.AddSheet "T2"

' iporting sheets to datattable
datatable.ImportSheet "F:\qtp2.xls","T1","T1"
datatable.ImportSheet "F:\qtp2.xls","T2","T2"
datatable.AddSheet "Result"
' clling fuction
compare("Name")
compare("Email")

'exporting results to excel
datatable.ExportSheet "F:\qtp2.xls","Result"

Function compare(colName)
datatable.GetSheet ("Result").AddParameter colName,""
' which col has max rows
rows=0
If datatable.GetSheet("T1").GetRowCount > datatable.GetSheet("T2").GetRowCount Then
    rows = datatable.GetSheet("T1").GetRowCount
else
    rows = datatable.GetSheet("T2").GetRowCount
End If

For i=1 to rows
    datatable.GetSheet("T1").SetCurrentRow(i)
    datatable.GetSheet("T2").SetCurrentRow(i)
    datatable.GetSheet("Result").SetCurrentRow(i)
    If datatable(colName,"T1") <> datatable(colName,"T2") Then
        datatable(colName,"Result") ="N"
    else
        datatable(colName,"Result") ="Y"
    End If
Next

End Function

DataTable_Importing[import from existing sheet to new sheet]

'Importing Datatable
datatable.AddSheet ("TestData")' if we want to import own sheet first we need to add sheet
datatable.import "F:\qtp2.xls" ' it import global and ation sheets


datatable.GetSheet("Action1").SetCurrentRow(4) 'the cursor is at row 4
print datatable ("Country","Action1") 'it will print the cursor row from action1 sheet and country column

'******************************************************

'Importing sheet from source to destination sheet!/importing existing sheet to new sheet
datatable.AddSheet("currentTest")' Adding the Sheet -currentTest
datatable.ImportSheet "F:\qtp2.xls","TestData","currentTest"'Adding the testData sheet to currentTest sheet
datatable.GetSheet("currentTest").SetCurrentRow(5)'cursor will be at 5th row
print datatable ("Test","currentTest")'priting the data of Test column in currentTest

'*************************************************


DataTable_Local Sheet Read Write and Export

'************************'Local data table*****************************

'To get the total rowCount  from Action1 Sheet


print datatable.GetSheet("Action1").GetRowCount
'*******************************************************
' Reading the data and wrting 

For i = 1 To datatable.GetSheet("Action1").GetRowCount Step 1
    datatable.GetSheet("Action1").SetCurrentRow(i)
    print datatable("Country","Action1")' read the data of Action1 of country column
    datatable("Test","Action1")=i 'Writes to the Action1 of Test Column
    ' in test column it will display 1,2,3,4.
Next
'wait 15

'*****************************************************
'Adding the column in Local Sheet
datatable.GetSheet("Action1").AddParameter "Col4","1234"
'if script complete column will be flashed out,see in test result window.
'wait 5

'*******************************************8
'Add own sheet in Datatable

datatable.AddSheet("TestData")                             ' Adding the Sheet to datattable
datatable.GetSheet("TestData").AddParameter "Test",""     'created a column in sheet "TEST
datatable.GetSheet("TestData").SetCurrentRow(5)            'writing in 5th column to the sheet TestData/Test
datatable("Test","TestData")="XXXXXXXX"                 'Writing data as XXXXXXX 
                                       
'******************************************************************
'Export complete datatble to xls file 2003
' in qtp only xls files are supported
' here old exported file will be deleted add new data will be appended


' to export complete datatable
datatable.Export "f:\qtp2.xls"
'to export particulat sheet from excel.
datatable.ExportSheet "f:\qtp2.xls","Action1"


                                       

Data Table-Global_reading_Writing

'Data Table
'Reading data from data table

'In data table 2 sheets 

'Global:-
'Local sheet:-

' change in---> setting --->Run--> RUN WITH ONE ITERATION ONLY

'****** Interact with GLOBAL sheet**********
print "start"
'open browser
'loggedin
print datatable("Name")' row 1 
datatable.SetCurrentRow(2)' cursor move to next
print datatable("Name")
datatable.SetCurrentRow(3)
print datatable("Name")
print "end"

' retrive all data using for loop
For i = 1 To datatable.GetRowCount Step 1
    print datatable("Name")
    datatable.SetCurrentRow(i)
    datatable("Country")="India"' wrting data on country column ie INDIA
Next
wait 5 ' it will wait to see the data india in coutry column ,

 'to know the total number of rows
 print datatable.GetRowCount


 'Writing data to datatable

 For i = 1 To 10 Step 1
     datatable.SetCurrentRow(i)
    datatable("Col1")=i                     ' it will write 1 to 10 in col1 
    datatable("Col2")=11-i          ' it will write 10 to 0 in colmn 2
    datatable("Col3")=cint(datatable("Col1"))+cint(datatable("Col2")) 'Adding column 1 and coulumn '2
 
 Next

wait 25

'IN DATATABLE MODIFICATIONS WONT DISPLAY ,IT WILL DISPLAY TILL THE TIME OF SCIPT RUNNING,ONCE SCRIPT END IT WILL 
'DISCARD,TO SEE THAT SEE IN RESULT WINDOW

' to add the column to the global sheet
 datatable.GlobalSheet.AddParameter "Test_Col",""
 wait 10'

Compare RO and TO properties

  'http://www.w3schools.com/html/default.asp

 bResult = bResult & "<table border=1><tr><th>" & _
                    "Status</th><th>Property</th><th>Expected</th><th>Actual</th></tr>"

Set allProp = Browser("HTML Tutorial").Page("HTML Tutorial").WebButton("Search").GetTOProperties
isPass=true
For i=0 to allProp.count -1
    expected = allProp(i).value
    actual = Browser("HTML Tutorial").Page("HTML Tutorial").WebButton("Search").GetROProperty(allProp(i).name)

    If trim(expected) <> trim(actual) Then
        bResult = bResult & "<tr><td>" & _
                            "Fail" & "</td><td>" & _
                            allProp(i).name & "</td><td>" & _
                            expected & "</td><td>" & _
                            actual & "</td></tr>"
        isPass=false
    else
        bResult = bResult & "<tr><td>" & _
                            "Pass" & "</td><td>" & _
                            allProp(i).name & "</td><td>" & _
                            expected & "</td><td>" & _
                            actual & "</td></tr>"
    End If
Next



Set StepInfo = CreateObject("Scripting.Dictionary")
StepInfo("ViewType") = "Sell.Explorer.2"
StepInfo("DllIconIndex") = 209
StepInfo("DllIconSelIndex") = StepInfo("DllIconIndex")
StepInfo("DllPAth") = Environment.Value("ProductDir") & "\bin\ContextManager.dll"

If isPass Then
    StepInfo("Status") = micPass
else
    StepInfo("Status") = micFail
End If


StepInfo("NodeName") = "Result page name"

StepInfo("StepHtmlInfo") = "<html>" & bResult & "</body></html>"



    Reporter.LogEvent "User", StepInfo, Reporter.GetContext

  

'''''''''''''''''''''''''''''''''''''''''''''''''''FUNCTION''''''''''''''''''''''''''''''''''''''''''''

Set o =Browser("HTML Tutorial").Page("HTML Tutorial").WebButton("Search")
validateObjectProperties o,"search Button Validation"

Set o = Browser("HTML Tutorial").Page("HTML Tutorial").Link("HTML Formatting")
validateObjectProperties o,"Html Formatting Link"

Set x = Browser("The Times of India: Latest").Page("The Times of India: Latest").Frame("Frame").WebElement("1 + 5 =")
validateObjectProperties x,"TOI Link"



Function validateObjectProperties(object,stepName)

   bResult = bResult & "<table border=1><tr><th>" & _
                    "Status</th><th>Property</th><th>Expected</th><th>Actual</th></tr>"

Set allProp = object.GetTOProperties
isPass=true
For i=0 to allProp.count -1
    expected = allProp(i).value
    actual = object.GetROProperty(allProp(i).name)

    If trim(expected) <> trim(actual) Then
        bResult = bResult & "<tr><td>" & _
                            "Fail" & "</td><td>" & _
                            allProp(i).name & "</td><td>" & _
                            expected & "</td><td>" & _
                            actual & "</td></tr>"
        isPass=false
    else
        bResult = bResult & "<tr><td>" & _
                            "Pass" & "</td><td>" & _
                            allProp(i).name & "</td><td>" & _
                            expected & "</td><td>" & _
                            actual & "</td></tr>"
    End If
Next



Set StepInfo = CreateObject("Scripting.Dictionary")
StepInfo("ViewType") = "Sell.Explorer.2"
StepInfo("DllIconIndex") = 209
StepInfo("DllIconSelIndex") = StepInfo("DllIconIndex")
StepInfo("DllPAth") = Environment.Value("ProductDir") & "\bin\ContextManager.dll"

If isPass Then
    StepInfo("Status") = micPass
else
    StepInfo("Status") = micFail
End If


StepInfo("NodeName") = stepName

StepInfo("StepHtmlInfo") = "<html>" & bResult & "</body></html>"

Reporter.LogEvent "User", StepInfo, Reporter.GetContext



End Function








Description Programming

'==Descriptive Programming language 'creating the common browser and page object  Set  myPage= browser( "creationtime:=0...