Hi Team, I am working on robot framework with Python.
I have a python functions where the they have initialized driver, i cannot modify the function nor can i create a new driver instance. I need to get the same driver instance into my testcase and run the testcases.
GUIApi.py
class GUIApi:
def init(self):
self.gui_url = get_test_env_api().get_console_core_url()
self.driver:webdriver = webdriver.Firefox(service=SERVICE, options=FIREFOX_OPTIONS)
self.load_gui_page(self.gui_url)
self._data_setter_obj = DataSetter(self.driver)
self.username = BuiltIn().get_variable_value("${CONSOLE_USERNAME}")
self.password = BuiltIn().get_variable_value("${CONSOLE_PASSWORD}")
if self.username and self.password:
self.data_setter.login(self.username, self.password)
self.enable_screenshots = False
self.set_screenshots_mode()
@property
def data_setter(self) -> DataSetter:
return self._data_setter_obj
Datasetter.py
class DataSetter:
def __init__(self,driver) -> None:
self.driver = driver
#self.actions = ActionChains(self.driver)
def exception_handler(func):
"""Generic exception handler decorator for all setter methods."""
def wrapper(self, *args, **kwargs):
try:
func(self, *args, **kwargs)
except Exception as e:
self.handle_exception(e)
return wrapper
ConfigLibrary.py
@library(scope=‘GLOBAL’,auto_keywords=False)
class ConfigApiLibrary():
def init(self) → None:
“”“Initialization”“”
self.config_obj = None
@keyword("Perform Config API Initialization", tags=['robot:private'])
def perform_config_api_initialization(self):
"""Keyword to perform all the essential configurations for ConfigAPI initialization"""
if utils.get_platform_type().lower() == "cnsbc":
config_api = get_test_env_api().get_configuration_api()
if config_api == 'GUI':
from ConfigAPI.cnSBC.GUI.ConfigApi import ConfigApi
else:
from ConfigAPI.cnSBC.common.ConfigApi import ConfigApi
ConfigApi.py
class ConfigApi(RestConfigApi):
“”“Config module to configure elements and/or attributes”“”
def __init__(self) -> None:
super().__init__()
def perform_config_api_initialization(self):
super().perform_config_api_initialization()
self.gui_instance = GUIApi()
CleanUp.get_cleanup_stack().push_keyword_to_cleanup_with_tag("cleanup_gui",
'Cleanup Config GUI')
I want to get the driver instance from these python func, I am not understanding how to do it.
These are my files
GUICOnfiguaration.py
class GUIConfiguration:
ROBOT_LIBRARY_SCOPE = ‘TEST SUITE’ # Ensures fresh instance per test suite
def __init__(self):
# Get active browser from ConfigApiLibrary's instance
try:
config_lib = BuiltIn().get_library_instance('ConfigApiLib') # Use the WITH NAME alias
gui_api = config_lib.config_obj.gui_instance
self.gui = GUIInitialization(gui_api._data_setter_obj.driver)
except Exception as e:
raise RuntimeError(f"Failed to initialize: {str(e)}. Verify ConfigApiLib is imported first.")
@keyword("Navigate To Config Tab")
def navigate_to_config_tab(self):
self.gui.navigate_to_config()
Login.robot
*** Settings ***
Library ConfigAPI.ConfigApiLibrary WITH NAME ConfigApiLib
Library WebGUI.SetupGUI.GUIConfiguration
Resource setup.resource
Resource TLS.resource
Suite Setup Suite Init
*** Variables ***
${CONFIG_API_LIB} ${None}
*** Keywords ***
Suite Init
Initialize Setup
${CONFIG_API_LIB} = Get Library Instance ConfigApiLibrary
Set Suite Variable ${CONFIG_API_LIB} ${ConfigApiLib}
*** Test Cases ***
Verify_Login
Log to console Hello
Log to console ${ConfigApiLib}
Navigate To Config Tab
Please help me get the driver instance from the above files. Any help would be appreciated