How to use is_obj_keyword method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

base.py

Source:base.py Github

copy

Full Screen

...25 _aliases = {}26 _alias_delimiter = "__name__"27 has_registered_s2l_keywords = False28 @classmethod29 def is_obj_keyword(cls, obj):30 """ Determines whether the given object is a keyword.31 """32 try:33 # It's either not a method or not an instance method, so34 # it can't be a keyword.35 name = obj.__name__36 except AttributeError:37 return False38 if inspect.isroutine(obj) and not name.startswith("_") and not _Keywords.is_method_excluded(name) and name not in ("get_keyword_names", "run_keyword"):39 return True40 else:41 return False42 @classmethod43 def is_obj_keyword_by_name(cls, name, inst):44 """ Determines whether a given name from the given class instance is a keyword.45 This is used by `get_keyword_names` in `robotpageobjects.page.Page` to decide46 what keyword names to report.47 :param name: The name of the member to check48 :type name: str49 :param inst: The class instance to check (such as a page object)50 :type inst: object51 """52 obj = None53 # If obj is a @property as oppose to a regular method or attribute,54 # its method will be called immediately. This could cause an attempt55 # to retrieve an element via webdriver, but when this method is called56 # no browser is open, so that will cause Selenium2Library's decorator57 # to attempt a screenshot - which will fail, because no browser is open.58 # To prevent this, we temporarily set inst._has_run_on_failure to True.59 # (_has_run_on_failure is used by Selenium2Library's decorator to prevent60 # redundant screenshot attempts.)61 inst._has_run_on_failure = True62 try:63 obj = getattr(inst, name)64 except Exception:65 inst._has_run_on_failure = False66 return False67 inst._has_run_on_failure = False68 return cls.is_obj_keyword(obj)69 @classmethod70 def is_method_excluded(cls, name):71 """72 Checks whether a method is to be excluded from keyword names.73 :param name: The name of the method to check74 :type name: str75 :returns: boolean76 """77 return cls._exclusions.get(name, False)78 @classmethod79 def get_robot_aliases(cls, name, pageobject_name):80 """81 Gets an aliased name (with page object class substitued in either at the end82 or in place of the delimiter given the real method name....

Full Screen

Full Screen

page.py

Source:page.py Github

copy

Full Screen

...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 """...

Full Screen

Full Screen

test_unit.py

Source:test_unit.py Github

copy

Full Screen

...351 docstring = inspect.getdoc(m)352 first_line_of_docstring = docstring.split("\n")[0]353 self.assertEquals(first_line_of_docstring, "click_element(self, selector_or_locator)")354 self.assertTrue("Click element identified by `selector` or `locator`" in docstring)355 def test_is_obj_keyword(self):356 is_obj_keyword = _Keywords.is_obj_keyword357 self.assertTrue(is_obj_keyword(Page.click_element))358 self.assertFalse(is_obj_keyword(Page.selectors))359 self.assertFalse(is_obj_keyword(Page._is_url_absolute))360 self.assertFalse(is_obj_keyword(Page.get_current_browser))361 self.assertFalse(is_obj_keyword(Page.driver))362 def test_is_obj_keyword_by_name(self):363 is_obj_keyword_by_name = _Keywords.is_obj_keyword_by_name364 self.assertTrue(is_obj_keyword_by_name("click_element", Page))365 self.assertFalse(is_obj_keyword_by_name("selectors", Page))366 self.assertFalse(is_obj_keyword_by_name("_is_url_absolute", Page))367 self.assertFalse(is_obj_keyword_by_name("get_current_browser", Page))368 self.assertFalse(is_obj_keyword_by_name("driver", Page))369 self.assertFalse(is_obj_keyword_by_name("foobarbatdaniel", Page))370 def test_page_property_raises_exception(self):371 class MyPage(Page):372 @property373 def some_property(self):374 raise Exception()375 exc_raised = False...

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