I have a directory Robot and have multiple suites (.robot files) in it. When i run individual file, tests run successfully. but when i run all suites together, the first .robot file run properly but from second file i get No keyword with name ‘Open New Browser’ found.
command to run all suites under a folder:
PycharmProjects/{projectname}/venv/bin/python -m robot -d Results --loglevel DEBUG -e EXCLUDED -i OUStests /Users/{user}/PycharmProjects/{projectname}/Tests/Web/Robot
I use robot framework with combination of python and selenium.
RobotFramework==5.0
Selenium==4.1.3
robotframework-seleniumlibrary==6.0.0
these are my test setup and tear down:
Test Setup run keywords Open New Browser
Test Teardown run keywords Close All Browsers
my custom keywords file:
from SeleniumLibrary import *
from …webdriver import WebDriver
from robot.libraries.BuiltIn import BuiltIn
class CommonKeywords(SeleniumLibrary):
@base.keyword
def open_new_browser(self, alias=None):
self.register_driver(WebDriver().driver, alias=alias)
@base.keyword
def close_all_browsers(self):
WebDriver().close()
my webdriver.py file:
from selenium.webdriver import DesiredCapabilities
from .configuration import *
from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn
from selenium.webdriver.remote.command import Command
from urllib3.exceptions import MaxRetryError
class WebDriver:
def __get_driver(self):
# Get to see if already a driver:
driver = BuiltIn().get_variable_value(’${driver}’, None)
if driver is None:
return None
else:
try:
driver.execute(Command.QUIT)
return driver
except MaxRetryError:
return None
def __init__(self, name=None, version=None):
driver = self.__get_driver()
if driver is None:
self.__headless = None
self.__local = None
self.name = name
self.conf = get_configuration('Browser')
driver_path = self.conf.get('driver_path', 'Resources/chromedriver')
logging.info('From My WebDriver')
from selenium.webdriver import ChromeOptions
options = ChromeOptions()
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
if self.headless:
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
if self.local:
driver = webdriver.Chrome('Resources/chromedriver', chrome_options=options, desired_capabilities=caps)
else:
driver = webdriver.Remote(command_executor="http://chrome:4444/wd/hub", options=options)
driver.set_window_size(1920, 1080)
self.driver = driver
BuiltIn().set_global_variable('${driver}', driver)
else:
self.driver = driver
def close(self):
"""Closes all open browsers and resets the browser cache.
After this keyword new indexes returned from `Open Browser` keyword
are reset to 1.
This keyword should be used in test or suite teardown to make sure
all browsers are closed.
"""
self.driver.quit()
BuiltIn().set_global_variable('${driver}', None)