Robotframework Interface Message Test-----(ii) Demo upgrade version

Source: Internet
Author: User

In the previous article, the simple demo implemented the XML data sending server side and obtained the RECVI_BUF, then carried on the simple parse operation. Now it's time to address the 2 questions that we mentioned earlier:

1. So many steps, do you want to repeat the script every time you write it?

2. Each interface of the SENDBUF XML format is not the same, the ID is not the same, the tag inside the nodename is not the same, how to do? Is every interface to write a createsendbuf, certainly not this, then how to do?

To solve the first problem, you can use to define your own resource in RF, then write the keyword defined in the direct call resource, one line is a test case, this problem is easy to solve. For the second problem, you should use an XML file to save the format of each interface, define a keyword, enter the ID of the interface, you can get the format of the corresponding interface from the XML, and then from the RF within the interface to accept the value of each field, combined into send_buf, To the underlying PY calls the DLL containing the network communication layer.

The implementation of the message format of the corresponding interface from XML according to ID is as follows:

            deffindnodebyidattr (self,idattr): Root= Xml.dom.minidom.parse ("D:/test2.xml"). documentelement node= Root.getelementsbytagname ('cmd')         forKinchnode:if(K.getattribute ('ID')==idattr): str1= (K.toxml ()). Encode ('Utf-8')                               returnStr1

This makes it easier to manage the message, and if an interface is added, the format is defined directly within the XML. Inside the code, there is no specific field involved in the specific message, which is easy to maintain. The next step is to take the value of the text segment (defined in list) obtained from RF and combine the specific value with the corresponding XML. The type of the data returned by the ToXml () method is no longer a instance, but Str (egg:<cmd id= "30000" ><username var= "name"/><loginserveraddr Var= "www.abc.com:1089"/><userpassword var= "000000"/></cmd>), the value of list is [' Loleina ', ' 192.165.5.144:1089 ', ' 000000 '] Now you need to assign these three to username, Loginserveraddr, UserPassword. The Str must first be converted to XML, then the XML tag name, set the value of attribute per tag is list[i]. The code is implemented as follows:

       def packagetoxml (Self,strnode,listarray):        tagnamelist=[]        length=len (listarray)              str1= ' <?xml Version= "1.0"?><root> '                str2= ' </root> '                strnode+=str2        strnode=str1+strnode        root = Xml.dom.minidom.parseString (Strnode). documentelement        node = root.getelementsbytagname (' cmd ') for child in        Node[0].childnodes:            if ((Child.nodeName.startswith (' # ')) ==false):                tagnamelist.append (Child.nodename) For                i in range (0,length):            Tagnode = Root.getelementsbytagname (Tagnamelist[i])            tagnode[0]. SetAttribute (' Val ', Listarray[i])            return  node[0].toxml (encoding= "Utf-8")            

Finally look at the design of the RF test case:

This completes the demo, at the beginning of the encounter several problems:

1. The interface of the project has multiple XML, which needs to be merged into one XML for RF use, each XML format is different, the encoding format is not the same, and the XML for each field has a comment, Commentnode exists, you have to remove the comment. (later found not to remove the annotated XML, do not remove the space, the empty line of XML, to the underlying DLL, the DLL will be preprocessed, collated and then sent to the server)

2. When you take the name of tag in XML, if Tagnode has childnode, it is not taken out according to the above code snippet, this is changed later.

3. Data returned from the server, depending on the interface type, add the class, delete the interface of the class or just return the result of a result field, query, modify such interface will return a lot of data, data is from the database, so the result is simple

The deal must be over. Must be queried from the database and then assembled into XML in a certain format, comparing the expected result XML with the actual returned XML.

4. Go to the name of Tagnode, you have to judge, because there is a comment inside the XML, annotation is also a kind of, called Commentnode.

5. WinSocket-based interface testing is very different from HTTP-based interface testing, and HTTP is stateless, and TCP itself is a stateful protocol. This doomed business is certainly more complex than the latter, based on the WinSocket interface, interface and interface between interfaces, there are some temporary runtime variables, that is, the B interface packet composition, from a interface message some output, the part of the output as a temporary variable running program, stored in the program memory, Instead of the database, when the B interface is used, it can be taken. At this point, do the B interface is bound to get a result of the temporary variables, this with the deep understanding of the business, it should be more and more clear the relationship between each interface.

These questions are getting to know more about RF and Python, and when you do the demo, you start to think about it. A good RF learning site is recommended here:

Http://blog.csdn.net/tulituqi/article/category/897484/2

This blogger also out of a book, I also bought, actually with the above blog on the content is not too much, look at the above is enough to get started.

Robotframework Interface Message Test-----(ii) Demo upgrade version

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.