How to run test in headed mode using VS Code

Hi, I’m new to robotframework and Playwright. I installed

  1. robotframework browser library

  2. VS code with Robot Framework language server extension
    I can run following sample test successfully in headless mode. But how can I run it in headed mode, i.e. showing browser UI?

    *** Settings ***
    Library Browser

    *** Test Cases ***
    Run Test
    New Page https://playwright.dev
    Get Text h1 contains Playwright

Hi Fred,

From the documentation for New Page:

When a New Page is called without an open browser, New Browser and New Context are executed with default values first.

The setting you are after is in New Browser:

headless = True bool

so you’ll want to change your test to:

*** Settings ***
Library Browser

*** Test Cases ***
Run Test
    New Browser    headless=False
    New Page    https://playwright.dev
    Get Text     h1    contains    Playwright

Dave.

2 Likes

Hi Dave,
Thanks for the solution. What if the test suite needs to be executed in both headed and headless mode, and the condition is defined outside of the script, say, via env or CLI argument?

Hi Fred,

Just create a variable like this:

*** Settings ***
Library Browser

*** Variables ***
${HEADLESS}       ${True}

*** Test Cases ***
Run Test
    New Browser    headless=${HEADLESS}
    New Page    https://playwright.dev
    Get Text     h1    contains    Playwright

Now it defaults to headless (or defaults to headed if you set it False), which you can override on the command line with the -v or --variable option, like this:

robot -v HEADLESS:${False} robotfile.robot

Dave.