I have a robot framework library that is getting quite large and which uses various other classes. I would like to split it up into multiple python files. I was wondering if there is a best practice for how to do this.
For example if I had a single file MyLibrary.py like this:
# MyLibrary.py
class BaseWidget:
def __init__(self, x, y):
self.x = x
self.y = y
class Button(BaseWidget):
def __init__(self, x, y, label):
super().__init__(x, y)
self.label = label
def click(self):
print(f"Clicked {self.label}")
class MyLibrary:
def __init__(self):
self.my_button = Button(10, 20, "My Button")
def click_my_button(self):
self.my_button.click()
with a simple test robot file:
# test.robot
*** Settings ***
Library MyLibrary
*** Test Cases ***
Test
Click My Button
My thoughts would be to create a structure like so:
βββ MyLibrary
β βββ __init__.py
β βββ BaseWidget.py
β βββ Button.py
βββ test.robot
with files in MyLibrary split up as follows:
# MyLibrary/__init__.py
from .Button import Button
class MyLibrary:
def __init__(self):
self.my_button = Button(10, 20, "My Button")
def click_my_button(self):
self.my_button.click()
# MyLibrary/BaseWidget.py
class BaseWidget:
def __init__(self, x, y):
self.x = x
self.y = y
# MyLibrary/Button.py
from .BaseWidget import BaseWidget
class Button(BaseWidget):
def __init__(self, x, y, label):
super().__init__(x, y)
self.label = label
def click(self):
print(f"Clicked {self.label}")
Iβve put this here: GitHub - kimfaint/robot-library-multifile: An example of using a Robot Framework library that is spit into multiple python files
This approach should allow me to build my RF library without ending up with a massive MyLibrary.py file. But is this the best approach?