How to run headless mode through terminal

Hi
Can anyone help me with this?
I’m trying to run test cases in headless mode from the terminal, but when I use this command:
robot --variable BROWSER:headless_chrome filename.robot
it’s not working.
@damies13

Setting a variable is not enough, you also need to pass the variable to Open Browser keyword something like this;

Open Browser  ${URL}  browser=${BROWSER}
1 Like

Hi, thanks for the quick reply.

I have added like this, can you tell me where i need to update
*** Settings ***
Library SeleniumLibrary

*** Variables ***
${URL} testurl.com
${browser} Chrome

*** Test Cases ***
To test authentication pop up
Launching Browser ${url} ${browser}

*** Keywords ***
Launching Browser
[Arguments] ${url} ${browserName}
Open Browser ${url} ${browserName}
Set Selenium Implicit Wait 5
Maximize Browser Window

Close the browser
Close All Browsers

Hi Kavitha,

When you say:

What’s not working? did you get an error message? usually the log.html file will tell you something that will help us guide you to the right solution.

Also

  • Are you running the command on your local machine or some other machine?
  • Does the test pass when you use Chrome (not headless) on the same machine?

Dave.

Hi Dave,

I am running the script in my local machine.

This the script which iam trying to run in headless mode

*** Settings ***
Library SeleniumLibrary

*** Variables ***
${URL} Your Store
${browser} headlessChrome

*** Test Cases ***
To test authentication pop up
Launching Browser ${url} ${browser}

*** Keywords ***
Launching Browser
[Arguments] ${url} ${browserName}
Open Browser ${url} ${browserName}
Set Selenium Implicit Wait 5
Maximize Browser Window

When i run this on terminal using this command robot 0Testing\Test\mytest.robot , it will work fine.
However when i try to use this robot --variable BROWSER:headless_chrome filename.robot, iam getting
the error failed: File or directory to execute does not exist.

Can you please guide me how to do this

Hi Kavitha,

Did it say was it filename.robot it couldn’t find or some other file?

To start with while troubleshooting can we stick to the same robot file? maybe try this first:

robot --variable BROWSER:headless_chrome 0Testing\Test\mytest.robot

Also even though it shouldn’t matter, can we also keep the variables with the same case, i.e. in your robot file ${browser} is lower case, so make it the same on the command line like this:

robot --variable browser:headless_chrome 0Testing\Test\mytest.robot

Lets see if you still get the File or directory to execute does not exist. or something else?

Dave.

Hi Dave,
This time i tried both the way as you suggested
robot --variable browser:headless_chrome 0Testing\Test\mytest.robot,
and now i am getting ValueError: headless_chrome is not a supported browser.

Hi Kavitha,

Are you using Selenium or Browser Library?

SeleniumLibrary Open Browser headlesschrome
Browser Library Open Browser Doesn’t use this type of syntax, it uses a headless=True argument

So that’s probably why.

Dave.

1 Like

Hi Dave
Its working, thanks.
i used the command robot --variable BROWSER:headlessChrome 0Testing\Test\mytest.robot