Revision: cf58ee12978b
Author: Janne Härkönen <[email protected]>
Date: Fri Jun 29 01:26:08 2012
Log: XML library: Element To String && Log Element
http://code.google.com/p/robotframework/source/detail?r=cf58ee12978b
Added:
/atest/testdata/standard_libraries/xml/to_string.txt
Modified:
/atest/testdata/standard_libraries/xml/test.xml
/src/robot/libraries/XML.py
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/xml/to_string.txt Fri Jun 29
01:26:08 2012
@@ -0,0 +1,17 @@
+*** Settings ***
+Library OperatingSystem
+Resource resource.txt
+
+*** Test cases ***
+Log element
+ Log Element <simple>content</simple>
+ Log Element <root><tag a="1" c="3">päivää</tag></root> DEBUG
+ Log Element ${TEST}
+
+Element to string
+ ${text}= Element To String <simple>content</simple>
+ Should Be Equal ${text} <simple>content</simple>
+ ${text}= Element To String ${TEST} with_preamble=${True}
+ ${expected}= Get File ${TEST}
+ # TODO: Fails because attributes are not ordered
+ Should Be Equal ${text.strip()} ${expected.strip()}
=======================================
--- /atest/testdata/standard_libraries/xml/test.xml Wed Jun 27 07:13:55 2012
+++ /atest/testdata/standard_libraries/xml/test.xml Fri Jun 29 01:26:08 2012
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version='1.0' encoding='UTF-8'?>
<test name="root">
<child>child 1 text</child>
<child id="2">
=======================================
--- /src/robot/libraries/XML.py Thu Jun 28 04:35:54 2012
+++ /src/robot/libraries/XML.py Fri Jun 29 01:26:08 2012
@@ -17,8 +17,9 @@
import re
from functools import partial
-from robot.utils import ET, ETSource
from robot.libraries.BuiltIn import BuiltIn
+from robot.api import logger
+from robot.utils import ET, ETSource
class XML(object):
@@ -124,9 +125,10 @@
normalize_whitespace=False, message=None):
raise NotImplementedError
- def log_element(self, source):
- raise NotImplementedError
-
- def element_to_string(self, source):
- raise NotImplementedError
-
+ def log_element(self, source, level='INFO'):
+ logger.write(self.element_to_string(source), level)
+
+ def element_to_string(self, source, with_preamble=False):
+ method = 'xml' if with_preamble else 'html'
+ return ET.tostring(self.get_element(source),
+ encoding='UTF-8', method=method).decode('UTF-8')