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

Saturday, 5 November 2016

Excel Screen Shot File:

'Option Explicit
Sub createxls()
Dim ibmCurrentTerminal As IbmTerminal
Dim ibmCurrentScreen As IbmScreen
Dim hiddenTextEntry As String
Dim returnValue As Integer
Dim timeout As Integer
Dim waitText As String
timeout = 15000
Set ibmCurrentTerminal = ThisFrame.SelectedView.control
Set ibmCurrentScreen = ibmCurrentTerminal.Screen

On Error Resume Next
Dim Root, Filepath, Imagepath, Objxl, iCountwb, wb, oSnapxl, i
Dim osnapsheet, osnaprows, wbs, usedrow, pasteAt
Root = "C:\Users\sunshine\Desktop\Data\"
Filepath = Root & "log.xlsx"
Imagepath = Root + "ReflectionScreen.bmp"
'MsgBox Filepath
'MsgBox Imagepath
Set Objxl = GetObject(, "Excel.Application")
'Gives runtime Error 429 if object not found
'On Error GoTo 0
If Err = 429 Then
MsgBox "Excel Not Running", vbInformation, "Excel.Status"
Set Objxl = CreateObject("Excel.Application")

Else

'MsgBox Objxl.workbooks.Count

Set snapxl = Nothing
For Each wb In Objxl.workbooks
'*********************************************8
If wb.Name = "log.xlsx" Then
'Set oSnapxl = Objxl
Set snapxl = wb
'Set osnapsheet = oSnapxl.worksheets(1)
Set osnapsheet = snapxl.worksheets(1)
Exit For
End If
Next
Dim snapxlvalue

MsgBox snapxl
'*********************************************8
End If
one = snapxl

'If snapxl Is Nothing Or snapxl = Empty Then
If IsEmpty(snapxl) Then
Set osnapwb = Objxl.workbooks.add()

osnapwb.Visible = True
'Objxl.Visible = True

Set osnapsheet = osnapwb.worksheets(1)


End If

'MsgBox snapxl

usedrow = osnapsheet.usedrange.rows.Count
lcol = 1
For Each shp In osnapsheet.Shapes
        If shp.BottomRightCell.column > lcol Then _
        lcol = shp.BottomRightCell.column
        lrow = shp.BottomRightCell.row
        'MsgBox lcol & lrow
       
       
        Next
       
        With osnapsheet.Pictures.Insert("C:\Users\sunshine\Desktop\Data\ReflectionScreen.bmp")
        With .ShapeRange
        .LockAspectRatio = msoTrue
        .Width = 820
        .Height = 426
    End With
    .Left = osnapsheet.cells(lrow + 5, 3).Left
    .top = osnapsheet.cells(lrow + 5, 3).top
    .Placement = 1
    .PrintObject = True
End With

Objxl.DisplayAlerts = False
osnapsheet.SaveAs (Filepath)




'End If

End Sub


Sub main()

Dim ibmCurrentTerminal As IbmTerminal
Dim ibmCurrentScreen As IbmScreen
Dim hiddenTextEntry As String
Dim returnValue As Integer
Dim timeout As Integer
Dim waitText As String
timeout = 15000

Set ibmCurrentTerminal = ThisFrame.SelectedView.control
Set ibmCurrentScreen = ibmCurrentTerminal.Screen


createxls
'Openxls
 Wait 3000

ibmCurrentScreen.SendKeys "hi"
createxls

ibmCurrentScreen.SendKeys "bye"
createxlslast "C:\Users\sunshine\Desktop\Data\loglast.xlsx"



End Sub



'Option Explicit
Sub createxlslast(strfilepath2)
Dim ibmCurrentTerminal As IbmTerminal
Dim ibmCurrentScreen As IbmScreen
Dim hiddenTextEntry As String
Dim returnValue As Integer
Dim timeout As Integer
Dim waitText As String
timeout = 15000
Set ibmCurrentTerminal = ThisFrame.SelectedView.control
Set ibmCurrentScreen = ibmCurrentTerminal.Screen

On Error Resume Next
Dim Root, Filepath, Imagepath, Objxl, iCountwb, wb, oSnapxl, i
Dim osnapsheet, osnaprows, wbs, usedrow, pasteAt
Root = "C:\Users\sunshine\Desktop\Data\"
strfilepath2 = Root & "loglast.xlsx"
Imagepath = Root + "ReflectionScreen.bmp"
'MsgBox Filepath
'MsgBox Imagepath
Set Objxl = GetObject(, "Excel.Application")
'Gives runtime Error 429 if object not found
'On Error GoTo 0
If Err = 429 Then
MsgBox "Excel Not Running", vbInformation, "Excel.Status"
Set Objxl = CreateObject("Excel.Application")

Else

