1

I am new to Robot and have this simple code from a tutorial. The code is supposed open chrome and visit the login page of this website. It does that, however, it closes the browser automatically. I've tried to debug by adding the params options=add_experimental_option("detach",${True}) after create webdriver, however, this makes things worse.

*** Settings ***
Documentation    To validate the Login form
Library    SeleniumLibrary


*** Test Cases ***
Validate Unsuccessful Login
    Open The Browser With The Mortgage Payment URL
    # Fill the login form
    # Wait until it checks and displays error message
    # Verify error message is correct

*** Keywords ***
Open The Browser With The Mortgage Payment URL
    Create Webdriver    Chrome
    Go To    https://rahulshettyacademy.com/loginpagePractise/
2
  • Why would you like to keep the browser open? It sounds like expected behavior of automated testing framework: open resource, execute some actions, test expectations, close resource. All that can be executed very fast in order of [ms].
    – pptaszni
    Commented Jun 25 at 14:30
  • @pptaszni because this is not the expected behaviour and i want to correct it before moving forward
    – User9123
    Commented Jun 25 at 18:31

1 Answer 1

0

The detach option appears to only work with Open Browser, not Create Webdriver.

Solution: Replace Create Webdriver with Open Browser:

Open Browser    browser=Chrome    options=add_experimental_option("detach",True)

I tested this on my machine and the browser stays open. Hope this helps!

Edit: I'm running on a Mac. Here's the full file, test.robot:

*** Settings ***
Documentation    To validate the Login form
Library    SeleniumLibrary

*** Test Cases ***
Validate Unsuccessful Login
    Open The Browser With The Mortgage Payment URL
    # Fill the login form
    # Wait until it checks and displays error message
    # Verify error message is correct

*** Keywords ***
Open The Browser With The Mortgage Payment URL
    Open Browser   browser=Chrome    options= add_experimental_option("detach",True)
    Go To    https://rahulshettyacademy.com/loginpagePractise/

Pip freeze for the venv:

attrs==23.2.0
certifi==2024.6.2
h11==0.14.0
idna==3.7
outcome==1.3.0.post0
PySocks==1.7.1
robotframework==7.0.1
robotframework-pythonlibcore==4.4.1
robotframework-seleniumlibrary==6.3.0
selenium==4.22.0
sniffio==1.3.1
sortedcontainers==2.4.0
trio==0.25.1
trio-websocket==0.11.1
typing_extensions==4.12.2
urllib3==2.2.2
websocket-client==1.8.0
wsproto==1.2.0

Browser: ChromeDriver 126.0.6478.126. chromedriver binary in same dir as test.robot.

4
  • still closes the browser for me on mac
    – User9123
    Commented Jun 25 at 18:30
  • Strange. I'm on a mac, too. Where do you have the Chrome runtime installed? Commented Jun 25 at 20:05
  • i have downloaded the chrome for developers
    – User9123
    Commented Jun 26 at 22:06
  • 1
    @User9123 I think @JasonRamboz deserves the accept & the bounty - using the experimental detach with True status is the way to keep the browser opened; github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk//examples/… . I've been using it this way in my projects, and - combined with Open Browser, not Create Webdriver it does work. Jason - that's a bit unorthodox way to pass the options though; one usually initializes them as a python object and passes that to the keyword. But if it works, it works :) Commented Jul 2 at 12:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.