Wednesday, May 11, 2011

Automation Framework & It's Type


Friends, one of my regular blog reader asked “What exactly Automation framework is”?   She was new to automation and while goggling the same she was confused the basic definition.  So I thought to share my understanding in simple words.  Please free to correct me at any point.
Let’s take it by word itself “Automation Framework”
Ø         
        Automation:  To automate a manual task
Ø          
         Framework:  Framework in general words it is outline structure or Master which control complex process or we can say control the execution for various child process.

For testing, automation framework is just combination Master and slave script where master script which control execution of your test (Slave scripts). Nothing more than that.  Now the type of automation framework depend on you how you want to implement test and your requirement. It also depends on type of test like business scenario, functional test, regression (Same functional test with different set of data).
 Type of automation also depend on the parameters like scope of testing, depth of testing, visibility of product enhancement or further development,  product may be developed in more than one technology. In short answer of the question “What we expect from automation”.
Well basic thing is application should be stable and if there is any change you should be well aware of that before planning, designing & implementation of the same.  Of course we can’t get visibility of the all parameter in real environment but we should try to cover as much as possible.
Master scripts:
Ø    
            Master script is the script from where we start our execution.  This script will take care of configuring the test environment and ensure the same before executing and test cases and at the end collect the all the result & log and provide them in required format to  end user.
Ø    Configuration of test environment include number of things like production install, verify required version AUT and supportive application, loading test case and test data, updating registry or other  system parameter, etc which we can handle  by calling function for different activity. 

Type of automation framework:
 These types are not specifically decided but these are most possible ways of implementation depending on your requirement.   
1.      
           Data Driven:

Ø  When you have the functional test case with different set of data one can use this approach.
Ø   In this approach we write the scripts/Function for each functional test where we pass the different set of data as input and expected output is compared as criteria of test case to pass & fail. 
Ø  Also there will be common function which we will be using in different test.

2.      Keyword driven

Ø  We take this approach when we have number of test case which we can divide them in number of steps and many of the steps are common in different test.
Ø  And we take each step as different “Keyword”. In this framework we maintain the test case and input data in excel. 
Ø  Implementation of this type of framework includes 4-5 level of hierarchy in execution.
1.       First level will be master script to set test environment call the second level.
2.       Second level will read the excel and  decide which module is set for execution and depending on that it will load required functional library, object library, test data ,etc and pass the call to Third level
3.       Third level will read the excel for respective module select in second level and load the test case and pass the call to fourth level
4.       In fourth level we read keyword of test cases and execution them one by one.
Ø   Here there will for loop in 2nd, 3rd & 4th level which will make sure all the module and respective test case are executed.
Ø  Logging of result and generating the final report we can decide as per our requirement. Handling of exception, error, passing  & failure condition, moving to next test when current one is failed are implemented in each level as per requirement.
Ø  Numbers of level completely depend on your application & number of test case and scope also.
Ø  But make sure to keep thing s independent which will be easy to debug, identify the issue and to make any big change in framework in future. It will be also easy to understand.
Ø    Implementation of key driven framework required lots of planning,   knowledge of domain and application and visibility of possible risk in term technical implementation.

3.       Modular driven:

Ø  This type approach is taken when different kind of test case for different module or we want to business scenario specific to module
Ø  Here we prepared the single script for each module which will execute independently from other.
Ø  Here we can also remove the master script and run the each module independently and to run module in single script we can have sort of wrapper script which will just control the sequence of execution
Ø  Environment configuration, test data, result, error handling all these are handled in module scripts itself.
 
4.       Hybrid:

Ø  Hybrid is combination of keyword and data driven framework. And as per my experience most of keyword driven and converted to hybrid at the end of implementation.

Basic Parameters of Framework

·         Configuration file:   This can be file or a function which will take care of configuration of test environment before execution. It will install, verify the required version of AUT and supporting application.  To test thing on multi OS booting from OS to anther can also be the part of Configuration.

·         Make base state: This function will take care to set AUT in required/base after any failure and exception occurred. We can call this function after each failure.

·         Global/Environment Variable: This file include the entire global variable which are very frequently used in automation like application/library path, results path, failure detail (Video/Snap), test data path, test cases path, etc.

·         Reusable: This file will contain all the reusable application independent function. For example string/Table/excel comparison, loading excels file, converting string to specific format, split the string, write into excel or test file, etc.
  
·         Common function:  This file will contain all the common function which specifically developed for application like select combo box item, verify or select tree item, etc.
 
Friends I have try to give basic idea about automation framework to beginner as per my experience. Please feel free to correct me if I am wrong at any point or if you have any query  by putting comment on blog or drop me a email @ deepakpesu@gmail.com
 Thanks

Monday, May 2, 2011

Verify Coloum exist in Datatable


 'Arguments Passed          : 1. objSheet -  Datatable object
'                                        2. strColumnName - Parameter name
'Return Value                    : True or False   

Function Fn_VerifyDataTableColumnExists(byRef objSheet, byval strColumnName)
    
     Dim intParamTotal
     Dim intIterator
     Dim intValue
    
     ' get total nbr of columns in datatable
     intParamTotal = objSheet.GetParameterCount
    
     ' loop all columns
     For intIterator = 1 To intParamTotal
    
          'get name of column
          intValue = objSheet.GetParameter(intIterator).Name
          
          ' compare if column name matches
          If strComp(strColumnName,intValue)=0 Then
           Fn_VerifyDataTableColumnExists=TRUE
           Exit Function
          End if
     Next
     Fn_VerifyDataTableColumnExists = False
    
