Wednesday, March 2, 2016

Creating testing Deliverables using TestComplete 2 - Test Log

TestComplete gives plenty of features to log the progress and significant outcomes of a test run using Logging in TestComplete.

To add to this functionality and have a customized deliverable at the end of every test run, I customized logging to log to a text file the progress and results from my test run.

Here is a VBScript sample.
'--------------------------------------------------------------------------------------
'LOG FILE UTILTIES
DIM theLogFile

FUNCTION Log_Start(ByVal msg_start, ByVal filePath)
  CALL lib_CreateFile(filePath)
  SET theLogFile = lib_OpenFileForWriting(filePath)
  theLogFile.WriteLine(now & vbTab & "INF" & vbTab & msg_start)
END FUNCTION

FUNCTION Log_End(ByVal msg_end)
  CALL Log_Write("INFO",msg_end)
  theLogFile .Close
END FUNCTION

FUNCTION Log_Write(ByVal Msg_Type, ByVal Msg)
  SELECT CASE UCASE(Msg_Type)
    CASE "INFO"
      theLogFile.WriteLine (now & vbTab & "INF" & vbTab & Msg)
    CASE "WARNING"
      theLogFile.WriteLine (now & vbTab & "WRN" & vbTab & Msg)
    CASE "ERROR"
      theLogFile.WriteLine (now &  vbTab & vbTab & "ERR" & vbTab & vbTab & Msg)   
    CASE "SUCCESS"
      theLogFile.WriteLine (now & vbTab & vbTab & "SCS" & vbTab & vbTab & Msg)
    CASE "BREAK"
      theLogFile.WriteLine (Msg)
    CASE ELSE
      Log.Error("Could not recognize message type:" & Msg_Type)   
  END SELECT
END FUNCTION

'--------------------------------------------------------------------------------------

The functions  lib_CreateFile and  lib_OpenFileForWriting are library functions I wrote that use the VBScript FileSystemObject to create a file and open the file for writing text respectively. Here is the documentation for that.

Here is how I use the function and how the log file looks like which I submit when asked, "What did/does your automation test test?"

FUNCTION Login
' Log into the website
 CALL Log_Write("INFO", "Logging into the webpage")
IF LoginSuccess THEN
 CALL Log_Write("SUCCESS", "Logging into the webpage")
ELSE
 CALL Log_Write("ERROR", "Logging failed")
END IF
END FUNCTION

I keep track of passed and failed test cases and log them too along with a final testing status at the end

Sample Log file created:

11/11/2015 8:34:39 AM    INF    LOGGING START : 11/11/2015 8:34:39 AM
11/11/2015 8:34:40 AM    INF    <<<<<<< TEST CASE >>>>>>>
11/11/2015 8:34:40 AM    INF    Test Identifier:     CardActivation_01-ActivateCard_ValidSrNo_FD
11/11/2015 8:34:40 AM    INF    >>>>>>> TEST CASE >>>>>>>
11/11/2015 8:35:38 AM    INF    STEP::Verifying if displayed page is :LoginHome
11/11/2015 8:35:41 AM        SCS        STEP::Verifying if displayed page is :LoginHome
11/11/2015 8:35:41 AM    INF    Access: Logout from the VTS website
11/11/2015 8:35:46 AM    INF    STEP::Verifying if displayed page is :Home
11/11/2015 8:35:48 AM        SCS        STEP::Verifying if displayed page is :Home
11/11/2015 8:35:48 AM        SCS        Access: Logout from the VTS website
11/11/2015 8:35:48 AM    INF    REPORT:##### CURRENT TEST CASE REPORT #####
11/11/2015 8:35:48 AM    INF    REPORT:Test Complete : True
11/11/2015 8:35:48 AM    INF    REPORT:Test Passed : True
11/11/2015 8:35:48 AM    INF    REPORT:# of Test Steps : 3
11/11/2015 8:35:48 AM    INF    REPORT:# of Test Points Passed : 3
11/11/2015 8:35:48 AM    INF    REPORT:# of Test Errors Found : 0
11/11/2015 8:35:48 AM    INF    REPORT:#####    FINAL TEST STATUS    #####
11/11/2015 8:35:48 AM    INF    REPORT:Test:CardActivation_01-ActivateCard_ValidSrNo_FD:COMPLETE ; PASSED.
11/11/2015 8:35:48 AM    INF    REPORT##### END TEST STATUS #####
'
'
'
11/11/2015 8:37:15 AM    INF    -----------------------------------------------------------------
11/11/2015 8:37:15 AM    INF    ##### FINAL #####
11/11/2015 8:37:15 AM    INF    ##### TEST REPORT #####
11/11/2015 8:37:15 AM    INF    REPORT:: Total Tests Run = 2
11/11/2015 8:37:15 AM    INF    REPORT:: Pass/Fail Ratio = 2/0
11/11/2015 8:37:15 AM    INF    REPORT:: Total Test Points = 8
11/11/2015 8:37:15 AM    INF   ######################################################
11/11/2015 8:37:15 AM    INF    LOGGING END : 11/11/2015 8:37:15 AM

Tuesday, March 1, 2016

Creating testing Deliverables using TestComplete 1 - Browser Images

Here is what I use to create deliverables after I finish an automated testing.

1) Having screenshots to submit for a web application.

I created this library routine Click_Picture that takes a picture of the entire browser screen(even parts that are not currently visible on the screen) and stores them at a desired location.

1) picNum starting from 1000 helps sort the pictures in the folder in the order it was taken. You can use/change/discard it as you desire.

2)  fldrPath_TestRun is a folder I create at the beginning of each test to save any files related to my current test run.

3) strPicName is a short descriptor for the picture that is being taken. A convention I use is 'B' means before and 'A' means after. e.g.
'A_Login' means after login
'B_SubmitForm' means before submitting the form.


 4) PagePicture is a method that TestComplete provides to capture a complete image of the tested object.

5) lib_FileCopy is any library function that can copy the picture from where TestComplete saves it to the desired folder.


DIM picNum: picNum = 1000

DIM fldrPath_TestRun

fldrPath_TestRun = "C:\TC11Projects\03012016_103216AM"

PUBLIC FUNCTION Save_PagePicture(ByVal strPicName)

  DIM src_Path, dest_Path
  picName = picNum & "_" & TRIM(strPicName)

  src_Path = Log.Picture(Sys.browser.Page("*").PagePicture, "Saving page picture")                                              
    dest_Path = fldrPath_TestRun & "\" & picName & ".png"                                               
    CALL lib_FileCopy(src_Path, dest_Path)
    Log.Message("SAVED PICTURE:")
    Log.Message(dest_Path)

END FUNCTION