Friday, October 7, 2011

New feature avaialble in QTP 11

Following are list of new feature available in QTP 11:


  1. XPath and CSS based object identification
  2. Good Looking and Enhanced Results Viewer
  3. Easy Regular Expressions
  4. Identifiation relation between neighbouring objects.
  5. Load Function Libraries at Run Time
  6. Test Your GUI and UI-Less Application Functionality in One Test
  7. Recording suppport for Firefox avaiable ...
  8. Log tracking
  9. Embedded/Run java script in webpage
  10. Automatically Parameterize Steps
  11. Silver light add ins
I will be back with detail of each feature including know issue n limitation.
Thanks,
Deepak

Monday, July 4, 2011

Function to create zip file of folder

Function ZipAttachment

    ZipAttachment = ""

    ' Declare the required variables
    Dim objZip, objSA, objFolder, zipFile, FolderToZip
   
    zipFile = Environment.Value("c:\ResultFolder") & ".zip"
    FolderToZip = Environment.Value("c:\ResultFolder")

    'Create the basis of a zip file.
    CreateObject("Scripting.FileSystemObject") _
    .CreateTextFile(zipFile, True) _
    .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

    ' Create the object of the Shell
    Set objSA = CreateObject("Shell.Application")
   
    ' Add the folder to the Zip
    Set objZip = objSA.NameSpace(zipFile)
    Set objFolder = objSA.NameSpace(FolderToZip)
    objZip.CopyHere(objFolder.Items)
   
    ' Wait for the folder to be added in the zip
    ' Increase the Wait time is the folder is too large
    WScript.Sleep 2000

    ZipAttachment = zipFile

End function

Function to Send mail through vbscript

Function SendMail

    ' Declare the required variables
    Dim strTextBody, MailNotification
    dim strModuleName, intTotalPassed,  intTotalFailed,  intTotalNotExecuted

    ' Assign value to result.
    strModuleName = "Smoke"
    intTotalPassed = 10
    intTotalFailed = 1
    intTotalNotExecuted = 0
   
    ' Prepare the body text
    strTextBody = "==================================" & vbcrlf
    strTextBody= strTextBody & "Test Execution Report" & vbcrlf
    strTextBody= strTextBody & "Date :"  & Date & " " & Time & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody= strTextBody & "Summary" & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody= strTextBody & "Total Tests Passed       : " & intTotalPassed & vbcrlf
    strTextBody= strTextBody & "Total Tests Failed       : " & intTotalFailed & vbcrlf
    strTextBody= strTextBody & "Total Tests Not Executed : " & intTotalNotExecuted & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody = strTextBody  &  "The attachment contains the" & vbcrlf & "results for the following modules:" & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody= strTextBody & strModuleName   
    strTextBody= strTextBody & "=================================="
   
    ' Create the Mail object
    Set MailNotification=CreateObject("CDO.Message")
   
    ' Set the subject
    MailNotification.Subject = Environment.Value("Smoke result")
   
    ' Set the Mail From parameter
    MailNotification.From = Environment.Value("Manual Team")
   
    ' Set the Mail To parameter
    MailNotification.To = Environment.Value("Manager")
   
    ' Set the Mail CC parameter
    MailNotification.CC = Environment.Value("Test Lead")
   
    ' Set the mail BCC parameter
    MailNotification.BCC= ""
   
    ' Set the Bod of the Mail
    MailNotification.TextBody= strTextBody & vbcrlf & vbcrlf & "DO NOT REPLY. This is an auto-generated mail." & vbcrlf & "Contact the administrator in case of any queries"
   
    ' Add the Attachements  (Zip Attachment is global which contain required result in detail)
    MailNotification.AddAttachment  ZipAttachment

    ' Configure the mail according the smtp server settings
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Environment.Value("SMTP server")
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0 'cdoBasic
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 120

    ' Update and send the mail
    MailNotification.Configuration.Fields.Update
    MailNotification.Send
   
    ' Clear the memory
    Set MailNotification=nothing

    Call DNALogEvent("Mail notification sent.")
   
End Function

Thursday, June 2, 2011

