The idea of building Java Automation test Platform

Source: Internet
Author: User

Many people are superstitious in the automated test platform, think that this thing is omnipotent, for testers, do not need to write code, just choose on the platform, enter a little parameter, you can achieve the purpose of testing. The idea is good, but the key is to implement the process of the platform, this needs a foundation for web development, we do not talk about web development today, talk about the need to do before building this platform to do some of the work. Take the interface test as an example, if we can use XML to describe our script, then select on the platform, and then enter some parameters ah, and then generate a temporary XML file, so it can run, right, so, now the problem into how to use XML to describe our script. In fact, the principle is very simple, we should know, is through the reflection of Java, for example, an XML, a node name represents a method, and then combined with the object, then invoke, you can execute this sentence XML, so, first of all, we have to design this XML format, Here's what I do:

Next, of course, parsing this XML, Java parsing XML in a variety of ways, I use the Dom4j+xpath way to do.

After parsing, such as the first sentence: <url>${url}/getipinfo.php?ip=210.75.225.254</url>, which <url> represents the method name, ${url}/ getipinfo.php?ip=210.75.225.254 This sentence represents a parameter, where ${url} represents a number of custom parameters, and multiple parameters are separated by commas. Since there is a method name, because Java invoke requires an object to invoke, so, this time, you need an object, in fact, there are many processing objects, you can new an object, and then put the new object in a static variable to save, in the future to use when the direct fetch.

The way I do this is to make a custom annotation that, when started, automatically generates the object that added the annotation:

As a result, the object and method names are available, and then we can invoke them to execute the corresponding method of the XML node. Note that some methods need to have a return value, this time, we add a return of the property can be, the return value, automatically saved in the static variable can be, convenient to call below.

Since the XML script can be written, then, when the platform is built, you can either generate a temporary XML file, you can upload an XML file up, and then execute, you can achieve the purpose of our platform. Isn't it convenient?

Need source code can talk about me privately!

The idea of building Java Automation test Platform

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.