Wednesday 13 February 2013

Library Functions


        Function CloseAllBrowsers()
                 While browser("creationtime:=0").Exist
                           browser("creationtime:=0").Close
                Wend
        End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Function LaunchWebAppl(broption,url)
                On error resume next
                 broption = trim(broption)
                url = trim(url)
                arrayofval = array(broption,url)
                blankspaces = CheckSpaces(arrayofval)
                If  blankspaces <> 0 Then
                    LaunchWebAppl = "invalid input given"
                Exit function
                End If
                If err.number <> 0 Then
                LaunchWebAppl = err.number&space(2)&err.description
                err.clear
                Exit function
                End If
                systemutil.Run broption,url
                LaunchWebAppl = "pass"
        End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Function  CheckSpaces(arrayofval)
           counter = 0
           sindex = lbound(arrayofval)
           eindex = ubound(arrayofval)
           For range = sindex to eindex
                  rangeval = arrayofval(range)
                  If  rangeval = "" Then
                      counter = counter +1
                  End If
                      CheckSpaces = counter
          Next
          End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

          Function LogResult(stepname,stepdesc,statusflag)
             If  statusflag = "pass" Then
                 reporter.ReportEvent micPass,stepname,stepdesc
             else
                   reporter.ReportEvent micFail,stepname,stepdesc&statusflag
             End If
          End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function WaitForPage(brname,pgname,wtime)
               On error resume next

                brname = trim(brname)
                pgname = trim(pgname)
                wtime = trim(wtime)
                action = false
                sindex = 0
                eindex = wtime
                arrayofval = array(brname,pgname,wtime)
                    blankspaces = CheckSpaces(arrayofval)
                    If  blankspaces <> 0 Then
                        WaitForPage = "invalid input given"
                    Exit function
                    End If
                    If err.number <> 0  Then
                        WaitForPage = err.number&vbtab&err.description
                        err.clear
                    Exit function
                    End If
                    For index = sindex to eindex
                           pageexist = browser(brname).page(pgname).Exist
                           If  pageexist Then
                               action = true
                           End If
                    Next
                    If action Then
                        WaitForPage = "pass"
                    else
                        WaitForPage = "page is not appearing with the time range"&wtime&"seconds"
                    End If
            End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function ClickOperation(brname,pgname,objtype,objname)
                    On error resume next
                    brname = trim(brname)
                    pgname = trim(pgname)
                    objtype = trim(objtype)
                    objname = trim(objname)
                    action = false
                    arrayofval = array(brname,pgname,objtype,objname)
                    blankspaces = CheckSpaces(arrayofval)
                    If  blankspaces <> 0 Then
                        ClickOperation = "invalid input given"
                    Exit function
                    End If
                    If err.number <> 0  Then
                        ClickOperation = err.number&vbtab&err.description
                        err.clear
                    Exit function
                    End If
                    If  objtype = "webelement" Then
                        browser(brname).page(pgname).webelement(objname).Click
                        action = true
                    End If
                    If objtype = "image" Then
                        browser(brname).page(pgname).image(objname).Click
                        action = true
                    End If
                    If action Then
                        ClickOperation = "pass"
                    else
                        ClickOperation = "Given input objtype not supported"& objtype
                    End If
            End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function SelectOperation(brname,pgname,fname,objtype,objname,val)
                    On error resume next
                    brname = trim(brname)
                    pgname = trim(pgname)
                    fname = trim(fname)
                    objtype =  trim(objtype)
                    objname = trim(objname)
                    val = trim(val)
                    action = false
                    arrayofval = array(brname,pgname,fname,objtype,objname,val)
                    blankspaces = CheckSpaces(arrayofval)
                    If  blankspaces <> 0 Then
                        SelectOperation = "invalid input given"
                    Exit function
                    End If
                   
                    If  objtype = "weblist" Then
                        allitems = browser(brname).page(pgname).frame(fname).weblist(objname).GetROProperty("all items")
                        strloc = instr(allitems,val)
                        If strloc <> 0  Then
                            browser(brname).page(pgname).frame(fname).weblist(objname).Select val
                            action = true
                        End If
                    End If

                    If objtype = "webradiogroup" Then
                            browser(brname).page(pgname).frame(fname).webradiogroup(objname).Select val
                            action = true
                    End If

                    If action  Then
                            SelectOperation = "pass"
                    else
                            SelectOperation = "Given input objtype not supported"&objtype
                    End If

                    If err.number <> 0  Then
                        SelectOperation = err.number&vbtab&err.description
                        err.clear
                    Exit function
                    End If
            End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function SetOperation(brname,pgname,fname,objtype,objname,val)
                    On error resume next
                     brname = trim(brname)
                    pgname = trim(pgname)
                    fname = trim(fname)
                    objtype = trim(objtype)
                    objname = trim(objname)
                    val = trim(val)
                    action = false
                    arrayofval = array(brname,pgname,fname,objtype,objname,val)
                    blankspaces = CheckSpaces(arrayofval)
                    If  blankspaces <> 0 Then
                        SetOperation = "invalid input given"
                    Exit function
                    End If
                    If err.number <> 0  Then
                        SetOperation = err.number&vbtab&err.description
                        err.clear
                    Exit function
                    End If
                    If  objtype = "webedit" Then
                        browser(brname).page(pgname).frame(fname).webedit(objname).Set val
                        action = true
                    End If
                    If action Then
                            SetOperation = "pass"
                    else
                            SetOperation = "Given objtype not supported"& objtype
                    End If
            End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function Verification(brname,pgname,fname,objtype,objname,expval)
                        On error resume next
                        brname = trim(brname)
                        pgname = trim(pgname)
                        fname = trim(fname)
                        objtype = trim(objtype)
                        objname = trim(objname)
                        expval = trim(expval)
                        action = false
                    arrayofval = array(brname,pgname,fname,objtype,objname,expval)
                    blankspaces = CheckSpaces(arrayofval)
                    If  blankspaces <> 0 Then
                        verification = "invalid input given"
                    Exit function
                    End If
                    If err.number <> 0  Then
                        Verification = err.number&vbtab&err.description
                        err.clear
                    Exit function
                    End If
                    If  objtype = "weblist" Then
                        actval = browser(brname).page(pgname).frame(fname).weblist(objname).GetROProperty("value")
                        If actval = expval Then
                            action = true
                       
                        End If
                    End If

                    If  objtype = "webedit" Then
                        actval = browser(brname).page(pgname).frame(fname).webedit(objname).GetROProperty("value")
                        If actval = expval Then
                            action = true
                       
                        End If
                    End If

                    If  objtype = "webradiogroup" Then
                        actval = browser(brname).page(pgname).frame(fname).webradiogroup(objname).GetROProperty("value")
                        If actval = expval Then
                            action = true
                       
                        End If
                    End If

                    If action Then
                            Verification = "pass"
                    else
                            Verification = "Actval Expval not matched"
                    End If
            End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            Function ClickOperation1(brname,pgname,fname,objtype,objname)
                    On error resume next
                    brname = trim(brname)
                    pgname = trim(pgname)
                    objtype = trim(objtype)
                    objname = trim(objname)
                    fname = trim(fname)
                    action = false
                    arrayofval = array(brname,pgname,fname,objtype,objname)
                    blankspaces = CheckSpaces(arrayofval)
                    If  blankspaces <> 0 Then
                        ClickOperation = "invalid input given"
                    Exit function
                    End If
                    If err.number <> 0  Then
                        ClickOperation = err.number&vbtab&err.description
                        err.clear
                    Exit function
                    End If
                    If  objtype = "webelement" Then
                        browser(brname).page(pgname).webelement(objname).Click
                        action = true
                    End If
                    If objtype = "image" Then
                        browser(brname).page(pgname).image(objname).Click
                        action = true
                    End If
                    If action Then
                        ClickOperation1 = "pass"
                    else
                        ClickOperation1 = "Given input objtype not supported"& objtype
                    End If
            End Function

