Robot Framework Tutorial with Robocorp, including Selenium and Playwright libraries. The project can be used as a starting point for automating own repetitive tasks, or to automatize the manual repetitive tests and verifications performed e.g., during a software development project. Robot Framework makes it easier for anyone with basic scripting knowledge (i.e., not necessarily a developer) to implement and run own automated tests and verifications, that otherwise would be run manually.
In order to setup and run this project, there are two ways. One is with Robocorp, the other is manually with Python and Robot Framework:
Robot Framework is an open-source automation framework, based on Python, that is highly customizable and extendable through libraries. Robot Framework makes Python, which is a native language for automation, accessible to anyone with basic scripting knowledge. This means automation is accessible not only for developers, but for testers, support specialists, or other IT workers.
Robocorp is mainly a RPA solution based on Robot Framework. It is going one step further and makes the whole Python and Robot Framework environment setup easier, as well as it makes tasks or tests runs even more accessible. Also, it is putting together and customizing a lot of RPA libraries, basically covering all aspects of computer tasks or tests automation.
The easier is to start with Robocorp, Rcc toolchain, which is automatically installing everything needed for run: https://robocorp.com/
-
Download this project release
-
Install Robocorp Rcc toolchain
Execute tools\install rcc.bat to install Rcc tool automatically and set the Path environment variable. Otherwise, do it manually:
Download Rcc tool from https://downloads.robocorp.com/rcc/releases/latest/windows64/rcc.exe and copy it anywhere in the PATH (e.g. open Command prompt and type path. The path could be e.g. %userprofile%\Rcc)
Open cmd within project directory and run once:
-
Disable tracking:
rcc configure identity --do-not-track
-
Check:
rcc configure identity
-
-
Run the first task
Open command prompt and run
rcc run -t SeleniumTask -e devdata\env.json
On first run the full environment is loaded, thus the first run will take up to 5 minutes to run.
-
In order to visualize and modify the robot code, there are 3 alternatives:
- Visual Studio Code with extensions (free for personal or commercial use): https://robocorp.com/docs/developer-tools/visual-studio-code/overview
- Robocorp Lab (free for personal or non-commercial internal business use)
- PyCharm Community with Robocorp (free, open source)
-
If VS Code is the preferred approach, install the two extensions from the above link or from within VS Code: Robocorp Code and Robot Framework Language Server
-
Open the downloaded rf-robocorp-tutorial folder within VSCode and check the following files:
- Environment settings: conda.yaml
- Tasks names: robot.yaml
- Environment variables: env.json and env-my.json
- Robot tasks: _tasks-*.robot
- Run within VS Code or command line:
-
Open project folder within Visual Studio Code, press CTRL+SHIFT+P, Robocorp: Run Robot, Choose task to run (will use default devdata/env.json)
-
Command prompt > rcc run -t taskname -e devdata\env.json (taskname as defined in robot.yaml), e.g.:
rcc run -t SeleniumTask -e devdata\env.json
rcc run -t PlaywrightTask -e devdata\env.json
rcc run -t SeleniumTask -e devdata\env-my.json
rcc run -t PlaywrightTask -e devdata\env-my.json
rcc run -t MyCustomTask
-
- Environment is downloaded under AppData\Local\robocorp. This folder can be removed in order to cleanup everything and start from scratch the above commands.
- First task run or when environment needs updating might take several minutes for all downloads to be performed
- Environment can be cleaned with >
rcc configuration cleanup --help
(e.g. --all, --dryrun, etc.) https://robocorp.com/docs/rcc/manual - Setting DEBUG=pw:api environment variables before run, enables Playwright log capture (Warning: passwords are logged in this log file)
Instead of using Robocorp and Rcc tool as described above, it is also possible to setup manually Python environment and corresponding libraries and run the tasks with Robot Framework:
-
Download this project release
-
Environment setup
Download and install Python 3.10.1 from https://python.org under a local directory, e.g. C:\Python3x - Choose e.g.: Customize installation, All optional features and Add Python to environment variables option. - Make sure that both Python and Python\Scripts directories are added to Path System variable.
Download and install Node.js 16.14.2 from https://nodejs.org/en/download. It can be installed in the default Program Files location. - For upgrade there is no need to remove previous installation, just install the upgrade in the same location. Also, there is no need to reinstall dependencies during upgrade.
-
Run the following commands in order to install Python libraries used by this project:
pip install robotframework
pip install robotframework-seleniumlibrary
pip install webdrivermanager
pip install robotframework-browser
- After finishing, run:
rfbrowser init
webdrivermanager chrome --linkpath C:\Python3x
(or any folder in the PATH) -
install Visual Studio Code
-
Install the two extensions: Robocorp Code and Robot Framework Language Server
- Within VSCode go to Extension settings and set Robot > Language-server: Python to e.g. C:\Python3x\python.exe or match with above Python installation directory.
-
Open the downloaded rf-robocorp-tutorial folder within VSCode and check the following files:
- Environment variables: env.py and env-my.py
- Robot tests: _test-*.robot
-
Run the test or task with the following command:
robot --outputdir result test-s.robot
robot --outputdir result test-p.robot
robot --outputdir result --variablefile devdata/env-my.py test-s.robot
robot --outputdir result --variablefile devdata/env-my.py test-p.robot
robot --outputdir result test-my.robot
Robocorp specific files:
-
tasks-p.robot, tasks-s.robot, tasks-my.robot contains the tasks instructions
-
devdata\env.json, devdata\env-my.json contains custom variables
-
conda.yaml defines the environment
-
robot.yaml defines the tasks and other run parameters
Robot Framework specific files:
-
test-p.robot, test-s.robot, test-my.robot contains the tests instructions
-
devdata\env.py, devdata\env-my.py contains custom variables
Playwright selectors:
- Run from command line: node inspect.js, go to desired URL, then open developer tools, Console and run playwright.$('text=Google') or playwright.$('anyselector') to test different Playwright selectors are working as expected.
-
Robocorp Documentation: https://robocorp.com/docs/
-
Robocorp RPA Libraries: https://robocorp.com/docs/libraries/rpa-framework
-
Robot Framework User Guide: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
-
Selenium Keywords: https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html
-
Browser Playwright Keywords: https://marketsquare.github.io/robotframework-browser/Browser.html
-
Robot Framework Standard Libraries: https://robotframework.org/robotframework/#standard-libraries
-
Other useful projects examples can be found at: https://github.com/robocorp