End Function

Monday, April 11, 2011

Function to verify whether any excel instance is open or not. If opened terminate the same.

Function IsAnyExcelInstancesOpen 'As Boolean

    IsAnyExcelInstancesOpen = True

    Dim objWMIService, objProcess, ProcessCollection
    Dim strComputer, strMessage
    Dim bolTerminate
    Dim InputUserSelection
    ' Make it true if you want to terminate process without any user;s permission.
    bolTerminate = False
   
    strComputer = "."
   
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   
    Set ProcessCollection = objWMIService.ExecQuery("Select * from Win32_Process")
   
    For Each objProcess in ProcessCollection
    If StrComp(objProcess.Name, "Excel.exe", 1) = 0 Then
        ' If true it will terminate process without any message or intimation
        If boolTerminate Then
            objProcess.Terminate()
        ' It will ask user(Permission) input "Yes" to terminate excel instance opened.     
        Else
           
            strMessage = "An Instance of Excel is running on the Machine. The Framework needs all the Excel instances to be closed for running the Tests." & vbCr & vbCr &_
                "Do you want the Framework to CLOSE all the instances of the Excel?" & vbCr & vbCr &_
                " - Yes:" & vbCr & "Click on Yes to close all the instances of Excel and proceed with the Test Execution." & vbCr & vbCr &_
                " - No :" & vbCr & "Click on No to Stop the test execution and close the Excel files manualy." & vbCr & "--" & vbCr &_
                "Note: All unsaved data in the open excel files will be lost on clicking Yes."
               
            oUserSelection = MsgBox(strMessage, vbYesNo + vbExclamation , "Excel Instances Open")
               
            If oUserSelection = vbYes Then
               
                boolTerminate = True
                objProcess.Terminate()
               
            Else
           
                Exit Function
               
            End If
           
        End If
       
    End If
   
    Next

    IsAnyExcelInstancesOpen = False
   
End Function

To get list of specific file from specific folder

'Funtion to get list of the specific type of files(Based on extension) in specified folder. In this example will filter 'out file having "txt", "qfl" & "vbs" extension. To get the list of file you have keept Array global for atleast that 'file (depend on implementation).
Public Function GetFileList (folderLocation, RequiredfileNames()) 'As Boolean
   
    'Initialize the function and declare the variables
    GetFileList = False
    Dim fso, sfileName, files, fileCount, folder, selectedFile
    fileCount = 0
     On Error Resume Next
    Set fso = CreateObject("Scripting.FileSystemObject")     
    Set folder = fso.GetFolder(folderLocation) 
    Set files = folder.Files
   
    'Browse through all the files in the selected folder
    For each selectedFile In files
           sfileName = selectedFile.Name
          
           'Filter the file based on the extension of the file
        If (StrComp(Right(sfileName,3), "txt", 1) Or StrComp(Right(sfileName,3), "qfl", 1) Or StrComp(Right(sfileName,3), "vbs", 1)) Then
            ReDim Preserve RequiredfileNames(fileCount)
            RequiredfileNames(fileCount) = sfileName
            fileCount = fileCount + 1                                      
        End If
    Next 
   
    'Finalize the function and return the value
    If(fileCount > 0) Then
        GetFileList = True
    End If
   
End Function

Monday, February 21, 2011

Read a Bookmark in a Word Document

Set objWord = CreateObject("Word.Application")
objword.Visible = False
Set objDoc = objWord.Documents.Open("e:\copy.doc")

Do until objDoc.AtEndofStream
                                stxt = objDoc.Readline
                                MsgBox stxt
Loop

objdoc.Close
objWord.Quit

Get Detail of Object Drive


Dim filesys
set filesys = CreateObject("Scripting.FileSystemObject")
Set drv = filesys.GetDrive("e")

select case drv.DriveType
                Case 0: drtype = "Unknown"
                Case 1: drtype = "Removable"
                Case 2: drtype = "Fixed"
                Case 3: drtype = "Network"
                Case 4: drtype = "CD-ROM"
                Case 5: drtype = "RAM Disk"
End Select

WScript.Echo "The specified drive is a " & drtype & " type disk."
WScript.Echo " "
WScript.Echo "Total size is " & drv.TotalSize & ". "
WScript.Echo "Available space is " & drv.AvailableSpace &  ". "
WScript.Echo "Type is " & drv.DriveType &  " "
WScript.Echo "Path is "  & drv.Path &  " "

Dim filesyst, drive
Set filesyst = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Before Condtion"

drive =  filesyst.DriveExists("z")
WScript.Echo drive

                If filesyst.DriveExists("z") Then
                                WScript.Echo("The specified drive does exist.")
                Else
                                WScript.Echo("The specified drive does not exist.")
                End If
WScript.Echo "After Condtion"

Sort Excel Worksheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)

objExcel.Cells(1, 1).Value = "4"
objExcel.Cells(2, 1).Value = "1"
objExcel.Cells(3, 1).Value = "2"
objExcel.Cells(4, 1).Value = "3"
objExcel.Cells(1, 2).Value = "A"
objExcel.Cells(2, 2).Value = "B"
objExcel.Cells(3, 2).Value = "C"
objExcel.Cells(4, 2).Value = "D"

Set objRange = objWorksheet.UsedRange
Set objRange2 = objExcel.Range("A1")
objRange.Sort(objRange2)
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons