Sunday, 30 September 2012

L7 - Handle multiple digits in Calculator

Problem statement : How to test calculator for multiple digits of different lengths.

We will use function to handle this type of situation as below:

Step 1.

Create a datatable as shown below:

Step2 . Write script as below:

x=1
DataTable.GetSheet dtlocalsheet
For x=1 to 2
DataTable.SetCurrentRow x
Window("Calculator").Activate
Window("Calculator").WinButton("C").Click
op1=DataTable.Value("Operand1",dtlocalsheet)
' Call function to click Operand 1
strcut(op1)
Window("Calculator").WinButton(DataTable.Value("Operator",dtlocalsheet)).Click
op2=DataTable.Value("Operand2",dtlocalsheet)
' Call function to click Operand 2
strcut(op2)
Window("Calculator").WinButton("=").Click
res=Window("Calculator").WinEdit("Edit").GetROProperty ("text")
ex_res=DataTable.Value("Expected_Result",dtlocalsheet) & ". "
If res=ex_res Then
reporter.ReportEvent micPass,"Passed","Succesfull" 
else
reporter.ReportEvent micFail,"Failed","Fail"
End If

Next

'Function to access value from data table and click one by one on calculator.
Function strcut(op)
    L=len(op)
For i=1 to L
t=mid(op,i,1)
Window("Calculator").WinButton(t).Click
Next
End Function