Monday, 16 October 2017

VBscript: Finding Occurance of Each Character in the string

Dim a()
Dim strtext
'Provide the text 
strtext="this is sparta"

'Create An Array with each letter of the text
ReDim a((len(strtext)-1))
For i=1 to len(strtext) Step 1
a(i-1)=mid(strtext,i,1)
Next

'Create Dictionary Object to store unique values of the text

Set odic=CreateObject("Scripting.Dictionary")
'ReDim a((len(strtext)-1))
For i=1 to len(strtext) Step 1

If NOT odic.Exists(mid(strtext,i,1)) Then
    odic.add (mid(strtext,i,1)),"i"
End If
   
Next

alluniquekeys=odic.Keys

'Compare unique items with each item present in the array and increase the counter when there is a match
For i = 0 To ubound(alluniquekeys) Step 1
    count=0
    For j = 0 To ubound(a) Step 1
       
        If alluniquekeys(i)=a(j) Then
        count=count+1
        End If
    Next
    print " "&a(i)& "appears "&count&"times"
Next




REM===> OUTPUT
 t appears 2 times
 h appears 1 times
 i appears 2 times
 s appears 3 times
   appears 2 times
 p appears 1 times
 a appears 2 times
 r appears 1 times

Saturday, 14 October 2017

UFT: Connecting to SQL SERVER with ADODB

Set con=CreateObject("ADODB.connection")
Set Rs=CreateObject("ADODB.Recordset")

On Error Resume next
con.Open "Provider = sqloledb.1;Server=SUNSHINE-PC;Database=northwind;User Id=sa;Password=password;"

rs.open "select * from [dbo].[Categories]",con

While rs.EOF<>True
 
msgbox rs.Fields.Item(0)&" "&rs.Fields.Item(1)


rs.MoveNext
   
   
Wend

If Err.Num<>0 Then
   
  msgbox "Something Wrong with ADOBDB"
End If

rs.Close
con.Close

Set rs=nothing
Set con=nothing

RegisterUserFunc in UFT


RegisterUserFunc "WebEdit""fnWebEditSet""fnWebEditSet"
RegisterUserFunc "WebEdit""fnWebEditSetSecure""fnWebEditSetSecure"


Function fnWebEditSet(objControl,objControlText)

If objControl.Exist(10) Then


           If objControl.GetRoProperty("Disabled")=0 Then
           objControl.Set objControlText
              
           Reporter.ReportEvent micPass,"WebEdit Set",""&objControl.ToString()&" "&"value captured"
              
           Else
           Reporter.ReportEvent micFail,"WebEdit Set",""&objControl.ToString()&" "&"is in disabled state"
              
           End If

Else
Reporter.ReportEvent micFail,"WebEdit Check",""&objControl.ToString()&" "&" does not exist"
End If


End Function





Function fnWebEditSetSecure(objControl,objControlText)

If objControl.Exist(10) Then


           If objControl.GetRoProperty("Disabled")=0 Then
           objControl.SetSecure objControlText
              
           Reporter.ReportEvent micPass,"WebEdit Set",""&objControl.ToString()&" "&"value captured"
              
           Else
           Reporter.ReportEvent micFail,"WebEdit Set",""&objControl.ToString()&" "&"is in disabled state"
              
           End If






Else

Reporter.ReportEvent micFail,"WebEdit Check",""&objControl.ToString()&" "&" does not exist"

End If


End Function



'Browser("Buy Women Clothing Online:").Page("Buy Women Clothing Online:").WebEdit("edsrchword").fnWebEditSet "sumit"

Browser("Buy Women Clothing Online:").Page("Buy Women Clothing Online:").WebEdit("edsrchword").fnWebEditSetSecure "x"

Friday, 3 March 2017

InProcess: Finding Particular element on Webpage

'Function to Find Particular Object Type

'Option Explicit

Function UDF_VerifyItem(objpage,micclass,michtmltag,expectedvalue)

Dim Odesc,objallitems,i
Set Odesc=Description.Create
Odesc("micclass").value=micclass
Odesc("html tag").value=michtmltag

Set objallitems=objpage.ChildObjects(Odesc)

'msgbox objallitems.count
'msgbox expectedvalue

For i = 1 To objallitems.count Step 1

'print objallitems(i).GetROProperty("innertext")
If objallitems(i).Getroproperty("innetext")=expectedvalue Then
            UDF_VerifyItem=True
           
           
            Exit For
            Else
            UDF_VerifyItem=False
            End If
Next
End Function

Dim objpage
Set objpage=Browser("Michael Clark learns to").Page("Michael Clark learns to")

'Browser("Michael Clark learns to").Page("Michael Clark learns to").ChildObjects(Odesc)
'

'Searchtext= UDF_VerifyItem(objpage,micclass,michtmltag,expectedvalue)

Dim expectedvalue
expectedvalue="Michael Clark learns.*"
Searchtext= UDF_VerifyItem(objpage,"WebElement","H1",expectedvalue)

                If Searchtext=True Then
                    Reporter.ReportEvent micPass,"Search For  "&expectedvalue ,"Search Passed"
               
                Else
                Reporter.ReportEvent micFail,"Search For  "&expectedvalue ,"Search Failed"
                End If

Descriptive Programming for Checkpoint for Webtable

Function Created Using Descriptive Programming for Checkpoint:


Function VerifyTextPresentOnPage(byval objPage, byval Textvalue)
On error resume next

    'Create child object description
    Set childobjdes = Description.Create()
    childobjdes("micclass").value="WebTable"
    childobjdes("html tag").value=".*[A-Za-z0-9].*"
   
    'Create ALL child object    
    set allobj = objpage.ChildObjects(childobjdes)
   
    'get all  web element  outer text from web page and store in output variable    
    For i=1 to allobj.count-1
        output= output & "-" & allobj.Item(i).GetROProperty("outertext")
        print output
       
    Next
   
    'now compare the value if the given value find or not
    If instr(1,lcase(output),lcase(Textvalue)) > 0  Then
        'return true if found
        VerifyTextPresentOnPage= True
    Else
        'return true if  not found
        VerifyTextPresentOnPage= False
    End If
    On Error GoTo 0
End Function

Saturday, 18 February 2017

UFT: Entering Data in WEBELEMENT

Dim owebele

Set owebele=description.Create
owebele("micclass").value="WebElement"
owebele("html id").value="lbl_txt"
'owebele("html tag")="SPAN"

set ole=Browser("Rediffmail Free Unlimited").Page("Rediffmail Free Unlimited").ChildObjects(owebele)

msgbox ole.count

If ole.count=1 Then
ole(0).object.innertext="+1"
   
End If

Monday, 6 February 2017

WaitProperty Method with Regular Expression



Description

Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

Important Information

Tip: This method is useful for test run synchronization. Unlike the Exist method, the WaitProperty method enables you to synchronize the test run based on a specific object property. For example, you can instruct QuickTest to wait for a particular string to appear in a static text control:
' Wait up to 30 seconds for the string "Ready" to appear in the "Status" text control.
Window("Test").Static("Status:").WaitProperty "text", "Ready", 30000

You can also use comparison objects to perform more complex value comparisons. For example, you can instruct QuickTest to wait until a specific property value is greater than the specified value.
An example of the syntax required when using a comparison object is: Object.WaitProperty "items count",micGreaterThan(8)
The following comparison objects can be used:
  • micGreaterThan: Greater than; Specifies that QuickTest waits until the property value is greater than the specified value.
  • micLessThan: Less than; Specifies that QuickTest waits until the property value is less than the specified value.
  • micGreaterThanOrEqual: Greater than or equal to; Specifies that QuickTest waits until the property value is greater than or equal to the specified value.
  • micLessThanOrEqual: Less than or equal to; Specifies that QuickTest waits until the property value is less than or equal to the specified value.
  • micNotEqual: Not equal to; Specifies that QuickTest waits until the property value is not equal to the specified value.
  • micRegExpMatch: Regular expression; Specifies that QuickTest waits until the property value achieves a regular expression match with the specified value. Regular expressions are case-sensitive and must match exactly. For example, 'E.*h' matches 'Earth' but not 'The Earth' or 'earth'.
When the types of the expected value and actual value do not match, the comparisons are performed as follows (in this order):
  • Empty values: Empty values may be an uninitialized variable or field (which returns TRUE for the IsNull function in VBscript) or initialized to an empty value (which returns TRUE for the IsEmpty function is VBscript). When trying to compare two arguments when at least one is an empty value, the comparison assumes equality for two uninitialized arguments and for two empty arguments. Any other combination is considered unequal.
    For example:
    dim vEmpty
    Object.WaitProperty “text”,micNotEqual
    (vEmpty) 
    will not wait for the timeout (because the 'text' property value is an empty string and the argument passed to micNotEqual is an empty value, and so micNotEqual finds them not equal and returns TRUE).
  • String values: When trying to compare a string value with non-string value, the string value is converted to the non-string type and then compared. If the string value cannot be converted to the non-string type, the comparison assumes the values are not equal.
    For example:
    Object.WaitProperty “text”,micGreaterThan(8) will not wait for the timeout if the 'text' property value is '16' (because micGreaterThan finds 16 to be greater than 8 and returns TRUE), but will wait if the 'text' property value is 'a' (because 'a' cannot be converted to a number).
  • Boolean values: When trying to compare a Boolean value with non-boolean value, the non-boolean value is converted to a boolean value and then compared. The conversion method assumes that any integer value other than '0' is TRUE, and that '0' alone is FALSE. If the conversion fails to produce a boolean value (for example, if the value is 'abc'), the comparison result will be FALSE (note that for the WaitProperty method this result would instruct QuickTest to keep waiting). If the conversion succeeds, the method compares the two boolean values according to the comparison logic.
  • Other value types: When other value types do not match, they are compared under the assumption that different types are not equal (nor greater than or less than each other).

Syntax

object.WaitProperty (PropertyName, PropertyValue, [TimeOut])

Syntax Details

Argument Description
object A test object of type WebList.
PropertyName Required. A String value. The name of the property whose value is checked. The available properties are listed in the Identification Properties page under the Properties section for each test object.
PropertyValue Required. A Variant value. The value to be achieved before continuing to the next step. You can either use a simple value or you can use a comparison object together with the value to perform more complex comparisons.
TimeOut Optional. A Long value. The time, in milliseconds, after which QuickTest continues to the next step if the specified value is not achieved. If no value is specified, QuickTest uses the time set in the Object Synchronization Timeout option in the Run pane of the Test Settings dialog box.

Return Type

A Boolean value.  Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value. A FALSE return value does not indicate a failed step.

Example

Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...