Reputation: 23
Open Browser ${REMOTE_URL} ${HEADLESS}
I want to pass the headlesschrome value to Open Browser keyword from commandline
Upvotes: 0
Views: 3983
Reputation: 1565
If you want to make the chrome headless to work, below code should work. When you want to parametrize then forllow this doc - https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#resource-and-variable-files
Create all the variables and store it in a file and then, when calling any of the below code use the following syntax, OR, pass the respective name:value as shown below from command line to use the same in your robot code.
robot -v <<variable file>> *.robot
OR
robot -v name:value *.robot
package list
(rf2) C:\Users\kgurupra>pip list
Package Version
------------------------------- ---------
appdirs 1.4.3
beautifulsoup4 4.8.1
certifi 2018.8.24
chardet 3.0.4
colorama 0.4.1
configparser 4.0.2
crayons 0.3.0
idna 2.8
pip 19.3.1
requests 2.22.0
robotframework 3.1.2
robotframework-selenium2library 3.0.0
robotframework-seleniumlibrary 4.1.0
robotframework-xvfb 1.2.2
selenium 3.141.0
setuptools 40.2.0
soupsieve 1.9.5
tqdm 4.38.0
urllib3 1.25.7
webdriver-manager 2.3.0
webdrivermanager 0.7.4
wheel 0.31.1
wincertstore 0.2
xvfbwrapper 0.2.9
Code
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Test title
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${options} add_argument --headless
#my_create_webdriver googlechrome ${options}
create webdriver Chrome chrome_options=${options}
Maximize Browser Window
go to https://google.com
Maximize Browser Window
capture page screenshot
close browser
Using OpenBrowser Headless
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Test title
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${options} add_argument --headless
#my_create_webdriver Chrome ${options}
Open Browser http://google.com Headless Chrome
# create webdriver Chrome chrome_options=${options}
Maximize Browser Window
go to https://google.com
Maximize Browser Window
capture page screenshot
close browser
OUTPUT
(rf2) C:\Users\kgurupra>robot sa.robot
==============================================================================
Sa
==============================================================================
Test title ..
DevTools listening on ws://127.0.0.1:54461/devtools/browser/ff94b77f-b963-428f-835e-f5e1932a1915
Test title | PASS |
------------------------------------------------------------------------------
Sa | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Users\kgurupra\output.xml
Log: C:\Users\kgurupra\log.html
Report: C:\Users\kgurupra\report.html
Better approach
Xvfb is a headless display server for the X Window System, instead if making chrome/firefox to run headless, why not use the below method instead.
Install XvfbRobot library for Robot Framework, this is a robot library for creating virtual display which can be used for running selenium tests in headless mode.
pip install robotframework-xvfb
Example
*** Settings ***
Documentation This example demonstrates how to use current library
Library Selenium2Library
Library XvfbRobot
*** Test Cases ***
Create Headless Browser
Start Virtual Display 1920 1080
Open Browser http://google.com
Set Window Size 1920 1080
${title}= Get Title
Should Be Equal Google ${title}
[Teardown] Close Browser
Upvotes: 1