************************************************************************************




''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function launchwebapp(broption,url)                                                                                                            'LaunchWebApplication
                    On Error Resume Next
                    broption=trim(broption)
                    url=trim(url)
                    If  broption="" or url="" Then
                        launchwebapp="invalid input given"
                        'SystemUtil.Run "iexplore.exe","www.google.com"
                    else
                        SystemUtil.Run "iexplore.exe","www.policymagic.co.in"
                        launchwebapp="pass"
                    End If
                       
            End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function logResult(stepName,stepDesc,stepFlag)                                                                                        'LogResult
                         If  stepFlag = "pass" Then
                            reporter.ReportEvent micPass,stepName,stepdesc
                        else
                            reporter.ReportEvent micFail,stepName,stepDesc&stepFlag
                        End If
            End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function contextWrapper(arrayofelements)                                                                                                'Context Wrapper
               startIndex = Lbound(arrayofelements)
               endIndex = Ubound(arrayofelements)
               For index = startIndex to endIndex
                   arrayval = arrayofelements(index)
                   If  arrayval="" Then
                       counter = counter +1
                   End If
               Next
                        contextWrapper = counter
            End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function validip(bname,pname,objtype,objname,expval)
                On error resume next
                If objtype="weblist" Then
                    actval=browser(bname).page(pname).weblist(objname).GetROProperty("value")
                End If
                    If expval=actval and  strcomp(expval,actval,1)=0 Then                          'comparing actval and expval
'                                    scmp=strcomp(expval,actval,1)
'                                    If  scmp=0 Then
                                            validip="pass"
                                    else
                                            validip="fail"
    '                                End If
                                   
                    End If
'                               If err.number<>0 Then
'                                    validip=err.number&vbtab&err.description
'                                    err.clear
'                               End If

                    If  objtype="webedit" Then
                        actval=browser(bname).page(pname).webedit(objname).GetROProperty("value")
                    End If
                        If expval=actval and strcomp(expval,actval,1)=0 Then
                                        validip="pass"
                        else
                                        validip="fail"
                        End If
                        If err.number<>0 Then
                            validip=err.number&vbtab&err.description
                            err.clear
                        End If
                        Exit function
                        validip="pass"
                        End Function
                   
                    Function logResult(stepName,stepDesc,statusFlag)
                                If  statusFlag = "pass" Then
                                    Reporter.ReportEvent micPass,stepName,stepDesc
                                else
                                    Reporter.ReportEvent micFail,stepName,stepDesc
                                End If
                    End Function

                   

'                    statusFlag=validip("CII","CII","weblist","w1","20 Lacs")
'                    stepName="How much insurance do you want?"
'                    stepDesc="to compare actual and  exp value"
'                    result=logResult(stepName,stepDesc,statusFlag)
'
'                    statusFlag=validip("CII","CII","weblist","dd","5")
'                    stepName="Date Of Birth DD"
'                    stepDesc="to compare actual and  exp value"
'                    result=logResult(stepName,stepDesc,statusFlag)
'
'                    statusFlag=validip("CII","CII","webedit","name","ChAnDu")
'                    stepName="Enter Name TextBox"
'                    stepDesc="to compare actual and  exp value"
'                    result=logResult(stepName,stepDesc,statusFlag)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Function selectOperation(brn,pgn,objtype,objname,val)                                                                            'Select Operation
                        On error resume next
                        brn = trim(brn)
                        pgn = trim(pgn)
                        objtype = trim(objtype)
                        objname = trim(objname)
                        val = trim(val)
                        arrayofelements = array(brn,objtype,objname,val)
                        nooferrors = contextWrapper(arrayofelements)
                        If  nooferrors>0 Then
                            selectOperation = "invalid I/P's given"
                        Exit function
                        End If
                        If  objtype = "weblist" Then
                            verifyflag = browser(brn).page(pgn).weblist(objname).Exist
                            If  verifyflag Then
                                allitems = browser(brn).page(pgn).weblist(objname).GetROProperty("all items")
                                strlocation = instr(allitems,val)
                                If  strlocation > 0 Then
                                    browser(brn).page(pgn).weblist(objname).Select val
                                else
                                    selectOperation = "Item"&vbtab&val&vbtab&"is not found in list"
                           Exit Function
                                End If
                             End If
                                else
                                    selectOperation = "The objtype "&vbtab&objtype&"is not found in page"
                        End If
                                If err.number>0 Then
                                    selectOperation = err.number&err.description
                                    err.clear
                                 Exit function
                                End If
                                     selectOperation = "pass"
            End Function


           
           

No comments:

Post a Comment