Can I use one import and expose keywords from multiple python libraries?
Question: I am fairly new to Python and Robot, so please bare with me, but here is what
I am trying to do.

I am doing some automation on 2 mobile devices, and I have a library created
that allows me to communicate with these devices, provided to me by one of our
dev teams. In my test suite I have to import this library twice, one instance
for each device, and I am using the robot WITH NAME to call keywords specific
to each device. For example I import the library like this:

    
    
    Library    keyword_module.DEVICE.DEVICE    ${USB_GUID_1}    WITH NAME    d1
    Library    keyword_module.DEVICE.DEVICE    ${USB_GUID_2}    WITH NAME    d2
    

The library has a set of keywords that I can call from Robot to perform basic
operations on the device. Such as:

    
    
    d1.turn_on_wifi
    d2.turn_on_cellular
    

I then created my own python module, in this module I created keywords that
take some keywords from this library to create higher level functions. I used
Robots BuiltIn().get_library_instance to bring in the instances above so i can
work with the keywords in my module. For example:

    
    
    class Common(object):
    
        def __init__(self, libName):
            self.d = BuiltIn().get_library_instance(libName)
    
        def some_keyword(self):
            self.d.turn_on_wifi
            self.d.turn_off_cellular
    

I then import my module for both devices as follows:

    
    
    Library    keyword_module.DEVICE.DEVICE    $[USB_GUID_1}    WITH NAME    d1
    Library    keyword_module.DEVICE.DEVICE    $[USB_GUID_2}    WITH NAME    d2
    Library    Common.Common    d1    WITH NAME    D1
    Library    Common.Common    d2    WITH NAME    D2
    

So now I can call my keywords from Common with D1 and D2, and use d1 and d2
for the DEVICE library.

The problem is that my library is growing larger and larger, and I want to
break it down into sub modules that are grouped based on similar traits, ie I
want one file/module for my wifi keywords that I create, another for cellular,
another for something else.

I could just do what I did above for each file, however then I would end up
with a large list of imports in Robot all with different names, which is what
I wanted to avoid.

Is there a way for me to move my keywords into multiple files but still only
have one import for each device in Robot. I basically want to have multiple py
files, but have them all linked somehow so that I can still only import the
one Common library for each device and this will expose all of the keywords
for me to call from all the sub-files?

Does that make sense?


Answer: You can see 'Selenium2Library'!

    
    
    class Selenium2Library(
    _LoggingKeywords, 
    _RunOnFailureKeywords, 
    _BrowserManagementKeywords, 
    _ElementKeywords, 
    _TableElementKeywords,
    _FormElementKeywords,
    _SelectElementKeywords,
    _JavaScriptKeywords,
    _CookieKeywords,
    _ScreenshotKeywords,
    _WaitingKeywords
    

):

You just to need to import 'Selenium2Library',but expose all of the keywords!
For example:

a module named '_ALibrary.py'

    
    
    class _ALibrary(object):
    def __init__(self):
        pass
    def fun1(self):
        print 'fun1'`
    

a module named '_BLibrary.py'

    
    
    class _BLibrary(object):
    
    def __init__(self):
        pass
    def fun2(self):
        print 'fun2'
    def fun3(self):
        print 'fun3'
    

a common module named'CommonLibrary.py'

    
    
    import _ALibrary
    import _BLibrary
    class CommonLibrary(_BLibrary._BLibrary,_ALibrary._ALibrary):
    def __init__(self):
        for base in CommonLibrary.__bases__:
            base.__init__(self)
    

so you just to need import 'CommonLibrary.py'

