08 May 2011

Automating Nokia Symbian OS using QTP: Basic Application Testing

Over the weekend as I was getting bored, I thought of giving this idea of automating the Symbian^3 OS of my Nokia N8 a shot. The test script is not bad if you are actually looking to navigate through an application within the OS. This test script is based out on an application called Remote Professional. This application present the exact interface of the connected phone on your computer screen. This application also provides a few other functionalities like, triggering some of the hardware buttons on the phone.


Technically, the script tries to unlock the phone and sends a SMS from the phone. The possibilities look great if you are a mobile developer working on a Symbian OS and looking to create a basic test suite for your application. Remote Professional runs on Symbian^3, S60 5th & 3rd Edition, Series 60 v1/v2 or UIQ 3 phones and is compatible with Windows 2000, XP, Vista and Windows 7.

The test script uses QTP's OCR functionality which works like a charm. The functions "GetVisibleText" and "ClickOnText" have been used extensively in the script. "GetVisibleText" retrieves the visible text on the associated object and  "ClickOnText" actually goes and click what ever text you want to click on an object area.

Download Test Script Source

'#######################################################################################
'Test :   Automating Nokia Symbian^3 OS Basic Application Testing
'Addin:   None Required
'Support Software:  Remote S60 Professional , Window Vista, QTP 9.5
'Link:  http://mobileways.de/products/remotepro/remote-professional/
'#######################################################################################

'=======================================================================================
' Function   ClickText       
'Parameter   sString       Text keyword to be clicked    
'Parameter  oTestObj     Object on which the text is to be found
'Parameter  oExpectedObj    Expected Object after the text is clicked
'Return    Exits test on failure
'=======================================================================================
Function ClickText (ByVal sString, ByVal oTestObj, ByVal oExpectedObj)
  On Error Resume Next
  t = Timer + 30
  Do While Not VerifyObjectExists(oExpectedObj)
    oTestObj.ClickOnText sString
    If  Timer>t Then
      Reporter.ReportEvent micFail, "Executing function ClickText.", "Failed to execute function."
      ExitTest
    End If
  Loop
  On Error GoTo 0
End Function

'=======================================================================================
' Function   VerifyObjectExists       Test the existence of an object
'Parameter   oTestObj       Object to be tested  
'Return    True if success else False
'=======================================================================================
Function VerifyObjectExists (ByVal oTestObj)
  If oTestObj.Exist(5) Then
    VerifyObjectExists = True
  Else
    VerifyObjectExists = False
  End If
End Function

'=======================================================================================
' Function   VerifyVisibleText       
'Parameter   sVerify       Text keyword to be verified
'Parameter  oTestObj     Object on which the text is to be found
'Parameter  intDelay        Timeout before function fails
'Return    True if success else False
'=======================================================================================
Function VerifyVisibleText( ByVal sVerify, ByVal oTestObj, ByVal intDelay)
  Dim sRcvText, t, bFlag
  sRcvText = "  "
  bFlag = True
  t = Timer + intDelay
  Do While Not CStr(InStr(sRcvText, sVerify)>0)
     Window("Remote Professional").Activate
     sRcvText = oTestObj.GetVisibleText
     Print sRcvText
     Wait 0, 100
     If  Timer>t Then
       'Reporter.ReportEvent micFail, "Executing function VerifyVisibleText.", "Failed to verify text '" & sVerify
       bFlag = False
       Exit Do
     End If
  Loop
  VerifyVisibleText = bFlag
End Function

'=======================================================================================
'Function UnlockPhone   Function that unlocks the phone if found locked
'Parameter  intDelay   Timeout
'Return           Exits test if Failed
'=======================================================================================
Function UnlockPhone (ByVal intDelay)
  Dim t, bFlag
  bFlag = True
  If Not Window("Remote Professional").Window("SideToolBar").Exist(2) Then
    ClickText "Keys", Window("Remote Professional").WinToolbar("ToolBar"), Window("Remote Professional").Window("SideToolBar")
  End If
  
  t = Timer + intDelay
  
  Do While Not VerifyVisibleText("nlock", Window("Remote Professional").WinObject("Display Panel"), 5)
    Window("Remote Professional").Window("SideToolBar").WinToolbar("Toolbar").ClickOnText "Menu"
    Print "Clicked" & t
    Wait 0, 500
    If Timer>t Then
      Reporter.ReportEvent micFail, "Executing function UnlockPhone.", "Failed to execute function."
      ExitTest
    End If
  Loop

  t = Timer + 30

  On Error Resume Next
  Do While VerifyVisibleText("nlock", Window("Remote Professional").WinObject("Display Panel"), 5)
    Print "UNlocking"
    Window("Remote Professional").WinObject("Display Panel").ClickOnText "nlock"
    If Timer>t Then
      Reporter.ReportEvent micFail, "Executing function UnlockPhone - After Unlocked.", "Failed to execute function."
      bFlag = False
      Exit Do
    End If
  Loop
  On Error GoTo 0
  UnlockPhone = bFlag
End Function

'=======================================================================================
'Function UnlockPhone   Scrolls Down the menu
'Return           Exits test if Failed
'=======================================================================================
Function SymScrollDown(ByVal sString)
  Dim t 
  t = Timer + 45
  Do While Not VerifyVisibleText(sString, Window("Remote Professional").WinObject("Display Panel"), 10)
    Print "test"
    Window("Remote Professional").WinObject("Display Panel").Type micDwn
    If Timer>t Then
      Reporter.ReportEvent micFail, "Executing function SymScrollDown", "Failed to execute function."
    End If
  Loop
End Function

'=======================================================================================
'Function UnlockPhone     Scrolls Up the Menu
'Return           Exits test if Failed
'=======================================================================================
Function SymScrollUp(ByVal sString)
  Dim t 
  t = Timer + 45
  Do While Not VerifyVisibleText(sString, Window("Remote Professional").WinObject("Display Panel"), 10)
    Window("Remote Professional").WinObject("Display Panel").Type micUp
    If Timer>t Then
      Reporter.ReportEvent micFail, "Executing function SymScrollDown", "Failed to execute function."
    End If
  Loop
End Function

'=======================================================================================


'=======================================================================================
'Test Execution Code
'=======================================================================================

UnlockPhone(30) 
SymScrollUp "Messaging"
Window("Remote Professional").WinObject("Display Panel").ClickOnText "Messaging"
Wait 2
Window("Remote Professional").WinObject("Display Panel").ClickOnText "New message"
Wait 5
Window("Remote Professional").WinObject("Display Panel").Type "Test123"
Window("Remote Professional").WinObject("Display Panel").Type micDwn
Window("Remote Professional").WinObject("Display Panel").Type "This is a test."
Window("Remote Professional").WinObject("Display Panel").ClickOnText "Options"
Wait 3
Window("Remote Professional").WinObject("Display Panel").ClickOnText "Send"


2 comments:

  1. Take a look at RealMobileTM, Conflair's patent-pending method for automating tests for mobile devices: http://www.youtube.com/watch?v=vkpBUZpKz68
    See also http://www.conflair.com

    ReplyDelete
  2. Thanks for sharing.

    It's very useful for all.

    QTPbook

    ReplyDelete