1
votes

I have created a python code to initialise a chrome browser and I want to pass this driver instance to Robot Framework so that the keywords of RF will work on this instance. Please let me know how could i do the same. The Py code for intializing a file is :

'class SeleniumKeywords:

    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

    def __init__(self):
        self.driver = None

    def open_browser(self, browser="chrome"):
        driver_class = drivers[browser]
        self.driver = driver_class()

    def go_to(self, url):
        self.driver.get(url)'

Now when using it in Robot framework, the browser opens but the RF keywords doesnt work on it(selenium2library keywords). Basically I opening an browser instance using the custom keyword and maximizing using selenium2library keywords in RF. Unfortunately it doesnt work. Please let me know how to pass this browser instance to RF:

'*** Settings ***
Library    ExtendedSelenium2Library
Library    ../Resources/SeleniumKeywords.py    
Resource    ../Global/GlobalConfig.robot




*** Test Cases ***
Reuse Session ID
    SeleniumKeywords.Open Browser    chrome
    maximize browser window  
    SeleniumKeywords.Go To    ${URL}  '

The maximize browser window is a RF keyword and I want it to work on my browserinstance

1
Is there a reason you're creating your own driver instead of using the driver created by ExtendedSelenium2Library? Why not have your code use the one opened by ExtendedSelenium2Library instead of the other way around?Bryan Oakley
Fair warning on Maximize Browser Window: it doesn't always work as advertised, especially on Chrome. Also, I can shorten your test case: Open Browser ${URL} chrome, Maximize Browser Window. Provided Maximize Browser Window works for your setup, that will do exactly what you seem to be trying to do. You don't need to specifically call SeleniumKeywords, you already initialized those exact keywords in your instance with your Library ExtendedSelenium2Library call.Brandon Olson

1 Answers

0
votes

I have written my own library, but I extended the Selenium2Library and i can mix the Selenium2Library keywords with my own. The Selenium2Library or in your case, the ExtendedSelenium2Library will not recognize the session you just started in Python and will give the "No browser is open" error. The "Maximize Browser Window" keyword relies on a browser that was previoulsy opened with the "Open Browser" keyword.

If you really need your own Selenium library, you can do something like this:

class SeleniumKeywords(ExtendedSelenium2Library):

    def go_to(self, url, browser="chrome"):
        self.open_browser(url, browser)