简体   繁体   中英

Robot Framework: How to use User created browser instance in Robot framework

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM