Revision: 97c08af4d783
Branch: default
Author: Pekka Klärck
Date: Wed May 28 20:07:28 2014 UTC
Log: XML: Implemented 'Evaluate Xpath' keyword.
Update issue 1623
Implemented 'Evaluate Xpath' keyword. Tests can be used to see examples of
some pretty funky expressions. Documentation of the new keyword is missing.
CSS selector support will not be implemented at least at this point. Thus
the only missing task is updating docs.
http://code.google.com/p/robotframework/source/detail?r=97c08af4d783
Modified:
/atest/robot/standard_libraries/xml/xpath.txt
/atest/robot/standard_libraries/xml/xpath_with_lxml.txt
/atest/testdata/standard_libraries/xml/xpath.txt
/atest/testdata/standard_libraries/xml/xpath_with_lxml.txt
/src/robot/libraries/XML.py
=======================================
--- /atest/robot/standard_libraries/xml/xpath.txt Wed May 28 14:33:17 2014
UTC
+++ /atest/robot/standard_libraries/xml/xpath.txt Wed May 28 20:07:28 2014
UTC
@@ -60,6 +60,9 @@
Warning when using more complex non-ASCII xpath with interpreter < 2.7
Run Keyword If ET < 1.3 Verify Non-ASCII xpath error
+
+Evaluate xpath does not work
+ Check Test Case ${TESTNAME}
*** Keywords ***
Make Tests Requiring ET 1.3 Non-Critical If Requirement Not Met
=======================================
--- /atest/robot/standard_libraries/xml/xpath_with_lxml.txt Wed May 28
14:44:41 2014 UTC
+++ /atest/robot/standard_libraries/xml/xpath_with_lxml.txt Wed May 28
20:07:28 2014 UTC
@@ -55,3 +55,6 @@
Advanced xpath supported by lxml matching multiple elements
Check Test Case ${TESTNAME}
+
+Evaluate xpath
+ Check Test Case ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/xml/xpath.txt Wed May 28 14:33:17
2014 UTC
+++ /atest/testdata/standard_libraries/xml/xpath.txt Wed May 28 20:07:28
2014 UTC
@@ -80,6 +80,10 @@
[Documentation] FAIL Multiple elements (2) matching './/chïld'
found.
.//chïld chïld xml=<rööt><chïld/><täg><chïld/></täg></rööt>
+Evaluate xpath does not work
+ [Documentation] FAIL 'Evaluate Xpath' keyword only works in lxml
mode.
+ [Template] NONE
+ Evaluate Xpath ${TEST} .
*** Keywords ***
Xpath should match element
=======================================
--- /atest/testdata/standard_libraries/xml/xpath_with_lxml.txt Wed May 28
14:44:41 2014 UTC
+++ /atest/testdata/standard_libraries/xml/xpath_with_lxml.txt Wed May 28
20:07:28 2014 UTC
@@ -85,6 +85,10 @@
(//child)[last()] child text
(child/grandchild)[last()] grandchild ${NONE}
(child | another | xxx)[last()] another
+ self::test test
+ child::child[1]/parent::test test
+ descendant::ggc/parent::* grandchild
+ descendant::ggc/ancestor::child[attribute::id] child
Advanced xpath supported by lxml matching multiple elements
[Template] Xpath should match elements
@@ -93,6 +97,19 @@
child[starts-with(normalize-space(text()), 'child')]
... child 1 text child 2 text grand child
text more text
+Evaluate xpath
+ [Template] Result of evaluation should be
+ count(*) ${4}
+ count(child[3]) ${1}
+ count(preceding-sibling::*) ${0}
+ count(*) ${1} context=child[3]
+ count(preceding-sibling::*) ${2} context=child[3]
+ string(child[1]) child 1 text
+ string() child 1 text context=child[1]
+ contains(child[1], '1 text') ${True}
+ string(child::child[last()]/ancestor::test/attribute::name) root
+ string(descendant::ggc/ancestor::child[attribute::id=3]/@a2) xxx
+
*** Keywords ***
Xpath should match element
[Arguments] ${xpath} ${tag} ${text}=IGNORE ${xml}=${TEST}
@@ -104,3 +121,8 @@
[Arguments] ${xpath} @{expected texts}
${texts} = Get Elements Texts ${TEST} ${xpath}
normalize_whitespace=yes
Lists Should be Equal ${texts} ${expected texts}
+
+Result of evaluation should be
+ [Arguments] ${xpath} ${expected} ${xml}=${TEST}
${context}=.
+ ${result} = Evaluate xpath ${xml} ${xpath}
context=${context}
+ Should Be Equal ${result} ${expected}
=======================================
--- /src/robot/libraries/XML.py Wed May 28 14:44:41 2014 UTC
+++ /src/robot/libraries/XML.py Wed May 28 20:07:28 2014 UTC
@@ -1176,6 +1176,11 @@
with open(path, 'w') as output:
tree.write(output, encoding=encoding, **xml_declaration)
+ def evaluate_xpath(self, source, xpath, context='.'):
+ if not self.lxml_etree:
+ raise RuntimeError("'Evaluate Xpath' keyword only works in
lxml mode.")
+ return self.get_element(source, context).xpath(xpath)
+
class NameSpaceStripper(object):
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.