Friday, February 4, 2011

Generic Function for button, Edit box, Combo box and Radio button

'########## button ##############
Function buttonclick(obutton)
     sobjname = obutton.tostring
     sstepname = "Buttonclick"
     bexists = obutton.Exist(0)

     If bexists Then
              smsg = sobjname&" Exists"
              reporter.ReportEvent micPass,sstepname,smsg
     else
              smsg = sobjname&" does not Exists"
               reporter.ReportEvent micFail,sstepname,smsg
               Exittest
     End If

     bdisabled = obutton.getroproperty("disabled")
     If bdisabled = 0 Then
         smsg = sobjname&" is enabled"
         reporter.ReportEvent micPass,sstepname,smsg
     else
         smsg = sobjname&" is disabled"
         reporter.ReportEvent micFail,sstepname,smsg
         Exittest
     End If

     smsg = "clicking on "&sobjname
     reporter.ReportEvent micPass,sstepname,smsg
     obutton.click
End Function

' ########## Edit box ###########
Function edit_set(oedit,sinputtext)
     sobjname = oedit.tostring
     sstepname = "EditSet"
     bexists = oedit.Exist(0)
     If bexists Then
          smsg = sobjname&" Exists"
          reporter.ReportEvent micPass,sstepname,smsg
    else
          smsg = sobjname&" does not Exists"
          reporter.ReportEvent micFail,sstepname,smsg
          Exittest
    End If

    bdisabled = oedit.getroproperty("disabled")
    If bdisabled = 0 Then
        smsg = sobjname&" is enabled"
        reporter.ReportEvent micPass,sstepname,smsg
    else
        smsg = sobjname&" is disabled"
        reporter.ReportEvent micFail,sstepname,smsg
        Exittest
    End If

    smsg = "Entering "&sinputtext&" into "&sobjname
    reporter.ReportEvent micPass,sstepname,smsg
    oedit.set sinputtext
End Function

' ########## Combo box ###########
Function itemselect(olist,sitemtoselect)
      sobjname = olist.tostring
      sstepname = "itemselect"
      bexists = olist.Exist(0)
      If bexists Then
            smsg = sobjname&" Exists"
            reporter.ReportEvent micPass,sstepname,smsg
      else
            smsg = sobjname&" does not Exists"
            reporter.ReportEvent micFail,sstepname,smsg
            Exittest
      End If
      bdisabled = olist.getroproperty("disabled")
      If bdisabled = 0 Then
           smsg = sobjname&" is enabled"
           reporter.ReportEvent micPass,sstepname,smsg
      else
            smsg = sobjname&" is disabled"
            reporter.ReportEvent micFail,sstepname,smsg
            Exittest
      End If
      bitemfound = false
      sallitems = olist.getroproperty("all items")
      allitems = split(sallitems,";")
      For i = 0 to ubound(allitems)
             av = allitems(i)
             If lcase(av) = lcase(sitemtoselect) Then
                 bitemfound = true
                 Exit for
             End If
      Next
      If bitemfound Then
         smsg = "Item "&sitemtoselect&" is found in "&sobjname
         Reporter.ReportEvent micPass,sstepname,smsg
      Else
           smsg = "Item "&sitemtoselect&" is not found in "&sobjname
           Reporter.ReportEvent micPass,sstepname,smsg
           Exittest
      End If
      smsg = "Selecting "&sitemtoselect&" from "&sobjname
      reporter.ReportEvent micPass,sstepname,smsg
      olist.select sitemtoselect

End Function

' ########## Radio Button ###########
Function selectRadioBtn(orbgroup,srbtoselect)
      sobjname = orbgroup.tostring
      sstepname = "selectRadioBtn"
      bexists = orbgroup.Exist(0)
      If bexists Then
          smsg = sobjname&" Exists"
           reporter.ReportEvent micPass,sstepname,smsg
      else
           smsg = sobjname&" does not Exists"
           reporter.ReportEvent micFail,sstepname,smsg
           Exittest
      End If
      bdisabled = orbgroup.getroproperty("disabled")
      If bdisabled = 0 Then
         smsg = sobjname&" is enabled"
          reporter.ReportEvent micPass,sstepname,smsg
     else
          smsg = sobjname&" is disabled"
          reporter.ReportEvent micFail,sstepname,smsg
          Exittest
      End If
      bitemfound = false
      sallitems = orbgroup.getroproperty("all items")
      allitems = split(sallitems,";")
      For i = 0 to ubound(allitems)
           av = allitems(i)
          If lcase(av) = lcase(srbtoselect) Then
                 bitemfound = true
                 Exit for
         End If
      Next
      If bitemfound Then
           smsg = "Item "&srbtoselect&" is found in "&sobjname
           Reporter.ReportEvent micPass,sstepname,smsg
      Else
           smsg = "Item "&srbtoselect&" is not found in "&sobjname
           Reporter.ReportEvent micPass,sstepname,smsg
           Exittest
      End If
       smsg = "Selecting "&srbtoselect&" from "&sobjname
       reporter.ReportEvent micPass,sstepname,smsg
       orbgroup.select srbtoselect
End Function

No comments: