Tuesday, December 30, 2008

QTP : Checking the current displayed window

In most of the case its necessory to check the current displayed or activated window with the expected window or dialog.
 So below is the code to get the Current activated window name

sActiveWindow = Window("ForeGround:=True").GetROProperty("Title")

With the above line sActiveWindow will get the current active window name.

For Example consider we are writing Test cases on calculator.

So expected window is calculator, the commands will be

sActiveWindow = Window("ForeGround:=True").GetROProperty("Title")
sActiveExplorerArray=Split(sActiveWindow," ")
iActiveExplorerArrayElement=Ubound(sActiveExplorerArray)
sActiveExplorer=sActiveExplorerArray(iActiveExplorerArrayElement)

sActiveExplorer will have the string "Calculator"

Check for that

If Lcase(sActiveExplorer)="calculator" then

' Test case is PASS

Else

' Test case is FAIL

End If

Now put every thing Together

sActiveWindow = Window("ForeGround:=True").GetROProperty("Title")
sActiveExplorerArray=Split(sActiveWindow," ")
iActiveExplorerArrayElement=Ubound(sActiveExplorerArray)
sActiveExplorer=sActiveExplorerArray(iActiveExplorerArrayElement)

If Lcase(sActiveExplorer)="calculator" then

' Test case is PASS

Else

' Test case is FAIL

End If


Next level of coding is getting the Expected window Name from Data table 

Code for that is :
iRowNumber=1
DataTable.SetCurrentRow(iRowNumber)
sGetDatatablevalue=DataTable.Value(,dtLocalSheet)

Now we can have an function to check the window name for us. This function will take  column name, row Number as parameters and Return PASS or FAIL

Public Checkwindow(Col_Name,RowNumber)

' Get the current Activated window
sActiveWindow = Window("ForeGround:=True").GetROProperty("Title")
sActiveExplorerArray=Split(sActiveWindow," ")
iActiveExplorerArrayElement=Ubound(sActiveExplorerArray)
sActiveExplorer=sActiveExplorerArray(iActiveExplorerArrayElement)

'Get the Expected Window Name from Data Table
DataTable.SetCurrentRow(RowNumber)
sGetDatatablevalue=DataTable.Value(Col_Name,dtLocalSheet)

'Compare Current and Expected
If Lcase(sActiveExplorer)=Lcase(sGetDatatablevalue) then

' Test case is PASS
Checkwindow="PASS"
Else

' Test case is FAIL
Checkwindow="FAIL"
End If


End Function

Call this function starting of each Test case

If you have any comments please let me know.


No comments: