Robot Framework Integrated Development Environment (RIDE)
XML.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import copy
17 import re
18 import os
19 
20 try:
21  from lxml import etree as lxml_etree
22 except ImportError:
23  lxml_etree = None
24 
25 from robotide.lib.robot.api import logger
26 from robotide.lib.robot.libraries.BuiltIn import BuiltIn
27 from robotide.lib.robot.utils import (asserts, ET, ETSource, is_falsy, is_string, is_truthy,
28  plural_or_not as s)
29 from robotide.lib.robot.version import get_version
30 
31 
32 should_be_equal = asserts.assert_equal
33 should_match = BuiltIn().should_match
34 
35 
36 
453 class XML():
454  ROBOT_LIBRARY_SCOPE = 'GLOBAL'
455  ROBOT_LIBRARY_VERSION = get_version()
456 
459  _xml_declaration = re.compile('^<\?xml .*\?>')
460 
461 
473  def __init__(self, use_lxml=False):
474  use_lxml = is_truthy(use_lxml)
475  if use_lxml and lxml_etree:
476  self.etreeetree = lxml_etree
477  self.modern_etreemodern_etree = True
478  self.lxml_etreelxml_etree = True
479  else:
480  self.etreeetree = ET
481  self.modern_etreemodern_etree = ET.VERSION >= '1.3'
482  self.lxml_etreelxml_etree = False
483  if use_lxml and not lxml_etree:
484  logger.warn('XML library reverted to use standard ElementTree '
485  'because lxml module is not installed.')
486  self._ns_stripper_ns_stripper = NameSpaceStripper(self.etreeetree, self.lxml_etreelxml_etree)
487 
488 
519  def parse_xml(self, source, keep_clark_notation=False, strip_namespaces=False):
520  with ETSource(source) as source:
521  tree = self.etreeetree.parse(source)
522  if self.lxml_etreelxml_etree:
523  strip = (lxml_etree.Comment, lxml_etree.ProcessingInstruction)
524  lxml_etree.strip_elements(tree, *strip, **dict(with_tail=False))
525  root = tree.getroot()
526  if not is_truthy(keep_clark_notation):
527  self._ns_stripper_ns_stripper.strip(root, preserve=is_falsy(strip_namespaces))
528  return root
529 
530 
555  def get_element(self, source, xpath='.'):
556  elements = self.get_elementsget_elements(source, xpath)
557  if len(elements) != 1:
558  self._raise_wrong_number_of_matches_raise_wrong_number_of_matches(len(elements), xpath)
559  return elements[0]
560 
561  def _raise_wrong_number_of_matches(self, count, xpath, message=None):
562  if not message:
563  message = self._wrong_number_of_matches_wrong_number_of_matches(count, xpath)
564  raise AssertionError(message)
565 
566  def _wrong_number_of_matches(self, count, xpath):
567  if not count:
568  return "No element matching '%s' found." % xpath
569  if count == 1:
570  return "One element matching '%s' found." % xpath
571  return "Multiple elements (%d) matching '%s' found." % (count, xpath)
572 
573 
589  def get_elements(self, source, xpath):
590  if is_string(source):
591  source = self.parse_xmlparse_xml(source)
592  finder = ElementFinder(self.etreeetree, self.modern_etreemodern_etree, self.lxml_etreelxml_etree)
593  return finder.find_all(source, xpath)
594 
595 
610  def get_child_elements(self, source, xpath='.'):
611  return list(self.get_elementget_element(source, xpath))
612 
613 
620  def get_element_count(self, source, xpath='.'):
621  count = len(self.get_elementsget_elements(source, xpath))
622  logger.info("%d element%s matched '%s'." % (count, s(count), xpath))
623  return count
624 
625 
635  def element_should_exist(self, source, xpath='.', message=None):
636  count = self.get_element_countget_element_count(source, xpath)
637  if not count:
638  self._raise_wrong_number_of_matches_raise_wrong_number_of_matches(count, xpath, message)
639 
640 
650  def element_should_not_exist(self, source, xpath='.', message=None):
651  count = self.get_element_countget_element_count(source, xpath)
652  if count:
653  self._raise_wrong_number_of_matches_raise_wrong_number_of_matches(count, xpath, message)
654 
655 
685  def get_element_text(self, source, xpath='.', normalize_whitespace=False):
686  element = self.get_elementget_element(source, xpath)
687  text = ''.join(self._yield_texts_yield_texts(element))
688  if is_truthy(normalize_whitespace):
689  text = self._normalize_whitespace_normalize_whitespace(text)
690  return text
691 
692  def _yield_texts(self, element, top=True):
693  if element.text:
694  yield element.text
695  for child in element:
696  for text in self._yield_texts_yield_texts(child, top=False):
697  yield text
698  if element.tail and not top:
699  yield element.tail
700 
701  def _normalize_whitespace(self, text):
702  return ' '.join(text.split())
703 
704 
720  def get_elements_texts(self, source, xpath, normalize_whitespace=False):
721  return [self.get_element_textget_element_text(elem, normalize_whitespace=normalize_whitespace)
722  for elem in self.get_elementsget_elements(source, xpath)]
723 
724 
746  def element_text_should_be(self, source, expected, xpath='.',
747  normalize_whitespace=False, message=None):
748  text = self.get_element_textget_element_text(source, xpath, normalize_whitespace)
749  should_be_equal(text, expected, message, values=False)
750 
751 
766  def element_text_should_match(self, source, pattern, xpath='.',
767  normalize_whitespace=False, message=None):
768  text = self.get_element_textget_element_text(source, xpath, normalize_whitespace)
769  should_match(text, pattern, message, values=False)
770 
771 
790  def get_element_attribute(self, source, name, xpath='.', default=None):
791  return self.get_elementget_element(source, xpath).get(name, default)
792 
793 
810  def get_element_attributes(self, source, xpath='.'):
811  return dict(self.get_elementget_element(source, xpath).attrib)
812 
813 
833  def element_attribute_should_be(self, source, name, expected, xpath='.',
834  message=None):
835  attr = self.get_element_attributeget_element_attribute(source, name, xpath)
836  should_be_equal(attr, expected, message, values=False)
837 
838 
852  def element_attribute_should_match(self, source, name, pattern, xpath='.',
853  message=None):
854  attr = self.get_element_attributeget_element_attribute(source, name, xpath)
855  if attr is None:
856  raise AssertionError("Attribute '%s' does not exist." % name)
857  should_match(attr, pattern, message, values=False)
858 
859 
875  def element_should_not_have_attribute(self, source, name, xpath='.', message=None):
876  attr = self.get_element_attributeget_element_attribute(source, name, xpath)
877  if attr is not None:
878  raise AssertionError(message or "Attribute '%s' exists and "
879  "has value '%s'." % (name, attr))
880 
881 
916  def elements_should_be_equal(self, source, expected, exclude_children=False,
917  normalize_whitespace=False):
918  self._compare_elements_compare_elements(source, expected, should_be_equal,
919  exclude_children, normalize_whitespace)
920 
921 
937  def elements_should_match(self, source, expected, exclude_children=False,
938  normalize_whitespace=False):
939  self._compare_elements_compare_elements(source, expected, should_match,
940  exclude_children, normalize_whitespace)
941 
942  def _compare_elements(self, source, expected, comparator, exclude_children,
943  normalize_whitespace):
944  normalizer = self._normalize_whitespace_normalize_whitespace \
945  if is_truthy(normalize_whitespace) else None
946  comparator = ElementComparator(comparator, normalizer, exclude_children)
947  comparator.compare(self.get_elementget_element(source), self.get_elementget_element(expected))
948 
949 
966  def set_element_tag(self, source, tag, xpath='.'):
967  source = self.get_elementget_element(source)
968  self.get_elementget_element(source, xpath).tag = tag
969  return source
970 
971 
976  def set_elements_tag(self, source, tag, xpath='.'):
977  for elem in self.get_elementsget_elements(source, xpath):
978  self.set_element_tagset_element_tag(elem, tag)
979 
980 
1002  def set_element_text(self, source, text=None, tail=None, xpath='.'):
1003  source = self.get_elementget_element(source)
1004  element = self.get_elementget_element(source, xpath)
1005  if text is not None:
1006  element.text = text
1007  if tail is not None:
1008  element.tail = tail
1009  return source
1010 
1011 
1016  def set_elements_text(self, source, text=None, tail=None, xpath='.'):
1017  for elem in self.get_elementsget_elements(source, xpath):
1018  self.set_element_textset_element_text(elem, text, tail)
1019 
1020 
1040  def set_element_attribute(self, source, name, value, xpath='.'):
1041  if not name:
1042  raise RuntimeError('Attribute name can not be empty.')
1043  source = self.get_elementget_element(source)
1044  self.get_elementget_element(source, xpath).attrib[name] = value
1045  return source
1046 
1047 
1052  def set_elements_attribute(self, source, name, value, xpath='.'):
1053  for elem in self.get_elementsget_elements(source, xpath):
1054  self.set_element_attributeset_element_attribute(elem, name, value)
1055 
1056 
1074  def remove_element_attribute(self, source, name, xpath='.'):
1075  source = self.get_elementget_element(source)
1076  attrib = self.get_elementget_element(source, xpath).attrib
1077  if name in attrib:
1078  attrib.pop(name)
1079  return source
1080 
1081 
1086  def remove_elements_attribute(self, source, name, xpath='.'):
1087  for elem in self.get_elementsget_elements(source, xpath):
1088  self.remove_element_attributeremove_element_attribute(elem, name)
1089 
1090 
1107  def remove_element_attributes(self, source, xpath='.'):
1108  source = self.get_elementget_element(source)
1109  self.get_elementget_element(source, xpath).attrib.clear()
1110  return source
1111 
1112 
1117  def remove_elements_attributes(self, source, xpath='.'):
1118  for elem in self.get_elementsget_elements(source, xpath):
1119  self.remove_element_attributesremove_element_attributes(elem)
1120 
1121 
1147  def add_element(self, source, element, index=None, xpath='.'):
1148  source = self.get_elementget_element(source)
1149  parent = self.get_elementget_element(source, xpath)
1150  element = self.copy_elementcopy_element(element)
1151  if index is None:
1152  parent.append(element)
1153  else:
1154  parent.insert(int(index), element)
1155  return source
1156 
1157 
1178  def remove_element(self, source, xpath='', remove_tail=False):
1179  source = self.get_elementget_element(source)
1180  self._remove_element_remove_element(source, self.get_elementget_element(source, xpath), remove_tail)
1181  return source
1182 
1183 
1201  def remove_elements(self, source, xpath='', remove_tail=False):
1202  source = self.get_elementget_element(source)
1203  for element in self.get_elementsget_elements(source, xpath):
1204  self._remove_element_remove_element(source, element, remove_tail)
1205  return source
1206 
1207  def _remove_element(self, root, element, remove_tail=False):
1208  parent = self._find_parent_find_parent(root, element)
1209  if not is_truthy(remove_tail):
1210  self._preserve_tail_preserve_tail(element, parent)
1211  parent.remove(element)
1212 
1213  def _find_parent(self, root, element):
1214  for parent in root.getiterator():
1215  for child in parent:
1216  if child is element:
1217  return parent
1218  raise RuntimeError('Cannot remove root element.')
1219 
1220  def _preserve_tail(self, element, parent):
1221  if not element.tail:
1222  return
1223  index = list(parent).index(element)
1224  if index == 0:
1225  parent.text = (parent.text or '') + element.tail
1226  else:
1227  sibling = parent[index-1]
1228  sibling.tail = (sibling.tail or '') + element.tail
1229 
1230 
1254  def clear_element(self, source, xpath='.', clear_tail=False):
1255  source = self.get_elementget_element(source)
1256  element = self.get_elementget_element(source, xpath)
1257  tail = element.tail
1258  element.clear()
1259  if not is_truthy(clear_tail):
1260  element.tail = tail
1261  return source
1262 
1263 
1281  def copy_element(self, source, xpath='.'):
1282  return copy.deepcopy(self.get_elementget_element(source, xpath))
1283 
1284 
1296  def element_to_string(self, source, xpath='.', encoding=None):
1297  source = self.get_elementget_element(source, xpath)
1298  string = self.etreeetree.tostring(source, encoding='UTF-8').decode('UTF-8')
1299  string = self._xml_declaration_xml_declaration.sub('', string).strip()
1300  if encoding:
1301  string = string.encode(encoding)
1302  return string
1303 
1304 
1312  def log_element(self, source, level='INFO', xpath='.'):
1313  string = self.element_to_stringelement_to_string(source, xpath)
1314  logger.write(string, level)
1315  return string
1316 
1317 
1336  def save_xml(self, source, path, encoding='UTF-8'):
1337  path = os.path.abspath(path.replace('/', os.sep))
1338  elem = self.get_elementget_element(source)
1339  tree = self.etreeetree.ElementTree(elem)
1340  config = {'encoding': encoding}
1341  if self.modern_etreemodern_etree:
1342  config['xml_declaration'] = True
1343  if self.lxml_etreelxml_etree:
1344  elem = self._ns_stripper_ns_stripper.unstrip(elem)
1345  # https://bugs.launchpad.net/lxml/+bug/1660433
1346  if tree.docinfo.doctype:
1347  config['doctype'] = tree.docinfo.doctype
1348  tree = self.etreeetree.ElementTree(elem)
1349  with open(path, 'wb') as output:
1350  if 'doctype' in config:
1351  output.write(self.etreeetree.tostring(tree, **config))
1352  else:
1353  tree.write(output, **config)
1354  logger.info('XML saved to <a href="file://%s">%s</a>.' % (path, path),
1355  html=True)
1356 
1357 
1378  def evaluate_xpath(self, source, expression, context='.'):
1379  if not self.lxml_etreelxml_etree:
1380  raise RuntimeError("'Evaluate Xpath' keyword only works in lxml mode.")
1381  return self.get_elementget_element(source, context).xpath(expression)
1382 
1383 
1385 
1386  def __init__(self, etree, lxml_etree=False):
1387  self.etreeetree = etree
1388  self.lxml_treelxml_tree = lxml_etree
1389 
1390  def strip(self, elem, preserve=True, current_ns=None, top=True):
1391  if elem.tag.startswith('{') and '}' in elem.tag:
1392  ns, elem.tag = elem.tag[1:].split('}', 1)
1393  if preserve and ns != current_ns:
1394  elem.attrib['xmlns'] = ns
1395  current_ns = ns
1396  elif current_ns:
1397  elem.attrib['xmlns'] = ''
1398  current_ns = None
1399  for child in elem:
1400  self.stripstrip(child, preserve, current_ns, top=False)
1401  if top and not preserve and self.lxml_treelxml_tree:
1402  self.etreeetree.cleanup_namespaces(elem)
1403 
1404  def unstrip(self, elem, current_ns=None, copied=False):
1405  if not copied:
1406  elem = copy.deepcopy(elem)
1407  ns = elem.attrib.pop('xmlns', current_ns)
1408  if ns:
1409  elem.tag = '{%s}%s' % (ns, elem.tag)
1410  for child in elem:
1411  self.unstripunstrip(child, ns, copied=True)
1412  return elem
1413 
1414 
1416 
1417  def __init__(self, etree, modern=True, lxml=False):
1418  self.etreeetree = etree
1419  self.modernmodern = modern
1420  self.lxmllxml = lxml
1421 
1422  def find_all(self, elem, xpath):
1423  xpath = self._get_xpath_get_xpath(xpath)
1424  if xpath == '.': # ET < 1.3 does not support '.' alone.
1425  return [elem]
1426  if not self.lxmllxml:
1427  return elem.findall(xpath)
1428  finder = self.etreeetree.ETXPath(xpath)
1429  return finder(elem)
1430 
1431  def _get_xpath(self, xpath):
1432  if not xpath:
1433  raise RuntimeError('No xpath given.')
1434  if self.modernmodern:
1435  return xpath
1436  try:
1437  return str(xpath)
1438  except UnicodeError:
1439  if not xpath.replace('/', '').isalnum():
1440  logger.warn('XPATHs containing non-ASCII characters and '
1441  'other than tag names do not always work with '
1442  'Python versions prior to 2.7. Verify results '
1443  'manually and consider upgrading to 2.7.')
1444  return xpath
1445 
1446 
1448 
1449  def __init__(self, comparator, normalizer=None, exclude_children=False):
1450  self._comparator_comparator = comparator
1451  self._normalizer_normalizer = normalizer or (lambda text: text)
1452  self._exclude_children_exclude_children = is_truthy(exclude_children)
1453 
1454  def compare(self, actual, expected, location=None):
1455  if not location:
1456  location = Location(actual.tag)
1457  self._compare_tags_compare_tags(actual, expected, location)
1458  self._compare_attributes_compare_attributes(actual, expected, location)
1459  self._compare_texts_compare_texts(actual, expected, location)
1460  if location.is_not_root:
1461  self._compare_tails_compare_tails(actual, expected, location)
1462  if not self._exclude_children_exclude_children:
1463  self._compare_children_compare_children(actual, expected, location)
1464 
1465  def _compare_tags(self, actual, expected, location):
1466  self._compare_compare(actual.tag, expected.tag, 'Different tag name', location,
1467  should_be_equal)
1468 
1469  def _compare(self, actual, expected, message, location, comparator=None):
1470  if location.is_not_root:
1471  message = "%s at '%s'" % (message, location.path)
1472  if not comparator:
1473  comparator = self._comparator_comparator
1474  comparator(actual, expected, message)
1475 
1476  def _compare_attributes(self, actual, expected, location):
1477  self._compare_compare(sorted(actual.attrib), sorted(expected.attrib),
1478  'Different attribute names', location, should_be_equal)
1479  for key in actual.attrib:
1480  self._compare_compare(actual.attrib[key], expected.attrib[key],
1481  "Different value for attribute '%s'" % key, location)
1482 
1483  def _compare_texts(self, actual, expected, location):
1484  self._compare_compare(self._text_text(actual.text), self._text_text(expected.text),
1485  'Different text', location)
1486 
1487  def _text(self, text):
1488  return self._normalizer_normalizer(text or '')
1489 
1490  def _compare_tails(self, actual, expected, location):
1491  self._compare_compare(self._text_text(actual.tail), self._text_text(expected.tail),
1492  'Different tail text', location)
1493 
1494  def _compare_children(self, actual, expected, location):
1495  self._compare_compare(len(actual), len(expected), 'Different number of child elements',
1496  location, should_be_equal)
1497  for act, exp in zip(actual, expected):
1498  self.comparecompare(act, exp, location.child(act.tag))
1499 
1500 
1501 class Location():
1502 
1503  def __init__(self, path, is_root=True):
1504  self.pathpath = path
1505  self.is_not_rootis_not_root = not is_root
1506  self._children_children = {}
1507 
1508  def child(self, tag):
1509  if tag not in self._children_children:
1510  self._children_children[tag] = 1
1511  else:
1512  self._children_children[tag] += 1
1513  tag += '[%d]' % self._children_children[tag]
1514  return Location('%s/%s' % (self.pathpath, tag), is_root=False)
An always available standard library with often needed keywords.
Definition: BuiltIn.py:3551
def __init__(self, comparator, normalizer=None, exclude_children=False)
Definition: XML.py:1449
def _compare_texts(self, actual, expected, location)
Definition: XML.py:1483
def _compare_tails(self, actual, expected, location)
Definition: XML.py:1490
def compare(self, actual, expected, location=None)
Definition: XML.py:1454
def _compare_children(self, actual, expected, location)
Definition: XML.py:1494
def _compare(self, actual, expected, message, location, comparator=None)
Definition: XML.py:1469
def _compare_tags(self, actual, expected, location)
Definition: XML.py:1465
def _compare_attributes(self, actual, expected, location)
Definition: XML.py:1476
def __init__(self, etree, modern=True, lxml=False)
Definition: XML.py:1417
def __init__(self, path, is_root=True)
Definition: XML.py:1503
def strip(self, elem, preserve=True, current_ns=None, top=True)
Definition: XML.py:1390
def __init__(self, etree, lxml_etree=False)
Definition: XML.py:1386
def unstrip(self, elem, current_ns=None, copied=False)
Definition: XML.py:1404
Robot Framework test library for verifying and modifying XML documents.
Definition: XML.py:453
def remove_element_attribute(self, source, name, xpath='.')
Removes attribute name from the specified element.
Definition: XML.py:1074
def set_elements_text(self, source, text=None, tail=None, xpath='.')
Sets text and/or tail text of the specified elements.
Definition: XML.py:1016
def remove_element_attributes(self, source, xpath='.')
Removes all attributes from the specified element.
Definition: XML.py:1107
def _compare_elements(self, source, expected, comparator, exclude_children, normalize_whitespace)
Definition: XML.py:943
def save_xml(self, source, path, encoding='UTF-8')
Saves the given element to the specified file.
Definition: XML.py:1336
def element_should_exist(self, source, xpath='.', message=None)
Verifies that one or more element match the given xpath.
Definition: XML.py:635
def _raise_wrong_number_of_matches(self, count, xpath, message=None)
Definition: XML.py:561
def elements_should_match(self, source, expected, exclude_children=False, normalize_whitespace=False)
Verifies that the given source element matches expected.
Definition: XML.py:938
def set_element_attribute(self, source, name, value, xpath='.')
Sets attribute name of the specified element to value.
Definition: XML.py:1040
def element_attribute_should_be(self, source, name, expected, xpath='.', message=None)
Verifies that the specified attribute is expected.
Definition: XML.py:834
def elements_should_be_equal(self, source, expected, exclude_children=False, normalize_whitespace=False)
Verifies that the given source element is equal to expected.
Definition: XML.py:917
def set_elements_tag(self, source, tag, xpath='.')
Sets the tag of the specified elements.
Definition: XML.py:976
def _wrong_number_of_matches(self, count, xpath)
Definition: XML.py:566
def element_should_not_exist(self, source, xpath='.', message=None)
Verifies that no element match the given xpath.
Definition: XML.py:650
def set_elements_attribute(self, source, name, value, xpath='.')
Sets attribute name of the specified elements to value.
Definition: XML.py:1052
def get_child_elements(self, source, xpath='.')
Returns the child elements of the specified element as a list.
Definition: XML.py:610
def __init__(self, use_lxml=False)
Import library with optionally lxml mode enabled.
Definition: XML.py:473
def element_to_string(self, source, xpath='.', encoding=None)
Returns the string representation of the specified element.
Definition: XML.py:1296
def get_elements(self, source, xpath)
Returns a list of elements in the source matching the xpath.
Definition: XML.py:589
def _preserve_tail(self, element, parent)
Definition: XML.py:1220
def log_element(self, source, level='INFO', xpath='.')
Logs the string representation of the specified element.
Definition: XML.py:1312
def _find_parent(self, root, element)
Definition: XML.py:1213
def evaluate_xpath(self, source, expression, context='.')
Evaluates the given xpath expression and returns results.
Definition: XML.py:1378
def get_elements_texts(self, source, xpath, normalize_whitespace=False)
Returns text of all elements matching xpath as a list.
Definition: XML.py:720
def _normalize_whitespace(self, text)
Definition: XML.py:701
def get_element_attributes(self, source, xpath='.')
Returns all attributes of the specified element.
Definition: XML.py:810
def add_element(self, source, element, index=None, xpath='.')
Adds a child element to the specified element.
Definition: XML.py:1147
def parse_xml(self, source, keep_clark_notation=False, strip_namespaces=False)
Parses the given XML file or string into an element structure.
Definition: XML.py:519
def get_element_text(self, source, xpath='.', normalize_whitespace=False)
Returns all text of the element, possibly whitespace normalized.
Definition: XML.py:685
def _remove_element(self, root, element, remove_tail=False)
Definition: XML.py:1207
def get_element_attribute(self, source, name, xpath='.', default=None)
Returns the named attribute of the specified element.
Definition: XML.py:790
def remove_elements_attributes(self, source, xpath='.')
Removes all attributes from the specified elements.
Definition: XML.py:1117
def element_should_not_have_attribute(self, source, name, xpath='.', message=None)
Verifies that the specified element does not have attribute name.
Definition: XML.py:875
def remove_elements(self, source, xpath='', remove_tail=False)
Removes all elements matching xpath from the source structure.
Definition: XML.py:1201
def element_text_should_be(self, source, expected, xpath='.', normalize_whitespace=False, message=None)
Verifies that the text of the specified element is expected.
Definition: XML.py:747
def remove_elements_attribute(self, source, name, xpath='.')
Removes attribute name from the specified elements.
Definition: XML.py:1086
def set_element_text(self, source, text=None, tail=None, xpath='.')
Sets text and/or tail text of the specified element.
Definition: XML.py:1002
def _yield_texts(self, element, top=True)
Definition: XML.py:692
def element_text_should_match(self, source, pattern, xpath='.', normalize_whitespace=False, message=None)
Verifies that the text of the specified element matches expected.
Definition: XML.py:767
def set_element_tag(self, source, tag, xpath='.')
Sets the tag of the specified element.
Definition: XML.py:966
def get_element(self, source, xpath='.')
Returns an element in the source matching the xpath.
Definition: XML.py:555
def clear_element(self, source, xpath='.', clear_tail=False)
Clears the contents of the specified element.
Definition: XML.py:1254
def get_element_count(self, source, xpath='.')
Returns and logs how many elements the given xpath matches.
Definition: XML.py:620
def copy_element(self, source, xpath='.')
Returns a copy of the specified element.
Definition: XML.py:1281
def remove_element(self, source, xpath='', remove_tail=False)
Removes the element matching xpath from the source structure.
Definition: XML.py:1178
def element_attribute_should_match(self, source, name, pattern, xpath='.', message=None)
Verifies that the specified attribute matches expected.
Definition: XML.py:853
def is_truthy(item)
Returns True or False depending is the item considered true or not.
Definition: robottypes.py:49
def is_falsy(item)
Opposite of :func:is_truthy.
Definition: robottypes.py:56
def get_version(naked=False)
Definition: version.py:24