'MsgBox Objxl.workbooks.Count

Set snapxl = Nothing
For Each wb In Objxl.workbooks
'*********************************************8
If wb.Name = "log.xlsx" Then
'Set oSnapxl = Objxl
Set snapxl = wb
'Set osnapsheet = oSnapxl.worksheets(1)
Set osnapsheet = snapxl.worksheets(1)
Exit For
End If
Next
Dim snapxlvalue

MsgBox snapxl
'*********************************************8
End If
one = snapxl

'If snapxl Is Nothing Or snapxl = Empty Then
If IsEmpty(snapxl) Then
Set osnapwb = Objxl.workbooks.add()

'osnapwb.Visible = True
Objxl.Visible = True

Set osnapsheet = osnapwb.worksheets(1)


End If

'MsgBox snapxl

usedrow = osnapsheet.usedrange.rows.Count
lcol = 1
For Each shp In osnapsheet.Shapes
        If shp.BottomRightCell.column > lcol Then _
        lcol = shp.BottomRightCell.column
        lrow = shp.BottomRightCell.row
        'MsgBox lcol & lrow
       
       
        Next
       
        With osnapsheet.Pictures.Insert("C:\Users\sunshine\Desktop\Data\ReflectionScreen.bmp")
        With .ShapeRange
        .LockAspectRatio = msoTrue
        .Width = 820
        .Height = 426
    End With
    .Left = osnapsheet.cells(lrow + 5, 3).Left
    .top = osnapsheet.cells(lrow + 5, 3).top
    .Placement = 1
    .PrintObject = True
End With

Objxl.DisplayAlerts = False
osnapsheet.SaveAs (strfilepath2)
 Objxl.Quit




'End If

End Sub

Thursday, 15 September 2016

VBScript: Function Returning Array



Function Getdata()

Dim a()
strt = "sumit"
strt2 = "raut"
a = Array(strt, strt2)

Getdata = a()


End Function

Sub main()


Dim oExcel, oWB, oSheet, setVal
Set oExcel = CreateObject("Excel.Application")
Set oWB = oExcel.Workbooks.Open("D:\Macrowork\Call from Sub.xlsx")
Set oSheet = oWB.WorkSheets("data")
oExcel.Visible = True
Dim Arr1()

rowcount = oSheet.usedrange.rows.Count

For r = 2 To rowcount Step 1

Arr1 = Getdata
oSheet.cells(r, 4) = Arr1(0)
oSheet.cells(r, 5) = Arr1(1)

Next

oWB.Save
Set oExcel = Nothing

End Sub


Sunday, 11 September 2016

MSWord: Posting Images in Word Document via Vbscript

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

'Set objRang = objDoc.Range()
Set objShape = objDoc.inlineShapes

''Add Picture to word file
fname="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"
fname2="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg"
objShape.AddPicture (fname)
objWord.Selection.MoveDown 1,0
objWord.Selection.TypeParagraph()

objShape.AddPicture (fname2)
objWord.Selection.MoveDown 1,0
objWord.Selection.TypeParagraph()

''Save Word File
objDoc.saveas("C:\Users\sunshine\Desktop\Test.docx")

Friday, 9 September 2016

VBscript:Sorting Numbers in Descending Order

dim a
a=array(1,5,6,7,8,9,0)
ub=ubound(a)
lb=lbound(a)

For i=lb to ub-1 Step 1



   For j=lb+i  to ub  Step 1
        if a(i)<a(j) then
         temp=a(j)
         a(j)=a(i)
         a(i)=temp
        end if
    Next


Next


'Print Sorted Array

for i=lbound(a) to ubound(a) Step 1
msgbox a(i)

Next







Saturday, 3 September 2016

Vbscript:Skipping Iteration in a loop

function writefail(r)
oSheet.cells(r,5).value="INVALID as P"

End function


Dim oExcel, oWB, oSheet, getVal
Set oExcel=CreateObject("Excel.Application")
Set oWB=oExcel.Workbooks.Open("C:\Users\sunshine\Desktop\Macro\Data.xlsx")
Set oSheet=oWB.WorkSheets("Sheet1")
oExcel.Visible=TRUE

for r =2 to 14

status=oSheet.cells(r,4).value

if status="P" then oSheet.cells(r,5).value="INVALID as P"

'if status="P" then writefail(r)
do

'if status="P" then _
'writefail(r)
'exit do



'if status="P" then _
'oSheet.cells(r,5).value="INVALID as P" exit do
'loop while false

if status="P" then exit do

if status<>"P" then _
oSheet.cells(r,6).value="V1"
oSheet.cells(r,7).value="V2"
'oSheet.cells(r,5).value="VALID"
exit do
'loop while false
loop while r<6

Next

oWB.save
set oExcel=nothing




Rest Assured Chectsheet

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