Automated Testing Framework Based on UI automation (1)

Source: Internet
Author: User

(To) http://blog.csdn.net/roger_ge/archive/2010/04/26/5531941.aspx

Part 1: Preface

Automated testing may be a field of research or preparation by many testers. Choosing appropriate automation tools and building a correct and efficient framework based on your own capabilities and the company's situation may be a topic that will never be discussed. As the answer goes, there is no better, only better.

Many of my company's current projects are developed based on win7 and WPF. I tried to use qtp to record and play them back. Unfortunately, additional WPF plug-ins are required. In addition, the qtp script language is VBScript. Although it is powerful and easy to use, its logic is not as rigorous as that of many class C advanced languages. The level of qtp can only be regarded as an entry level.ProgramI had to study qtp in depth before, and I felt a little cool to dance. In fact, I am eager to learn about the automated testing framework. After all, recording and writing procedural automation programs are not difficult. building an efficient framework is the core, only those who have mastered the framework can be used across the world.

In my hard work, UI automation appeared in front of me. It has the following advantages:

N the new automatic framework provided by Microsoft is embedded in. NET Framework and fully supported by WPF.

NProgramming LanguageUse C #

N msdn provides very detailed help documentation and detailedCodeExample

N elasticity is excellent. Only common methods such as identification, action, and attribute of elements such as windows and controls are provided. The upper-layer architecture is completely determined by the programmers themselves.

Part 2: Build a framework

Let's take a look at the most common automated testing process:

If you write a procedural Automation program and execute a test case, a lot of code and actions are redundant. Well, let's take a look at what aspects can be abstracted and encapsulated:

N Automation program configuration: defined in APP. config

N test scenario preparation and cleaning: considering the differences between different scenarios, the interface specification is adopted.

N start the tested program

N test scenario preparation and cleaning: considering the differences between different scenarios, the interface specification is adopted.

N control element organization: XML lists several important attributes of each element.

Create n control elements

Action of n control elements

N test result judgment

N storage of test results: using open-source nlog

N Exception Handling: Define User exception classes at the underlying layer, and capture these exceptions by top-level class handling

Abstract encapsulated framework:

Note:

The delegate in C # is equivalent to the previous callback function, but its advantage is that you can add the method chain to be run iteratively, this eliminates the need to modify the code in the class where the launch aut is located when adding or deleting test cases. You only need to dynamically Add the test scenario in the external test scenario, which is very convenient.

Class C language also has a good Exception Handling Mechanism, which is fully apparent in multi-layer applications. Imagine if a program has more than 10 levels of function calls, and there is no good exception transmission and processing mechanism, it will be a headache to handle exceptions at each layer. With this exception transmission mechanism, if the underlying layer encounters an exception and it is necessary to terminate the current automated test scenario, you only need to discard the handling and throw the exception, all the methods in the middle layer can ignore the exception handling operations. The top-layer calling methods will naturally capture and handle this exception. This is a great thing to do when writing the middle layer method, because you only need to write the method according to the normal process, you do not need to care about exceptions and actions that should be taken. (This does not mean that VBScript does not have this function. On the contrary, VBScript also has similar functions. For more information, see another blog article: exception transfer and handling of VBScript)

Part 3: postscript

Some problems are found when building the framework, that is, if you want to make the self-built Automated Testing Program Framework efficient and change as little as possible in the future, then we need to go through the software development process completely:

N Analysis automated testing requirements

N Architecture Design

N Mode Design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.