Skip to content

Instantly share code, notes, and snippets.

@GLMeece
Last active October 3, 2022 10:00
Show Gist options
  • Save GLMeece/c26aae72fb1f8aa5192065793aab3477 to your computer and use it in GitHub Desktop.
Save GLMeece/c26aae72fb1f8aa5192065793aab3477 to your computer and use it in GitHub Desktop.
How to Run Robot Framework Tests

About

This is a quick "how to run" if you already have everything Robot Framework-related installed. This Gist might be especially handy for those you either just starting out, or if you've inherited a code-base from someone else.

The following assumes you have a terminal (CMD or PowerShell on Windows, Terminal on Mac or Linux) and aren't afraid to use it.

Testing ALL THE THINGS

Test All the Things

  1. cd into the root directory of the Robot Framework files and test cases; we'll assume all test cases are somewhere within a directory named test_cases.
  2. If the directory doesn't already exist, then mkdir reports (this is a convenience - where our reports will live).
  3. Execution step: robot -T -d reports -n noncritical test_cases
  4. You'll see a bunch of stuff on the terminal. Get some ☕ if you have many tests.
  5. When it's done, you'll see the report (timestamped) in the reports directory; double-click the report-YYYYMMDD-HHMMSS.html (where YYYYMMDD is the year, month, date and HHMMSS is the hour, minute, and seconds - e.g, report-20170302-114737.html).

Quick Explanation of Switches Shown

  • -T - Short for --timestampoutputs. Creates reports, logs, etc. with the current timestamp so we don't overwrite existing ones upon execution.
  • -d - Short for --outputdir. Tells the framework where to create the report files.
  • -n - Short for --noncritical. This tells Robot Framework what tag indicates a non-critical test (I've standardized on noncritical to reduce ambiguity).

Try Before You Buy

There's one more switch you should probably use: --dryrun. This tells Robot Framework to run through all of your test cases, resource files, etc. looking for syntax-type problems. Recommended as it can save some headaches if you have a lot to execute. You can add it anywhere in the command line.

Test Everything with a Given Tag

To execute only the test cases with a particular tag, do everything in Testing ALL THE THINGS above, except in step 3, perform:

robot -T -d reports -n noncritical -i NAMEOFTAGHERE test_cases

Substitute NAMEOFTAGHERE with whatever is appropriate; e.g., smoke or api. This will execute all test cases that include the tag you specify. The -i is short for --include which means "include for testing only those test cases with this tag".

Also, you can "stack" the selected tags by repeating the switch and tag name. For example, you could do -i negative -i smoke and it would execute all test cases which have a tag of both negative and smoke.

Test Only a Given Suite

To execute only a particular test suite (file), do everything in Testing ALL THE THINGS above, except in step 3, perform:

robot -T -d reports -n noncritical test_case/path/to/case.robot

where /path/to/case.robot is of course the path to the suite (file) you want to execute.

Test Only a Particular Test Case

To execute only a particular test case, do everything in Testing ALL THE THINGS above, except in step 3, perform:

robot -T -d reports -n noncritical -t "Name of Test Case Here" test_case/path/to/case.robot

where "Name of Test Case Here" is the name of the test case within the file pointed to via /path/to/case.robot. For example, if you wanted to execute the test case Verify All Widgets Present within the Smoke - Dashboard Page suite, you'd execute:

robot -T -d reports -n noncritical -t "Verify All Widgets Present" test_case/path/to/dashboard_tests.robot

For More Info...

See the official word on all command-line switches. Have fun!

@bobbysteels214
Copy link

I have an init.robot that contains a Suite Setup. In the same directory I have a couple robot files with test cases: init.robot # there are 2 leading and trailing underscores around init, but they get removed when I post my comment foo1.robot foo2.robot

If I run "robot ." the foo1 and foo2 files will both run, and will call the Suite Setup in init.robot. If I run "robot foo1.robot", foo1 will execute, but it will not use the Suite Setup in init.robot. How can I run only foo1.robot, and also have it use the Suite Setup in the init.robot file?

Thank you

Actually, I think I just figured it out.
robot --suite 'foo1' .

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment