How to use xml_get_nodes method in autotest

Best Python code snippet using autotest_python

bkr_xml.py

Source: bkr_xml.py Github

copy

Full Screen

...27 try:28 return str(node.attributes[key].value)29 except Exception:30 return default31def xml_get_nodes(node, tag):32 return [n for n in node.childNodes if n.nodeName == tag]33class Recipe(object):34 def __init__(self):35 self.tasks = []36 self.id = -137 self.job_id = -138 self.exclude_dir = []39class Task(object):40 """41 Simple record to store task properties42 """43 def __init__(self):44 self.name = ''45 self.params = {}46 self.rpmName = ''47 self.rpmPath = ''48 self.timeout = ''49 self.exclude_dir = []50 self.id = -151 def __str__(self):52 return "- %s %s" % (self.name, str(self.params))53 def __repr__(self):54 return "%s %s" % (self.name, str(self.params))55 def get_param(self, key, default=None):56 if key in self.params:57 return self.params[key]58 else:59 return default60class BeakerXMLParser(object):61 """62 Handles parsing of beaker job xml63 """64 def __init__(self):65 self.recipes = {}66 def parse_from_file(self, file_name):67 log.debug('BeakerXMLParser - opening file: %s', file_name)68 f = open(os.path.expanduser(file_name), 'r')69 contents = f.read()70 f.close()71 log.debug('BeakerXMLParser - content read ok')72 return self.parse_xml(contents)73 def parse_xml(self, xml):74 """75 Returns dict, mapping hostname to recipe76 """77 log.debug('Parsing recipes')78 log.debug("xml type is %s" % type(xml))79 doc = minidom.parseString(xml)80 recipe_nodes = doc.getElementsByTagName('recipe')81 self.handle_recipes(recipe_nodes)82 log.debug('Parsing recipes ok')83 return self.recipes84 def handle_recipes(self, recipe_nodes):85 for recipe_node in recipe_nodes:86 self.handle_recipe(recipe_node)87 def handle_recipe(self, recipe_node):88 hostname = recipe_node.getAttribute('system')89 recipe = Recipe()90 recipe.id = recipe_node.getAttribute('id')91 recipe.job_id = recipe_node.getAttribute('job_id')92 log.debug('Parsing recipe with id: <%s>', recipe.id)93 #tasks = recipe.getElementsByTagName('task')94 task_nodes = xml_get_nodes(recipe_node, 'task')95 self.handle_tasks(recipe, task_nodes)96 self.recipes[hostname] = recipe97 return True98 def handle_tasks(self, recipe, task_nodes):99 for task_node in task_nodes:100 self.handle_task(recipe, task_node)101 def handle_task(self, recipe, task_node):102 task = Task()103 task.name = task_node.getAttribute('name')104 task.id = task_node.getAttribute('id')105 task.timeout = task_node.getAttribute('max_time') or task_node.getAttribute('avg_time')106 task.status = task_node.getAttribute('status')107 log.debug('Parsing task with id: <%s>', task.id)108 recipe.tasks.append(task)109 params_tags = xml_get_nodes(task_node, 'params')110 if params_tags:111 param_nodes = params_tags[0].getElementsByTagName('param')112 self.handle_task_params(task, param_nodes)113 rpm_nodes = xml_get_nodes(task_node, 'rpm')114 task.rpmName = rpm_nodes[0].getAttribute('name')115 task.rpmPath = rpm_nodes[0].getAttribute('path')116 def handle_task_params(self, task, param_nodes):117 for param_node in param_nodes:118 self.handle_task_param(task, param_node)119 def handle_task_param(self, task, param_node):120 param_name = param_node.getAttribute('name')121 param_value = param_node.getAttribute('value')...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Use Playwright For Web Scraping with Python

In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.

Migrating Test Automation Suite To Cypress 10

There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.

A Reconsideration of Software Testing Metrics

There is just one area where each member of the software testing community has a distinct point of view! Metrics! This contentious issue sparks intense disputes, and most conversations finish with no definitive conclusion. It covers a wide range of topics: How can testing efforts be measured? What is the most effective technique to assess effectiveness? Which of the many components should be quantified? How can we measure the quality of our testing performance, among other things?

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

Getting Started with SpecFlow Actions [SpecFlow Automation Tutorial]

With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful