Java Automation-keyword driven applications in JUnit interface automation

Source: Internet
Author: User

This article is based on the continuation of the discussion above, it is recommended that readers first read http://www.cnblogs.com/xuezhezlr/p/9097137.html and https://www.cnblogs.com/xuezhezlr/p/ 9096063.html after the understanding of this article, this article is aimed at the data driven in the above practical application of the question to answer

In actual use, the reader will find that the original framework in some scenarios is not too good to use, such as the order to complete the interface, it is necessary to use the keyword-driven way, the key word drive in this article and the formal has a certain discrepancy, but still from the most orthodox keyword-driven thinking out, the real keyword drive, The core is the code to define some keywords, once a certain trigger conditions are met, it will directly trigger the corresponding code logic and operation to achieve the purpose

The so-called data-driven, is really the data and test code to separate, but in the above method will be found, whether excle form of data-driven or database form, will be the data abstraction, in practice, each test case in a database in a record or excle in a row to show, It abstracts all the data into a single record in the database, but there are some problems with the order completion interface

Here to say, the general company orders to complete, is a normal state of the order, call a specific interface to pass some parameters, to complete the Change Order status and payment operations, in automation, because it is difficult to ensure that the test data is always correct, often need to create a normal state of the order, And then to take the order number of this order to invoke the interface, that is, the order number is changed, in the Run Automation task generated by the

On the other hand, in the above framework, the basic is written dead parameters, this change of data, the temporary generation of data, will be incompatible with the problem, in theory we need two rows of data, a row is called to create an order when the parameters, the second line is called the order to complete the parameters, and so, the code will be very confusing, The complexity will be raised straight

Therefore, the keyword driver appears, its task is to solve this, similar to the order number of this special parameter, assuming that in the interface test, the order completion interface in the original code we want to pass a OrderNo field, where the orderno need a normal order, then, What we're going to do is enter a keyword to let the code know that we need a keyword like this, and here's some code

else if (Value.indexof (Urlencoder.encode ("created order buyer bid OrderID", "Utf-8"))!=-1)
{
Value = Value.replaceall (Urlencoder.encode ("created order buyer bid OrderID", "Utf-8"), Order.testorder11 ());
}
else if (Value.indexof (Urlencoder.encode ("created order buyer bid ipid", "Utf-8"))!=-1) {
Value = Value.replaceall (Urlencoder.encode ("created order buyer bid ipid", "Utf-8"), Order.testorder11 ());
}
else if (Value.indexof (Urlencoder.encode ("created order seller bid ipid", "Utf-8"))!=-1| | Value.indexof (Urlencoder.encode ("created order seller bid OrderID", "Utf-8"))!=-1)
{
Value = Value.replaceall (Urlencoder.encode ("created order seller bid ipid", "Utf-8"), Order.testorder12 ());
}
else if (Value.indexof (Urlencoder.encode ("created order seller bid OrderID", "Utf-8"))) {
Value = Value.replaceall (Urlencoder.encode ("created order seller bid OrderID", "Utf-8"), Order.testorder12 ());
}
else if (Value.indexof (Urlencoder.encode ("Completed order OrderID", "Utf-8"))!=-1)
{
Value = Value.replaceall (Urlencoder.encode ("Completed order OrderId", "Utf-8"), GetData (Order.testorder2 (), "orderId"));
}
else if (Value.indexof (Urlencoder.encode ("pre-created order OrderID", "Utf-8"))!=-1)
{
Value = Value.replaceall (Urlencoder.encode ("pre-created order OrderId", "Utf-8"), GetData (Order.testorder0 (), "orderId"));
}
else if (Value.indexof (Urlencoder.encode ("pre-created order Ipid", "Utf-8"))!=-1)
{
Value = Value.replaceall (Urlencoder.encode ("pre-created order Ipid", "Utf-8"), Order.testorderzlr0 ());
}
else if (Value.indexof (Urlencoder.encode ("Cancelled orders OrderID", "Utf-8"))!=-1)
{
Value = Value.replaceall (Urlencoder.encode ("Cancelled order OrderId", "Utf-8"), GetData (Order.testorder3 (), "orderId"));
}
is the document's


The code above can be seen in the code that will identify the completed order OrderID, the canceled order OrderID and other keywords, the code see this will be executed directly after the corresponding operation, and then replace the string
For example, the original is OrderNo, in the document will write a variety of keywords, such as the revocation of the order OrderID, and then invoke the interface or code itself logic, directly generate a corresponding status of the order ID, and then the original data to replace it.
This is the keyword-driven code core.

  

Java Automation-keyword driven applications in JUnit interface automation

Related Article

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.