Robot Framework SeleniumLibrary Chrome Docker
▌Introduction
We will use Robot Framework
to run E2E test in a Docker container.
Here are the frameworks and toolkit that we will use.
·
Robot Framework: An open source
automation framework
·
SeleniumLibrary:
Web testing library for Robot Framework.
·
ChromeDriver: WebDriver
for Chrome
·
XVFB:
It performs all graphical operations in virtual memory without showing any
screen output.
·
Katalon
Recorder: Web extension for automating actions and automated testing on the
browser
▌Environment
▋Robot Framework 4.1.2
▋ChromeDriver 95.0.4638.17
▋Google Chrome 95.0.4638.54
▋SeleniumLibrary 5.1.3
▌Implement
▋Dockerfile
Here is a sample dockerfile that installs Chrome, ChromeDriver
and XVFB on the fly.
▋Requirement: Python packages
Here are the python packages we need to run recorded E2E test by
Chrome with Robot Framework.
▋Export Test Case to Robot Framework from Katalon Recoder
One of the fast ways to have an E2E test case is recording the
end-user’s steps by Selenium IDE that can be exported or playback. Take Katalon
Recorder for example, we can export a test case as Robot Framework format
(.robot file) like following.
However, if we want to run the test in a docker environment, we
will need to modify some code of the .robot file.
▋Update Test Case
The original test case exported from Katalon Recorder is as following,
To run Chrome in a docker container (Like Debian in this sample),
we need to run it with headless and no-sandbox arguments.
·
--headless: Run Chrome without GUI.
·
--no-sandbox: Sandbox removes unnecessary
privileges from the processes that don't need them in Chrome. Disable
Sandboxing will run google chrome as a root user.
Let’s create a module that can create and return a new WebDriver
instance with the above arguments.
▋ChromeConfiguration.py
Then we can use it in our test case.
▋MyTest.robot
Notice that after the WebDriver created, we must use Go To keyword to
open the URL with the WebDriver instance.
Or we can replace the above 2 line with Open Browser keyword.
Open Browser https://172.19.160.1:5001/OpenId/Login
${BROWSER} options=${chrome_options}
If you encounter any
problem, you can open /var/log/chromedriver.log to see what happened.
And please make sure
the Chrome and ChromeDriver are the same version.
For example, I am having Chrome 95 for my testing.
▌Reference
▋Robot
Framework: SeleniumLibrary
▋WSL: dbus
doesn't seem to work