How to use ReturnValueResolver method in Robotframework

Best Python code snippet using robotframework

assigner.py

Source: assigner.py Github

copy

Full Screen

...82 return HandlerExecutionFailed(ErrorDetails(exc_info))83 def assign(self, return_value):84 context = self._context85 context.trace(lambda: 'Return: %s' % prepr(return_value))86 resolver = ReturnValueResolver(self._assignment)87 for name, value in resolver.resolve(return_value):88 if not self._extended_assign(name, value, context.variables):89 value = self._normal_assign(name, value, context.variables)90 context.info(format_assign_message(name, value))91 def _extended_assign(self, name, value, variables):92 if name[0] != '$' or '.' not in name or name in variables:93 return False94 base, attr = self._split_extended_assign(name)95 try:96 var = variables[base]97 except DataError:98 return False99 if not (self._variable_supports_extended_assign(var) and100 self._is_valid_extended_attribute(attr)):101 return False102 try:103 setattr(var, attr, value)104 except:105 raise VariableError("Setting attribute '%s' to variable '%s' "106 "failed: %s" % (attr, base, get_error_message()))107 return True108 def _split_extended_assign(self, name):109 base, attr = name.rsplit('.', 1)110 return base.strip() + '}', attr[:-1].strip()111 def _variable_supports_extended_assign(self, var):112 return not (is_string(var) or is_number(var))113 def _is_valid_extended_attribute(self, attr):114 return self._valid_extended_attr.match(attr) is not None115 def _normal_assign(self, name, value, variables):116 variables[name] = value117 # Always return the actually assigned value.118 return value if name[0] == '$' else variables[name]119def ReturnValueResolver(assignment):120 if not assignment:121 return NoReturnValueResolver()122 if len(assignment) == 1:123 return OneReturnValueResolver(assignment[0])124 if any(a[0] == '@' for a in assignment):125 return ScalarsAndListReturnValueResolver(assignment)126 return ScalarsOnlyReturnValueResolver(assignment)127class NoReturnValueResolver(object):128 def resolve(self, return_value):129 return []130class OneReturnValueResolver(object):131 def __init__(self, variable):132 self._variable = variable133 def resolve(self, return_value):134 if return_value is None:135 identifier = self._variable[0]136 return_value = {'$': None, '@': [], '&': {}}[identifier]137 return [(self._variable, return_value)]138class _MultiReturnValueResolver(object):139 def __init__(self, variables):140 self._variables = variables141 self._min_count = len(variables)142 def resolve(self, return_value):143 return_value = self._convert_to_list(return_value)144 self._validate(len(return_value))145 return self._resolve(return_value)146 def _convert_to_list(self, return_value):147 if return_value is None:148 return [None] * self._min_count149 if is_string(return_value):150 self._raise_expected_list(return_value)151 try:152 return list(return_value)153 except TypeError:154 self._raise_expected_list(return_value)155 def _raise_expected_list(self, ret):156 self._raise('Expected list-like value, got %s.' % type_name(ret))157 def _raise(self, error):158 raise VariableError('Cannot set variables: %s' % error)159 def _validate(self, return_count):160 raise NotImplementedError161 def _resolve(self, return_value):162 raise NotImplementedError163class ScalarsOnlyReturnValueResolver(_MultiReturnValueResolver):164 def _validate(self, return_count):165 if return_count != self._min_count:166 self._raise('Expected %d return values, got %d.'167 % (self._min_count, return_count))168 def _resolve(self, return_value):169 return list(zip(self._variables, return_value))170class ScalarsAndListReturnValueResolver(_MultiReturnValueResolver):171 def __init__(self, variables):172 _MultiReturnValueResolver.__init__(self, variables)173 self._min_count -= 1174 def _validate(self, return_count):175 if return_count < self._min_count:176 self._raise('Expected %d or more return values, got %d.'177 % (self._min_count, return_count))178 def _resolve(self, return_value):179 before_vars, list_var, after_vars \180 = self._split_variables(self._variables)181 before_items, list_items, after_items \182 = self._split_return(return_value, before_vars, after_vars)183 before = list(zip(before_vars, before_items))184 after = list(zip(after_vars, after_items))...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Testing in Production: A Detailed Guide

When most firms employed a waterfall development model, it was widely joked about in the industry that Google kept its products in beta forever. Google has been a pioneer in making the case for in-production testing. Traditionally, before a build could go live, a tester was responsible for testing all scenarios, both defined and extempore, in a testing environment. However, this concept is evolving on multiple fronts today. For example, the tester is no longer testing alone. Developers, designers, build engineers, other stakeholders, and end users, both inside and outside the product team, are testing the product and providing feedback.

Why Agile Is Great for Your Business

Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.

How To Test React Native Apps On iOS And Android

As everyone knows, the mobile industry has taken over the world and is the fastest emerging industry in terms of technology and business. It is possible to do all the tasks using a mobile phone, for which earlier we had to use a computer. According to Statista, in 2021, smartphone vendors sold around 1.43 billion smartphones worldwide. The smartphone penetration rate has been continuously rising, reaching 78.05 percent in 2020. By 2025, it is expected that almost 87 percent of all mobile users in the United States will own a smartphone.

10 Best Software Testing Certifications To Take In 2021

Software testing is fueling the IT sector forward by scaling up the test process and continuous product delivery. Currently, this profession is in huge demand, as it needs certified testers with expertise in automation testing. When it comes to outsourcing software testing jobs, whether it’s an IT company or an individual customer, they all look for accredited professionals. That’s why having an software testing certification has become the need of the hour for the folks interested in the test automation field. A well-known certificate issued by an authorized institute kind vouches that the certificate holder is skilled in a specific technology.

The Art of Testing the Untestable

It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?

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 Robotframework 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