2 new revisions:
Revision: 031a4146ca4b
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Thu Oct 18 01:56:24 2012
Log: XML lib: Documentation enhancements
http://code.google.com/p/robotframework/source/detail?r=031a4146ca4b
Revision: ea118bdba5fd
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Thu Oct 18 01:58:11 2012
Log: XML lib: Implemented, including tests and docs, `Element Should
Not Ha...
http://code.google.com/p/robotframework/source/detail?r=ea118bdba5fd
==============================================================================
Revision: 031a4146ca4b
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Thu Oct 18 01:56:24 2012
Log: XML lib: Documentation enhancements
http://code.google.com/p/robotframework/source/detail?r=031a4146ca4b
Modified:
/src/robot/libraries/XML.py
=======================================
--- /src/robot/libraries/XML.py Wed Oct 17 14:05:19 2012
+++ /src/robot/libraries/XML.py Thu Oct 18 01:56:24 2012
@@ -291,10 +291,11 @@
| ${xml} = | Parse XML | ${CURDIR}/test.xml |
| ${root} = | Parse XML | <root><child/></root> |
- For more details and examples, see `Parsing XML` section in the
- `introduction`.
+ Use `Get Element` keyword if you want to get a certain element and
not
+ the whole structure. See `Parsing XML` section for more details and
+ examples
- See also `Get Element` and `Get Elements`.
+ TODO: document namespace handling (new in 2.7.5)
"""
with ETSource(source) as source:
root = ET.parse(source).getroot()
@@ -327,7 +328,9 @@
| ${element} = | Get Element | ${XML} | second |
| ${child} = | Get Element | ${element} | child |
- See also `Parse XML` and `Get Elements`.
+ `Parse XML` is recommended for parsing XML when the whole structure
+ is needed. It must be used if there is a need to configure how XML
+ namespaces are handled.
"""
elements = self.get_elements(source, xpath)
if len(elements) != 1:
@@ -362,8 +365,6 @@
| Length Should Be | ${children} | 2 | |
| ${children} = | Get Elements | ${XML} | first/child |
| Should Be Empty | ${children} | | |
-
- See also `Get Element`.
"""
if isinstance(source, basestring):
source = self.parse_xml(source)
@@ -518,9 +519,6 @@
| Length Should Be | ${texts} | 2 | |
| Should Be Equal | @{texts}[0] | more text | |
| Should Be Equal | @{texts}[1] | ${EMPTY} | |
-
- See also `Get Element Text`, `Element Text Should Be` and
- `Element Text Should Match`.
"""
return [self.get_element_text(elem,
normalize_whitespace=normalize_whitespace)
for elem in self.get_elements(source, xpath)]
@@ -539,16 +537,14 @@
The keyword passes if the text of the element is equal to the
`expected` value, and otherwise it fails. The default error
message can
- be overridden with the `message` argument.
+ be overridden with the `message` argument. Use `Element Text
Should
+ Match` to verify the text against a pattern instead of an exact
value.
Examples using `${XML}` structure from the `introduction`:
| Element Text Should Be | ${XML} | text |
xpath=first |
| Element Text Should Be | ${XML} | ${EMPTY} |
xpath=second/child |
| ${paragraph} = | Get Element | ${XML} |
xpath=html/p |
| Element Text Should Be | ${paragraph} | Text with bold and
italics. | normalize_whitespace=yes |
-
- See also `Get Element Text`, `Get Elements Texts` and
- `Element Text Should Match`.
"""
text = self.get_element_text(source, xpath, normalize_whitespace)
should_be_equal(text, expected, message, values=False)
@@ -569,9 +565,6 @@
| Element Text Should Match | ${XML} | t??? | xpath=first
|
| ${paragraph} = | Get Element | ${XML} | xpath=html/p
|
| Element Text Should Match | ${paragraph} | Text with * and *. |
normalize_whitespace=yes |
-
- See also `Get Element Text`, `Get Elements Texts` and
- `Element Text Should Be`.
"""
text = self.get_element_text(source, xpath, normalize_whitespace)
should_match(text, pattern, message, values=False)
@@ -594,7 +587,7 @@
| Should Be Equal | ${attribute} | value |
| |
See also `Get Element Attributes`, `Element Attribute Should Be`,
- and `Element Attribute Should Match`.
+ `Element Attribute Should Match` and `Element Should Not Have
Attribute`.
"""
return self.get_element(source, xpath).get(name, default)
@@ -614,8 +607,7 @@
| ${attributes} = | Get Element Attributes | ${XML} | third |
| Should Be Empty | ${attributes} | | |
- See also `Get Element Attribute`, `Element Attribute Should Be`,
- and `Element Attribute Should Match`.
+ Use `Get Element Attribute` to get the value of a single attribute.
"""
return self.get_element(source, xpath).attrib.copy()
@@ -628,17 +620,18 @@
keyword.
The keyword passes if the attribute `name` of the element is equal
to
- the `expected` value, and otherwise it fails. To test that the
element
- does not have certain attribute, use Python `None` (i.e. variable
- `${NONE}`) as the `expected` value. The default error message can
be
- overridden with the `message` argument.
+ the `expected` value, and otherwise it fails. The default error
message
+ can be overridden with the `message` argument.
+
+ To test that the element does not have a certain attribute, Python
+ `None` (i.e. variable `${NONE}`) can be used as the `expected`
value.
+ A cleaner alternative is using `Element Should Not Have Attribute`.
Examples using `${XML}` structure from the `introduction`:
| Element Attribute Should Be | ${XML} | id | 1 |
xpath=first |
| Element Attribute Should Be | ${XML} | id | ${NONE}
| |
- See also `Get Element Attribute`, `Get Element Attributes` and
- `Element Text Should Match`.
+ See also `Element Attribute Should Match` and `Get Element
Attribute`.
"""
attr = self.get_element_attribute(source, name, xpath)
should_be_equal(attr, expected, message, values=False)
@@ -658,9 +651,6 @@
Examples using `${XML}` structure from the `introduction`:
| Element Attribute Should Match | ${XML} | id | ? | xpath=first
|
| Element Attribute Should Match | ${XML} | id | c*d |
xpath=third/second |
-
- See also `Get Element Attribute`, `Get Element Attributes` and
- `Element Text Should Be`.
"""
attr = self.get_element_attribute(source, name, xpath)
if attr is None:
==============================================================================
Revision: ea118bdba5fd
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Thu Oct 18 01:58:11 2012
Log: XML lib: Implemented, including tests and docs, `Element Should
Not Have Attribute` keyword.
Update issue 1260
Status: Done
http://code.google.com/p/robotframework/source/detail?r=ea118bdba5fd
Modified:
/atest/robot/standard_libraries/xml/element_attribute.txt
/atest/testdata/standard_libraries/xml/element_attribute.txt
/src/robot/libraries/XML.py
=======================================
--- /atest/robot/standard_libraries/xml/element_attribute.txt Wed Jul 25
09:10:36 2012
+++ /atest/robot/standard_libraries/xml/element_attribute.txt Thu Oct 18
01:58:11 2012
@@ -42,6 +42,12 @@
Element attribute should match with custom error message
Check Test Case ${TESTNAME}
+
+Element should not have attribute
+ Check Test Case ${TESTNAME}
+
+Element should not have attribute with custom error message
+ Check Test Case ${TESTNAME}
Non-ASCII
Check Test Case ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/xml/element_attribute.txt Mon Sep 24
03:17:56 2012
+++ /atest/testdata/standard_libraries/xml/element_attribute.txt Thu Oct 18
01:58:11 2012
@@ -61,6 +61,16 @@
[Documentation] FAIL Special
Element Attribute Should Match <tag a="1"/> a ??
message=Special
+Element should not have attribute
+ [Documentation] FAIL Attribute 'y' exists and has value '3'.
+ Element Should Not Have Attribute <elem/> attr
+ Element Should Not Have Attribute <r x="1"><c y="2"/></r> x
xpath=c
+ Element Should Not Have Attribute <r x="1"><c y="3"/></r> y
xpath=c
+
+Element should not have attribute with custom error message
+ [Documentation] FAIL Custom
+ Element Should Not Have Attribute <elem id="1"/> id
message=Custom
+
Non-ASCII
${attr}= Get Element Attribute <täg ä='ö'/> ä
Should Be Equal ${attr} ö
=======================================
--- /src/robot/libraries/XML.py Thu Oct 18 01:56:24 2012
+++ /src/robot/libraries/XML.py Thu Oct 18 01:58:11 2012
@@ -657,6 +657,30 @@
raise AssertionError("Attribute '%s' does not exist." % name)
should_match(attr, pattern, message, values=False)
+ def element_should_not_have_attribute(self, source, name, xpath='.',
message=None):
+ """Verifies that the specified element does not have attribute
`name`.
+
+ The element whose attribute is verified is specified using `source`
+ and `xpath`. They have exactly the same semantics as with `Get
Element`
+ keyword.
+
+ The keyword fails if the specified element has attribute `name`.
+ The default error message can be overridden with the `message`
argument.
+
+ Examples using `${XML}` structure from the `introduction`:
+ | Element Should Not Have Attribute | ${XML} | id |
+ | Element Should Not Have Attribute | ${XML} | xxx | xpath=first |
+
+ See also `Get Element Attribute`, `Get Element Attributes`,
+ `Element Text Should Be` and `Element Text Should Match`.
+
+ New in Robot Framework 2.7.5.
+ """
+ attr = self.get_element_attribute(source, name, xpath)
+ if attr is not None:
+ raise AssertionError(message or "Attribute '%s' exists and "
+ "has value '%s'." % (name,
attr))
+
def elements_should_be_equal(self, source, expected,
exclude_children=False,
normalize_whitespace=False):
"""Verifies that the given `source` element is equal to `expected`.