0

In this StackOverflow posting Bryan Oakley suggested subclassing AppiumLibrary and gave an example of doing so. I’m trying to do this and I can’t seem to get it to work. For example:

ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:20:15)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

>>> from AppiumLibrary import AppiumLibrary
>>> class foo(AppiumLibrary):
…     pass
…
>>> f = foo()
>>> print f
<__main__.foo object at 0x102097bd0>
>>> print f.__dict__

{‘_running_on_failure_routine’: False, ‘_screenshot_index’: 0, ‘_run_on_failure_keyword’: ‘Capture Page Screenshot’, ‘_element_finder’: <AppiumLibrary.locators.elementfinder.ElementFinder object at 0x1036f7e50>, ‘_timeout_in_secs’: 5.0, ‘_bi’: <robot.libraries.BuiltIn.BuiltIn object at 0x1036f7d50>, ‘_cache’: <AppiumLibrary.utils.applicationcache.ApplicationCache object at 0x1036f7d90>}

>>> f.OpenApplication()
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
AttributeError: ‘foo’ object has no attribute ‘OpenApplication’

Why did this work for Bryan and AronS and not now for me?

Thanks, Martin

Community
  • 1
  • 1
CMTaylor
  • 11
  • 1

1 Answers1

0

Boy do I feel stupid! As soon as I re-ready my own posting of the question I knew the answer. The Robot Framework keyword is "Open Application" but the internal keyword method in AppiumLibrary is "open_application". When subclassing you have to call by the actual method name, not by RobotFramework's "friendly" keyword name!

I'm still not clear why dict doesn't list the keyword method names, but maybe I'm being dumb about something in Python that I should also know without asking.

CMTaylor
  • 11
  • 1
  • `__dict__` is for attributes. I think what you want to do is `dir(f)`. That will show all the methods and attributes. To try and see just public methods - `[x for x in dir(f) if inspect.ismethod(getattr(f,x)) and x[0]!='_']`. Of course there are exceptions to all this. – ombre42 Feb 11 '16 at 21:41