Archive

Tuesday, August 2, 2011

Get count of file with matching extension in a Folder

In automation testing, you might come across with situation where in you need to find out number of files with a particular extension. Below is the code to get the count of file matches with the extension.

Function GetFileCount(ByVal sFolderPath, ByVal sExt)

 

            Dim iCount

            Dim oFile, pFolder

            Dim fso

            On Error Resume Next

           

            Set fso=CreateObject("Scripting.FileSystemObject")

            set pFolder=fso.GetFolder(sFolderPath)

            set oFile=pFolder.Files

 

            For each sFile in oFile

                        If instr(1,lcase(sFile.Path),sExt,1)>0 Then     'It's a text comparison

                                    iCount=iCount+1

                        End IF

            Next

 

                        'Count all files in each subfolder – recursion point

            For Each SubFld In pFolder.SubFolders

                        iCount = iCount + GetFilecount(SubFld.Path, sExt)

            Next

 

            GetFilecount=iCount  'Return the count to the calling statement

            Set fso=Nothing

End Function

 

sPath="E:\Debajit Hazarika\EDI Files"

sCount=GetFileCount(sPath, ".mbi")

Msgbox "Total Count  ="&sCount


Saturday, June 4, 2011

How to import all working sheets of an excel file to QTP DataTable: Excel Automation

Hello, friends
This post is meant for QTP learner and who are novice at it. You know that DataTable plays a big role in parameterizing our automation test. We pass arguments to our test script using this dataTable provided by QTP. However, in automation testing of a complex and large scale project we become less dependent on DataTable. Most of our test data is stored in Excel sheet because it gives us a flexibility to modify when needed. We know that to import and excel sheet, we use following commands: 
                               i)DataTable.Import(FilePath)
                               ii) DataTable.ImportSheet "FilePath", "SourceSheet", "DestinationSheet"

If your excel file contains more than one sheet, then none of the above command gives you the ability to import all the sheets at a time. In this case, you have to meet the requirement pragmatically. Sometimes, there is a requirement of using different local sheets at a time during execution. To get ride of such situation or to ease the process, I would like to share the following code snippet with you to achieve that goal. Code is given in Function format for reusability.

   Function ImportAllSheetsToDataTable(FileName)
       Dim objExl, objWBook

       If  Not IsNull(FileName) Then        'Check if the File name has been passed.
    Set objExl=CreateObject("Excel.Application")
    Set objWBook=objExl.Workbooks.Open(FileName,,True) 'Open the excel file

For each oWSheet in objWBook.WorkSheets  'Read all the worksheets
DataTable.AddSheet oWSheet.Name
DataTable.ImportSheet FileName, oWSheet.Name,oWSheet.Name
Next
        Set objWBook = Nothing
    objExl.Quit      'Quit the Application
    Set objExl = Nothing
Else
msgbox "No File name has been passed"
End IF
   End Function

   'To call the Function
   sPath="C:\TestData\TestData_QA.xls"
   ImportAllSheetsToDataTable(sPath)

Hope this code will also help

Thursday, June 2, 2011

How to identify a WebButton under a WebTable on a page

We, the automation tester frequently encounter web table on web page. WebTable is a way by which developers use to display information or data to user in tabular form on web page. Handling webtable is not a big deal in automation testing. But handling objects inside the table needs care. You must have faced such situation where you need to identify the button or link to perform "click" operation on it to open the respective page. It is simple if there is only one object of that type.
What will you do if there is more than one object of that type with same sets of property? Probably, you remember how to use index property and that will solve the issue at hand. If you are asked to identify a button and click on it based on some arguments, what you are going to do. Then we will be going into a bit complex thing. First you need to determine which button to identify and then click. To find the button, we need to know the row and column number of the cell of the table.
Let me proceed with an assignment. Assignment is- You need to delete the account with the name "Acc Nick Name". Look at the image below. This is a list containing different account nos. From here you need to search for "Acc Nick Name" and hit the "Delete" button to delete the account. Since you never know how many accounts this list may contain. So the behavior of this list is dynamic and each "Delete" button is of same nature.



Let's get into action. I pull up the spy button and get to see below mentioned hierarchy.






As you can see that the Delete button is located inside the webtable. Now, we are going use the Object Repository to store the object. To achieve that, I started recording the script. While recording I click on any of the Delete button. As a result, QTP automatically saved all the objects it has interacted with. Then I change the Title of the browser to broWCP and Page to pgWCP in the OR. Below is the code.

  Browser("broWCP").Page("pgWCP").WebButton("Delete")

You noticed that web table is missing from the recorded script. This is because QTP conceals the complete hierarchy. Now, remove the WebButton part and type WebTable, it will automatically display the name of the table. So, the code will look like this:

  Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian")

Now, we need to find out how many rows and column the table has. Then we need to locate the Delete button based on the Account NickName. Here is the complete code:

Dim iRow, iCol, sRow, sButton
Dim bStatus:bStatus=False
sAccount="Acc Nick Name" 'Account Name to delete

iRow= Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").RowCount 'Find out the total row
iCol= Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").ColumnCount(iRow) 'Find the total Column

For i=1 to iRow 'get the row no where the target item exists
  If Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").GetCellData(i,3)= sAccount Then
      sRow=i
      bStatus=True
      Exit for
  Else
      bStatus=False
  End If
Next

  If bStatus Then
      Set sButton=Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").ChildItem(sRow, iCol, "WebButton", sRow-2)
      sButton.Highlight
      sButton.click
  Else
      Msgbox "Could not find the item"
  End IF


We know that the field "Account Nickname" exits on the 3rd column of the table. We have also identified that all the "Delete" buttons located in the last column of the table, hence we used whatever value is assigned to iCol. Later part "sRow -2" is due to the fact that index starts with "0" and our first row of the table contains the column heading. Hence, we need to subtract 2 from sRow. Last argument of childitem method is the index no.

This is how we can handle dynamic button inside a WebTable. Hope you enjoyed learning this fact.

Tuesday, September 21, 2010

What is the difference between QTP 9.2 and QTP 9.5?

Following are the points that make QTP 9.5 different from QTP 9.2:

1. QTP 9.5 supports MS Vista 64 bit edition also, in comparison to QTP 9.2's support for 32 bit edition only.
2. Support for omnipresent tabbed browsing is also introduced with this version.
3. All the addins come itegrated with QTP. But, still we need to buy add ins seperately to get them activated.
4. QTP 9.5 has introduce support for Bitmap torenace. You can change the tolerance level directly from GUI and define it in terms of RGB and pixel.
5. Checkpoints & Output values are getting recorded in OR.
6. You can create your own QTP add-in. When your add-in is loaded, Quicktest will recognize objects as you defined.
7. Maintenance Run mode.

Monday, March 30, 2009

Tool that may help you in cross browser testing

Everybody of you will agree that one of the most toughest and tiresome task is to perform cross browser testing. In addition to Firefox and IE, we’ve got multi-platform versions of Safari, Opera, Chrome, and a wealth of mobile phone browsers. In addition, there are multiple versions of all these browsers, many of which have different rendering mannerism. So, it's like adding fuel to the fire..... To ease out your tension and difficulties, Microsoft has come out with a tool called Expression Web SuperPreview. As per Microsoft, Expression Web SuperPreview for Internet Explorer is a stand-alone visual debugging tool that makes it faster and easier to migrate your sites from Internet Explorer 6 to Internet Explorer 7 or 8. With Expression Web SuperPreview for Internet Explorer, you can ensure that your Web sites work correctly in Internet Explorer 8 while also maintaining compatibility with earlier versions of Internet Explorer.
The problems it caters to:
  • Most browsers can’t have multiple versions installed side-by-side. The newest version replaces older versions. So, you can’t have IE6 and IE7 on the same machine (unless you’re using virtual machines or unstable registry hacks).
  • Many browsers support both Mac and Windows. Devs want to test in (at least) Mac Safari, which doesn’t render the same as Safari on Windows.
Advantage of using Expression Web Super Preview:
  • It simplifies testing and debugging layout issues across different web browsers and platforms.
  • You can view your pages in multiple browsers simultaneously or view how a page renders in a browser and compare it to a comp or mock-up image of a page.
  • You can even do overlays to see exactly where mismatches may occur. To help you quickly figure out where the problem is, DOM highlighting shows absolute positions of the rendered elements and HTML elements display CSS properties.
Are you excited enough to see this product? If yes, I suggest you to visit this link http://www.microsoft.com/expression/features/Default.aspx?key=webpreview for further reading and downloading. Since it is in Beta version, anticipate issues.

Enjoy Testing..Thanks.

Thursday, June 26, 2008

Testing Web Application Part-1



1. Introduction
Testing process in any software organization is the key element to produce bug free, highly quality oriented software applications. This White Paper provides a great deal of information regrading testing process of web based applications.
Before we go ahead, we would like to provide an idea what Software Testing is all about.
Software Testing is an activity aimed at evaluating an attribute or capability of a program or system and determining that it meets its required results. It also ensures the working of the designed application as per specification. There are many approaches to software testing, but effective testing of complex products is essentially a process of investigation, not merely a matter of creating and following rote procedure.
Mainly, we have targeted to cover the answers of the following four points:
1. Why we encounter bugs in software applications
2. What can be the best practice to prevent bugs.
3. What is the best way to get them managed.
4. What is the ideal testing process.
Software testing continues to grow more complex as the nature of web software application is getting more complicated and the vista of these application are becoming widen making it challenging for any tester to cope up with this process.
2.Why we encounter bugs in software applications:
Many of us encounter bugs in day to day life in the application that we use. Have we ever tried to give a thought why we encounter bugs in a software application. There are many factors playing a major role behind a buggy software. Most are man introduced and some are machine oriented.
If we elaborate the issue , we will have the following points:
2.1. Lack of proper communication: People associated with developing the software is not we aware of what an application should do and what it should not. In short, lack of requirements gathering.
2.2. Complexity of Software: Now a days software enters in to every domain of work. Complexity of current software system is so hard that it is very difficult to comprehend for anyone without the experience and knowledge of modern day software development. Right from Windows-type interfaces, client-server and distributed applications, data communications, enormous relational databases to sheer size of applications have all contributed to the exponential growth in software/system complexity. And the use of object-oriented techniques can complicate instead of simplify a project unless it is well-engineered.
2.3. Programing error committed by programmers: It is obvious that programmers can introduce syntax error or logical error without their knowledge, which may lead to disaster situation.
2.4. Rapid changes of requirements: Client can request any feature or changes in the mid of the development without knowing the impact of the changes. If there are many minor changes or any major changes, known and unknown dependencies among parts of the project are likely to interact and cause problems, and the complexity of keeping track of changes may result in errors. Redesign, rescheduling of engineers, effects on other projects, work already completed that may have to be redone or thrown out, hardware requirements that may cause unbalance in the developed system.
2.5. Dead Line and Time pressure: When unrealistic deadline is given, people rush in hurry without going in-depth of the product. Scheduling of software projects is difficult at best, often requiring a lot of guesswork. When deadlines predominate and the crunch comes, mistakes will be made.
2.6. Poorly Documented Code: It’s very tough to maintain and modify code that is badly written or poorly documented. That appears or results as a bug later after any changes. In many organizations management provides no incentive for programmers to document their code or write clear, understandable code. In fact, it’s usually the opposite: they get points mostly for quickly turning out code, and there’s job security if nobody else can understand it.
2.7. Lack of real Testing Environment: It is also important to consider the real environment where the software program will be implemented. It is very common that we can miss out those test conditions and scenarios to test for the lack of proper testing environment. This might be turned out as critical defect leakage at times.
2.8. Undefined Testing Process: Testing of a software system is not taken as seriously and carried out undocumented and undefined testing activities. Lack of well trained and experience QA professional also be the cause of buggy software.
4. What can be the best practice to prevent bugs:
We know that prevention is better than cure. This is the section in which we will discussion what can be done to prevent bugs before testers come to rescue. We had seen enough evidence in our company earlier that very few were interested in taking the initiative to prevent early mistakes. However, since the guide line in place, we witnessed a lot of improvement in the software developing stage.
3.1. Writing quality code: Though quality is a non tangible attribute, but programmer needs to ensure it right from the beginning.
3.2. Unit testing:Programmer should debug the code using any Unit testing tool to insure the functionality of the developed module. They should not limit themselves to positive cases but also negative use cases.
3.3. Use Editor tools: Despite the availability of automatic error prevention tools for coding, it seems developers pay less interest in adopting such tool. Automatic error prevention tools are the good way to guarantee syntax error free code.

