Wednesday, June 11, 2008

VisualTest - Radio button functions

Last week, I interviewed one guy and he is using VisualTest in his company. I'm surprised. IBM - Rational VisualTest development was stopped about seven years ago and Still people are using the tool. Here I have given code snippet for Handling Radio buttons in the browser.

Sample VisualTest Code:



'--------------------------------
' Method : WebClickRadio
' Author : T.Palani Selvam
' Purpose : Selects the Radio Button to the given value.
' Parameters: sContext - String, Contains web context
' sForm - String, contains information about Form
' sRadioButton - String, Contains name of control
' sRadioValue - String, Contains value of control
' Returns : Returns Integer, either TRUE or FALSE
' Caller : WebHandleClick(sContext, sForm, sElement ,sElementValue , sElementType)
' Calls : - Nil -
'-----------------------------
Function WebClickRadio(sContext As String, sForm As String, sRadioButton As String,sRadioValue As String) As Integer
Dim iIndex as Integer, iCount As Integer
Dim sControl As String, sTemp As String
Dim lItem As Long, lState As Long

WebClickRadio = FALSE
If (WebRadioExists(sContext,sForm,sRadioButton)) Then
If (Instr(LCase(sRadioValue),"check") = 1 OR Instr(LCase(sRadioValue),"select") = 1) Then
lState = SELECTED
Else
lState = NOTSELECTED
End IF

If (Instr(sRadioButton,"@") = 0) Then
iCount = WebInputelementCount(sContext, sForm,"radio")
For iIndex= 1 To iCount
lItem = iIndex
sControl = Str$(WebInputElementProperty(sContext,sForm, _ord(lItem), "radio", "name"))
sTemp = Str$(WebInputElementProperty(sContext,sForm, _ord(lItem), "radio", "value"))

Print sControl,sTemp

If ((Instr(Lcase(sRadioButton),lcase(sControl)) <> 0) AND (Lcase(Trim(sRadioValue)) = lcase(sTemp))) Then
WebRadioSetState(sContext, sForm, _ord(lItem), lState)
'WebInputElementSetState(sContext,sForm, _ord(lItem), "radio", SELECTED)
WebClickRadio = TRUE
LogWrite("Successfully set the state for radio button " + sRadioButton, 1)
Exit Function
End IF
Next iIndex
LogWrite("Failure to set the state for radio button " + sRadioButton, 1)
Else
WebRadioSetState(sContext, sForm,sRadioButton, lState)
WebClickRadio = TRUE
LogWrite("Successfully set the state for radio button " + sRadioButton, 1)
End IF
Else
LogWrite("Doesn't exist radio button " + sRadioButton, 1)
End IF
End Function


Sample Visual Test Code: Checks the selected Radio Button to the given value


'---------------------------
' Method : WebRadioCheck
' Author : T.Palani Selvam
' Purpose : Checks the selected Radio Button to the given value.
' Parameters: sContext - String, Contains web context
' sForm - String, contains information about Form
' sRadioButton - String, Contains name of control
' sRadioValue - String, Contains value of control
' Returns : Returns Integer, either TRUE or FALSE
' Caller : WebHandleCheck(sContext, sForm, sElement ,sElementValue , sElementType)
' Calls : - Nil -
'--------------------------
Function WebRadioCheck(sContext As String, sForm As String, sRadioButton As String,sRadioValue As String) As Integer
Dim iValue As Integer, iState AS Integer

WebRadioCheck = FALSE
If (WebRadioExists(sContext,sForm,sRadioButton)) Then
If (Instr(LCase(sRadioValue),"check") = 1 OR Instr(LCase(sRadioValue),"select") = 1) Then
iState = SELECTED
Else
iState = NOTSELECTED
End IF

iValue = WebRadioState(sContext, sForm, sRadioButton)
If (iState = iValue) Then
LogWrite("Successful to check Radio " + sRadioButton,1)
WebRadioCheck = TRUE
Else
LogWrite("Failure to check Radio " + sRadioButton ,1)
End IF
Else
LogWrite("Doesn't exist radio button " + sRadioButton, 1)
End IF

End Function

No comments: