Summary of learning process for RF built-in libraries-----built-in libraries

Source: Internet
Author: User
Tags builtin xml example

The previous period of busy learning RF, the system after the study began to do a variety of interface testing, although all types of interface testing can run through the basic, but the problem of repeated car building is too obvious. RF itself built-in libraries are already rich, such as no need to import directly into the memory of the Builtin library, and the need to import the common module String,collections,xml library. In front of the interface test, the most used is the number of built-in libraries, the interface is basically the return of the data are mostly XML format, and then their own repeatedly made car, for this special spent a few days to learn the next built-in library, mainly learned the next XML library, the following share is based on the XML library.

To learn the XML built-in library, I think there are a few things to know:

First: The concept of built-in libraries? What are the built-in libraries and what are the key words about them? Is there a differentiated version? Is it related to the RF version? Why does the built-in library need import, some do not need import?

Second: What standard library does the XML built-in library use for Python? What is the basic understanding of this standard library?

Third: How is the built-in library built up? Are basic keywords flexible to use?

IV: Sometimes you may need to modify the built-in library, such as adding some keywords, etc., how to modify?

From the online and official website (http://robotframework.org) to search for some information, organized as follows:

First: The basic concept of built-in libraries?

The built-in library is actually called Standard library in the official website. Other common libraries, such as the Request,seleniumlibrary library, called external libraries, are external libraries, also known as third-party libraries. The standard libraries and external libraries are first correctly differentiated, and for standard libraries, these libraries are directly bound to the RF,

D:\Python27\Lib\site-packages\robot\libraries (depending on the Python installation directory changes) can see, no need to download, while the external library, is required according to personal needs, download and then install the import before you can use. For the standard library, there are two categories, similar to the BUILTIN library is the RF automatically loaded into memory, after installation press F5 can be used directly, do not need to import again, and the XML library needs to import again to normal use. Because the BUILTIN library provides a number of common keywords, such asshould be Equal, Convert to Integer, and so on, so RF will automatically load this common library into memory.

Different versions of RF, support for different built-in libraries and keywords in the same built-in library may also not be the same, with RF3.0 (using the command robot--version to view the RF version), for example, 3.0 is currently the latest RF version, support a lot of built-in libraries, view D:\Python27 \lib\site-packages\robot the py file below, you can see:

The basic official website written 10 standard library can find the corresponding PY file in this area. Builtin,collections,datetime,dialogs,process,operatingsystem,remote (no keywords, not included at the moment), Screenshot,string,telnet, XML. These 11 libraries, some of which are already in the RF2.0, the latest datetime,process,xml is built after RF2.8, that is, if the current version of RF2.8 is used, the built-in library cannot be directly import XML is used, you need to download the installation to use, it is important to note that the different RF versions, the same standard library is also a subtle difference between the need to carefully review the categorization malleability library in each version of the use of the document.

10 Standard library, what is the use of it, it really needs to understand, but also need to spend more time to understand each of the standard library keywords, these 10 standard library, introduced as follows:

The source of this watch is from the official website, and the user manual document has been described in detail. When studying, you can check the relevant documents of the official website in detail.

Second: XML built-in library learning.

From the built-in library of XML source can be seen, RF use is etree to parse XML, part of the source code is as follows:

ImportCopyImportReImportOSTry:     fromlxmlImportetree as Lxml_etreeexceptImporterror:lxml_etree=None fromRobot.apiImportLogger fromRobot.libraries.BuiltInImportBuiltIn fromRobot.utilsImport(asserts, ET, Etsource, is_string, Is_truthy, plural_or_not as s) fromRobot.versionImportget_versionshould_be_equal=Asserts.assert_equalshould_match=BuiltIn (). Should_matchclassXML (object): Robot_library_scope='GLOBAL'robot_library_version=get_version () _xml_declaration= Re.compile ('^<\?xml .*\?>')
def __init__ (self, use_lxml=false):
Use_lxml = Is_truthy (use_lxml)
If Use_lxml and Lxml_etree:
Self.etree = Lxml_etree
Self.modern_etree = True
Self.lxml_etree = True
Else
Self.etree = ET
Self.modern_etree = ET. VERSION >= ' 1.3 '
Self.lxml_etree = False
If Use_lxml and not lxml_etree:
Logger.warn (' XML Library reverted to use standard ElementTree '
' Because lxml module is not installed. ')


def parse_xml (self, Source, Keep_clark_notation=false):
With Etsource (source) as Source:
Tree = self.etree.parse (source)
If Self.lxml_etree:
Strip = (Lxml_etree.comment, Lxml_etree. ProcessingInstruction)
Lxml_etree.strip_elements (tree, *strip, **dict (With_tail=false))
root = Tree.getroot ()
If not Is_truthy (keep_clark_notation):
Namespacestripper (). Strip (Root)
return root

Python provides several standard libraries that can parse XML, and I used the DOM, which is based on the etree of RF, and began to learn the development documentation for the next etree. Learning the operation of an XML file must also have a basic understanding of the XML itself, such as the purpose of XML, tree structure, node type (DOM), and XML with namespaces. The following is a summary of some of the knowledge points:

XML is an Extensible Markup language. Requires that tokens be paired (sometimes abbreviated <b/>). A typical XML document is as follows:

<example>  <first id="1">text</first>  <second id="  2">    <child/>  </second>  <third>    <child>more text</child>    <second id="child"/>    <child>< Grandchild/></child>  </third></example>

A. The entire XML document is a document node, belonging to the root node, such as the <example> node of the above document is a root node, an XML file can only have one root node, otherwise parse when Hu error

B. Each XML tag is an element node, such as <first> and <second>, and <third> belongs to the element node, but belongs to the child node of <example>.

C.attribute value: Represents the attribute value of a node element, such as first has a property ID, the property value is 1;second also has an id attribute, the property value is 2, and third has no attribute.

D.text value: Represents the text content in the element. For example: first the text value is 1;second No, third also not;

One XML also contains other content, such as processing instructions and some annotations, and in Python's etree standard library parsing, the two are eliminated directly. Interested can be based on the official website of the development of documents, some commonly used methods are knocked over, the main is the use of 2 class Element Objects and elementtree Objects.

Third: The learning of XML libraries in RF.

When testing with Sudslibrary for the SOAP protocol, the returned XML is a namespace, which has not been understood before and has a great understanding of the overall learning of the XML library.

The XML library has several functions (translated into the original manual):

A. Parse an XML file, or a string containing XML, in an XML element structure, and from which to look for some elements for further analysis (e.g. Parse XML and Get element keywords).

B. Gets the text or attributes of the element (e.g. get elements text and get element Attribute).

C. Direct validation of text, attributes, or all elements (e.g element text should be and Elements should be Equal).

D. Modify and save it (e.g. Set element Text, Add element and save XML).

following the type of keyword: The parsed XML is the preceding XML example

A. Learning from the most commonly used keywords:

B. Use XPath to search for a child node.

C. Simple parsing of XML with namespaces

D. XML parsing of complex namespaces (supplemented by parsing of XML returned by the SOAP protocol)

These operations are basically around the read and write to the XML, before the message test, encountered the return of the XML is no root element, if the direct use of XML Library is unable to parse, need to add the root node, and then parse, and then directly write a user-defined library. It was also necessary to read the report text field from XML, which was combined with the test data, and then sent to the server, which was not provided by the XML library. But the data of the returned XML is parsed, and the XML library is still relatively in place.    If you feel that the system with the XML library function is not enough to use, or want to put a few functions into a function to use, through the above learning basic can modify the code, and then customize a library. There are a few points of study, the back also need to have a deeper understanding of RF to have a feeling, this study brought me a few new harvest, I looked at the information rarely official documents, although the English has been six levels, but a look at English documents will be dizzy brain swelling, This time forced himself to see the official website of the standard library development documents and user manuals, really feel very good, concise and clear, Learning official website manual is really a good way to learn, than to see some blog harvest more comprehensive more authoritative ~ ~ ~ this skill get ~ ~ ~

 

Summary of learning process for RF built-in libraries-----built-in libraries

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.