Hi Team, I am facing an issue while trying testcases with robot framework with python libraries
gui_initilization.py
from robot.libraries.BuiltIn import BuiltIn
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
class Initialization:
def **init**(self, driver) → None:
self.driver = driver
def gui_login(self, username, password):
username_input = self.find_gui_element_by_xpath("//*[@id='username']")
password_input = self.find_gui_element_by_xpath("//*[@id='password']")
login_button = self.find_gui_element_by_xpath("//*[@id='kc-login']")
if username_input and password_input:
username_input.send_keys(username)
password_input.send_keys(password)
login_button.click()
def find_gui_element_by_xpath(self, xpath):
"""Returns the web-element of the xpath provided."""
element = WebDriverWait(self.driver, WAIT_TIMEOUT).until(
expected_conditions.presence_of_element_located((By.XPATH, xpath)))
self.driver.execute_script("arguments[0].scrollIntoView({block: \"center\", inline: \"center\"});", element)
element_visible = WebDriverWait(self.driver, WAIT_TIMEOUT).until(expected_conditions.visibility_of(element))
return element_visible
gui_configuration.py
import json
import time
from robot.libraries.BuiltIn import BuiltIn
from robot.api.deco import keyword
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.chrome.options import Options
from gui_initialization import Initialization
from ConfigAPI.Test.GUI.GUI import GUIApi
CHROME_OPTIONS = Options()
CHROME_OPTIONS.add_argument(‘–ignore-certificate-errors’)
CHROME_OPTIONS.add_argument(“–headless”)
WEB_PAGE_LOAD_TIMEOUT = 20
class GUI_Configuration:
def **init**(self):
print(“Hello this is a new testcase”)
self.gui_url = “https://10.10.10.10/”
self.driver:webdriver = webdriver.Chrome(options=CHROME_OPTIONS)
self.load_webgui(self.gui_url)
self.gui_data_obj = Initialization(self.driver)
self.username = “admin”
self.password = “123”
if self.username and self.password:
self.gui_data_obj.gui_login(self.username, self.password)
# self.enable_screenshots = False
# self.set_screenshots_mode()
self.gui_api_obj = GUIApi()
@property
def gui_data_setter(self) -> Initialization:
return self._gui_data_obj
@keyword
def display(self):
print("Login to GUI")
def load_webgui(self, url):
try:
self.driver.set_page_load_timeout(WEB_PAGE_LOAD_TIMEOUT)
self.driver.get(url)
self.driver.maximize_window()
except Exception as e:
exception_message = getattr(e, 'msg', str(e))
BuiltIn().run_keyword('FAIL', f"Timeout loading Test GUI page {exception_message}")
@keyword("Navigate to Configuration")
def navigate_to_configuration_tab(self):
return self.gui_api_obj.navigate_to_config_tab()
@keyword("Get Username")
def get_username(self):
return self.gui_api_obj.username # Return username
@keyword("Get Password")
def get_password(self):
return self.gui_api_obj.password # Return password
Login.robot
*** Settings ***
Library ../GUI_Config/gui_configuration.py
*** Test Cases ***
Verify_Login
Display
${username}= Get Username
${password}= Get Password
Log to console ${username}
Log to console ${password}
Verify_login testcase is failing, it is failing to identify the keywords
Error: Imported library ‘/home/sbc-user/testsuites/Test_Automation/GUI_Config/gui_configuration.py’ contains no keywords.
Folder structure
Project
GUI_Config
- gui_initialization.py
- gui_configuaration,py
Testcases - Login.robot
Can someone please help me with this.