Continue......

Testing Web Application Part-2


Testing Process: Software Testing process is a very indispensable part of any software development process. If you are developing a web based application for your business, then the scope of testing challenges are getting increased. If the develop web site does not perform well under the stress of many customer visiting your site, you will lose business, customer and credibility. So, it's very essential to follow a software application testing process to deal with these issue and to measure the quality of it. A typical testing process starts from the initiation of Software Application. We are portraying the Software Testing Life Cycle with help of following diagram. This will let you know the different phases and its inter dependencies.


4.1. Requirement Gathering: Requirement gathering is an essential part of any project and project management. Understanding fully what a project will deliver is critical to its success. We want to be sure that the requirements specification contains all the requirements that are known about. While we know that there will be evolutionary changes and additions, we would like to restrict those changes to new requirements. We also consider the functional and non functional requirements for testing. As far as non functional requirements are concerned, it is the response by the system on a particular action. In other word, if system needs to respond to an event in 1 sec then we are talking about how the system must work; not what the system does. In this phase we refer to the following documents to collect the requirements details for testing.
• Requirement Specification documents
• Functional Specification documents
• Design Specification documents (use cases, etc)
• Use case Documents
• Test Trace-ability Matrix for identifying Test Coverage
On completion of this phase, we move out to start planning the testing process.
4.2.Test Plan: Test plan specifies process and scheduling of an application under test. QA Manager/Test lead prepares test plan document based on what to test, how to test, when to test, whom to test. It contains test plan id, one or two lines about project, estimated project testing start date, actual project testing start date, estimated project testing end date, actual project testing end date, selected test engineer names for the current project, training needs, schedule, use of automation tools, risks and mitigations, selecting test cases for regression testing. A Test Plan describe the following points:
• Introduction and Objectives
• Scope of Testing.
• Test items
• Features to be tested (who , what and when)
• Entry and Exit criteria
• Testing task
• Testing strategy and approach
• Assignment of Role and responsibilities
• Testing scheduling
• Risks and contingencies
• Staff and training needed
• Identify the areas for automation
• Automation Tool to use
• Test Deliverables
Basically, a Test Plan is systematic approach to testing a developed system. The plan typically contains a detailed understanding of what the eventual work flow will be. We draw plan to keep track of progress on the software that is being built.
4.3. Test Environment Setup: This is phase we prepare the Test bed. We need to set up the environment in terms of software/Tools and hardware according to the specification provided by client. This process involves with software and hardware installation required for testing. We also focus on network connectivity. Moreover, a good coordination is establish with vendors and maintenance departments for smooth running of testing activities.
4.4. Test Design: In this phase, we cover test design of software testing life cycle. It starts with in-depth coverage of test case design techniques for black box testing. This includes Equivalence Class Partitioning, Boundary Value Analysis, and Decision Tables. We emphasize on design activities and writing Test Design Specifications including documenting test conditions, test cases, test scripts and procedures and expected results. We pursue the following three stages in Test case developing which are described below:
• Develop test scenarios.
• Develop Test Cases.
• Review Test Cases.
• Writing/recording test script.
Developing test scenarios is crucial to successful implementation of test cases. On the basis of Test Scenario, we create test cases. Once we are completed with test case writing process, we send the test case document to Team Lead or higher level for review process.
As the test case writing is an art, and anyone can enhance the skill on writing test cases by the experience and practices. Keeping the following facts in mind, we can write effective test cases. 1. Always try to design the test cases in such a way to ensure the maximum coverage of
functionality with less number of test cases.
2. Read the specification carefully before developing test cases.
3. Focus on boundary value analysis and equivalent class partitioning techniques.
4. Make the test cases generic.
5. Try to make the test case as simple as that anyone can understand easily.
6. Classify the test cases according to the module/feature.
7. Identify those test cases which are required for Sanity Test of a build and make a
separate file for it.
Use specific test case template that covers all the necessary information which required in execution of test cases. Though every company has its own Test Case template, we have designed the following template to cover all the important information suitably.
In parallel, we always look out for the areas that can be automated so that manual testing effort can be reduced. This effort is generally made for functionality which are repeated in nature and stable. This automation scripts are written to perform sanity test and regression testing.

Continue........