Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

Options for checking your automation scripts

Why check your automation scripts before actually using them?

As you build out your automation scripts with Robot Framework, they will become more complex and will likely take some time to run. This becomes even more of a problem once more people start helping you with these scripts and contributing to it through source control. It’s a good idea to make sure that every .robot file is checked for correctness, style issues, and possible syntax errors. There are tools that can assist with statically checking that work without actually executing any of it. This will save you time, and catch problems earlier.

What are the options and their benefits?

The most accessible option for checking your .robot files is to use Robot Framework’s --dryrun feature. This option is built into the framework and can be used immediately without installing anything else. It checks .robot files for syntax errors, missing library dependencies, and it also generates all of the same results output as the regular robot command without actually running any keywords.

Another option is Bryan Oakley’s robotframework-lint (also known as rflint). This is an external linter specifically for checking .robot files and does not utilize any of the internals of Robot Framework. A linter is a static analysis tool that can help identify style issues and other errors in source code. The robotframework-lint tool needs to be installed by running pip install --upgrade robotframework-lint in your terminal or command-line prompt.

How do I use the --dryrun option and robotframework-lint?

Both options can be used by running robot --dryrun <robot-file-name> and rflint <robot-file-name> in your terminal or command-line prompt. It’s a good practice to first run the --dryrun option and fix any syntax or library dependency problems identified by it. Then run rflint to identify and fix any possible style issues. Here are some examples of the capabilities of both options.

Create a file on your machine called check-this-script.robot and save the following in it.

*** Settings *** Library SeleniumLibrary *** Variables *** ${URL} http://www.google.com ${BROWSER} Chrome *** Tasks *** Can you identify the problems in this script? Open Chrome Browser [Teardown] Close Browser *** Keywords *** Open Chrome Browser Open Browser ${URL} ${BROWSER} Sleep 2 Open Chrome Browser Open Browser http://www.yahoo.com ${BROWSER}

Then open a terminal or command-line prompt and go to the specific directory that contains your check-this-script.robot file, and make sure it’s there by running either ls (macOS or Linux users) or dir (Windows users). When you are ready, run the following command.

robot --dryrun check-this-script.robot

The following problems should have been identified and displayed after running that command. This should have also generated log.html and output.xml result files.

Creating keyword 'Open Chrome Browser' failed: Keyword with same name defined multiple times.

From that same terminal or command-line prompt run the following command.

rflint check-this-script.robot

The following problems should have been identified and displayed after running that command.

+ check-this-script.robot E: 15, 0: No keyword documentation (RequireKeywordDocumentation) E: 19, 0: No keyword documentation (RequireKeywordDocumentation) W: 18, 0: Too few steps (1) in keyword (TooFewKeywordSteps)

See robotframework-lint for more instructions on how to use and configure the rflint tool.

Summary

Robot Framework and external tools provide ways for checking your robot scripts. Using them is optional, but they might provide value when your scripts get more complex or when you want to enforce a specific style (such as maximum line lengths) inside your project.

Last edit: June 1, 2020