I'm starter in Python and Robot framework. I'm trying to create and learn to use custom library in my robot framework test suite.
I have created a custom library with the following code:
from selenium import webdriver
import time
class CustomLibrary:
def Open_My_Browser(self):
browser = webdriver.Chrome()
browser.maximize_window()
browser.get("http://demo.guru99.com/V4/")
time.sleep(5)
I imported this custom library and had specified the keyword "Open My Browser". This keyword executes the code from my custom library but the next steps are from selenium2library like click button.
The execution stops and i get message "No browser is open". I understood that my selenium2library is not recognizing the browser which is opened by my customlibrary. But I'm not able to fix this problem. Can anyone please shed some advice
My robot file:
Documentation Test the Guru99 Banking Website
Library Selenium2Library
Library CustomLibrary.py
*** Test Cases ***
Test Case: 001 - The user should be able to navigate to Guru99
[Tags] Smoke
Open the Guru99 website
*** Keywords ***
Open the Guru99 website
Open My Browser ```
Well, of course the browser session will not be reused - it is owned by a separate object, the SeleniumLibrary/Selenium2Library has no knowledge or access to it.
It is the same as if you establish a DB or ssh connection manually, and then expect a library just to start using it - that doesn't happen.
If you want to use the keywords in the SeleniumLibrary, you need to use its Open Browser
, so it has reference to it (the browser).