How to initiate with Keydriven Framework

 Hello Friend as I have already discussed about framework & types in my last post. Then my one of blog follower asked me how to initiate with any framework, especially Keyword driver.

So I have tried to share my thoughts on the same with example of sample application “Flight” which we usually get with QTP. I know it’s very simple application compare to our practical work but as this command available to person who use QTP, hence I decide to go with it.

Here I will not get deep in coding but will go in concept ually way.
Let’s consider the basic 3 test for flight application as follow.
1.       Login into application and logout
2.       Login, book the order,  confirm it and log out
3.       Login, open the order, delete it and confirm the deletion and logout.

Of course these test will not be single line, there will be specific steps with verification point. This step will be our first target to identify the keyword. Definitely there will be 4-5 steps which we have to perform in single window so we take the as single activity as a keyword. It also depends on how the test cases are written.

For example:
Test 1 – Type 1:
·         Login into application with correct credential
·         Confirm the Home page of application
·         Log out from the application
·         Confirm the logout that it returns to “Login page”
Test1 –Type2:
·         Open the application by from start or writing “Test Application” in run
·         Confirm the login page
·         Enter User name
·         Enter Password and click “Login” Button
·         Wait and confirm the Home page.
·         Select logout option from the menu item
·         Confirm the logout that it returns to “Logint page”

This is very simple and small test but you can see in both type we are doing same thing  process of writing is different. These similar things we have to take care while deciding the key word.
Because Login step can be perform by single keyword
·         Login(“UserName”,”Password”)

It can also be perform using following 4 keyword
·         OpenApplication(“Argument”)
·         EnterValueinEditbox(“LoginPage”“UserEdit”, “Username”)
·         EnterValueinEditbox(“LoginPage”,“PasswordEdit”, “Hello123”)
·         ClickonButton(“LoginPage”,”Login”)
·         IspageExit(“Pageopen”)

Well you think no one will split the login step this way, But looking to broader picture to any huge n complex application where single test contain many steps you have decide step with proper scope and  which don’t have any dependency.

Many people avoid identifying keyword for the entire test or at least the core area which is our first target as automation ROI. But as I have experience predefining of keyword help you lot and save you most of time.
For above three tests will required following keywords.
  • ·         Login
  • ·         Bookorder
  • ·         Isorderexist
  • ·         Deleteorder
  • ·         Logout
Similarly for remaining functionality we can identify the keyword which will be max to max 15. And using those 15 keywords we can automate at least 100 or more test.  Which is quality or you can say best quality of Keyword driven

While identifications of  keyword we should take care it should not perform much operation or more then window, because what we ever operation the keyword do for that it might required input data which we have to provide and manage for expected output.
While identify keyword we should make sure following things
  1. What stage of application/Window will be required?
  2. What input will be provided?
  3. Each key word will provide either true or false and base on that Driver script will execute the next step otherwise it will move to next test marking the current test as Failed.
  For Input:

1.       From where we are going to provide input. While deciding this we should take case the person who write test case for execution has manage n provide this input data which should not be any lengthy or complex process.
2.       Expected output day which always depend on our input data so that we have to maintain also. This specially comes in picture when we are dealing with financial or online web application where small input is going to affect many places & we have to verify at the end of test.

Once you identify the keyword we can start development of function/Keyword.  And development of keyword is not dependent on any other keyword which will help to speed up the development. This independency comes only when we identify the keyword properly.

Keyword to Input & Expected Output:

Most of time we maintain keywords/Tests in excel only. So for the test in which we have to provide 2 or 3 value as input data we can put them in column of the excel beside to the keyword only.

But there will be time when you have provide more data around 10 -20 and even every data is not required to that keyword in each test, so for such keyword we can maintain the excel where we can have the unique ID of each test cases. For example

TestCaseID
First Name
Last Name
Class
Contact no
Email
TestCase_001
Sachin
Tendulkar
8
9988998899

TestCase_002
Shewag

6

..

..
.
.
TestCase_025
Zaheer
Khan

9879879899


As you see in this example we can provide input to test as per our requirement and also we can use this same table for expected output. In Blank cell will reflect to keyword that we don’t want to provide this value to test.

Please correct me if I am wrong at any place and feel free ask any query related to QTP or automation framework

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"

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons