How to use _fix_docstrings method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

page.py

Source:page.py Github

copy

Full Screen

...51 def must_return(cls, f):52 # Use decorator module to preserve docstings and signatures for Sphinx53 return decorator.decorator(cls._must_return, f)54 @classmethod55 def _fix_docstrings(cls, bases):56 """ Called from _PageMeta's __new__ method.57 For Sphinx auto-API docs, fixes up docstring for keywords that58 take locators by59 redefining method signature, replacing "locator" parameter with60 "selector_or_locator". Does this by taking advantage of Sphinx's61 autodoc_signature feature, which allows you to override documented62 function signature by putting override as first line in docstring.63 Also replaces references to "locator" in rest of docstring with64 "selector or locator".65 :param bases: A tuple of base classes a particular class66 inherits from.67 """68 for base in bases:69 # Don't fix up a class more than once.70 if not hasattr(base, "_fixed_docstring"):71 for member_name, member in inspect.getmembers(base):72 if _Keywords.is_obj_keyword(member):73 try:74 # There's a second argument75 second_arg = inspect.getargspec(member)[0][1]76 except IndexError:77 continue78 orig_doc = inspect.getdoc(member)79 if orig_doc is not None and second_arg == "locator":80 orig_signature = get_method_sig(member)81 fixed_signature = orig_signature.replace("(self, locator", "(self, selector_or_locator")82 if orig_doc is not None:83 # Prepend fixed signature to docstring84 # and fix references to "locator".85 fixed_doc = fixed_signature + "\n\n" + orig_doc86 fixed_doc = fixed_doc.replace("`locator`", "`selector` or `locator`")87 fixed_doc = fixed_doc.replace(" locator ", " selector or locator ")88 member.__func__.__doc__ = fixed_doc89 base._fixed_docstring = True90 def __new__(cls, name, bases, classdict):91 # Don't do inspect.getmembers since it will try to evaluate functions92 # that are decorated as properties.93 for member_name, obj in classdict.iteritems():94 if _Keywords.is_obj_keyword(obj):95 classdict[member_name] = cls.must_return(classdict[member_name])96 cls._fix_docstrings(bases)97 return _ComponentsManagerMeta.__new__(cls, name, bases, classdict)98class Page(_BaseActions, _SelectorsManager, _ComponentsManager):99 """100 This is the base Page Object from which all other Page Objects should inherit.101 It contains all base Selenium2Library actions and browser-wrapping behavior102 used by this class and its descendents.103 It is a robotframework library which implements the dynamic API.104 """105 __metaclass__ = _PageMeta106 ROBOT_LIBRARY_SCOPE = 'TEST SUITE'107 def __init__(self):108 """109 Initializes the pageobject_name variable, which is used by the _Keywords class110 for determining aliases....

Full Screen

Full Screen

cli.py

Source:cli.py Github

copy

Full Screen

...352 for cmd in cmds:353 Msg.info("Running: " + cmd)354 check_call(cmd.split(" ")) # nosec355 return cmds356def _fix_docstrings(commands):357 for f in commands:358 if "Args:" in [q.strip() for q in f.__doc__.splitlines()]:359 continue360 f.__doc__ += "\n" + " " * 8 + "Args:\n"361 for p in inspect.signature(f).parameters.values():362 arg = p.default363 if arg is not None:364 d = arg.default365 if isinstance(d, (OptionInfo, ArgumentInfo)) and hasattr(d, "default"):366 d = d.default367 try:368 h = re.compile(" +").sub(arg.help.replace("\n", "").strip(), " ")369 f.__doc__ += " " * 12 + p.name + ": " + h + "\n"370 if d is not False:371 f.__doc__ += " " * (12 + 1 + len(p.name)) + f" [default: {str(d)}]\n"372 except (AttributeError, TypeError):373 f.__doc__ += " " * 12 + p.name + " "374if __name__ == "__main__":375 cli()376# else:377# _fix_docstrings(CliCommands.commands())...

Full Screen

Full Screen

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