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:

Scala Testing: A Comprehensive Guide

Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.

What Agile Testing (Actually) Is

So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.

How To Choose The Right Mobile App Testing Tools

Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools

A Complete Guide To CSS Houdini

As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????

Appium Testing Tutorial For Mobile Applications

The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.

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