RobotFramework use wrong browser

Hello everyone
i am a Maxime, beginner in RobotFramework and I am facing issue.

I am working with Python 3.9 and Robot 3.2.2.

I try to write some code to test a web application. For this I write python Class who use selenium to launch application under a web browser (Chrome).

To test it I need to launch 2 instances of my class.

When I do that with robot, it seems that robot use only the last version of my class (wrong driver)

here my example:

My robot code:

** Settings ***
Library AppUI WITH NAME UI1
Library AppUI WITH NAME UI2

*** Keywords ***
Test CheckCall
UI1.open application
UI2.open application
UI1.login login password #In this case Robot use last openned browser UI2 browser
UI2.login login password #This failed because login page is not display he already login …

My python code:
Class AppUI(object):

def __init__(self, url)
    self.url = url
    self.driver = None

def open_application(self):
    """ Launch application """
        self.driver.get(self.url)

If I try to write my test in python everything is working as expected but with Robot, it used the wrong driver (everytime the last one)

Does anyone have an idea about this issue ?

Hello, It’s me again,

Because I haven’t any answer maybe my issue is not clear so I write an example to reproduce this issue.

I am new user so I can not upload file so I will juste copy my code here:

My python lib :

from time import sleep
from selenium import webdriver as webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By

class AppUI(object):
ROBOT_LIBRARY_SCOPE = ‘GLOBAL’

def __init__(self):
    self.driver = None

def open_application(self, url):
    """ Launch application """
    self.driver = webdriver.Chrome()
    self.driver.get(url)
    sleep(5)

def close_application(self):
    """ Close application """
    self.driver.quit()

def get_element_by_class_name(self, element, timeout=5, poll_frequency=0.5):
    return WebDriverWait(self.driver, timeout, poll_frequency).until(ec.visibility_of_element_located((By.CLASS_NAME, element)))

def click_forum_logo(self):
    self.get_element_by_class_name("title").click()

def main():
my_app_1 = AppUI()
my_app_2 = AppUI()
my_app_1.open_application(“https://forum.robotframework.org/”)
my_app_2.open_application(“Robot Framework documentation”)
my_app_1.click_forum_logo()

if name == “main”:
main()

If you execute it everything works fine

Here my robot test:
*** Settings ***
Library lib.appui.AppUI WITH NAME browser1
Library lib.appui.AppUI WITH NAME browser2

*** Keywords ***
Test Teardown
browser1.close application
browser2.close application

*** Test Cases ***
#CHP O1
Test Search
[Teardown] Test Teardown
browser1.open application ${see_first_links_in_python_lib_new_user_can_only_put_2_links}
browser2.open application ${see_second_links_in_python_lib_new_user_can_only_put_2_links}
browser1.click forum logo

For me it is a robot issue, robot does not handle correctly class instances but maybe I am wrong and I do not use robot correctly so please if you guys have any idea how I can solve that tell me :slight_smile:

Have a nice day
Max

Hello,

Sorry it is me again, I have the same issue than here : https://github.com/robotframework/robotframework/issues/3417

With that topics I manage to understand how robot works to create class instance so I manage to solve my issue

Thanks
Maxime

1 Like

Hi Maxime

You should use the seleniumlibrary for your tests rather than write your own keywords. Here is an example