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!

@Quietbeat
Copy link

Quietbeat commented Jan 13, 2020

I'm completely new to RF and I'm looking for a little assistance. I'm using to 3rd party apps like TestComplete that have a nice interface, the ability to see test run history, and select which tests I want to run and potentially how often. We're using PyCharm (RIDE sometimes) and I'm looking for a GUI that has similar features to TestComplete?

This is a long shot I know but maybe you could help with getting over some hurdles.

  • If I run all tests under a folder that has x number of tests, it appears that the last test will overwrite the Log, Output, and Report files, so how do I get a report for all of the tests that were run?

  • How would I craft a script that calls other scripts within a folder? For example:
    Mainscript.robot

      #Online App folder
          script 1
          script 2
      #Help folder
          script 1
          script 2
    
  • How do I stop RF from creating screenshot after each run?

Thx in advance

@GLMeece
Copy link
Author

GLMeece commented Jan 15, 2020

I'm not really actively doing RF work any more. We deprecated our runs last year. Having said that...

  1. I'm not sure I'm understanding what you're saying. If you do a single run which uses all the folders/directories you have, it will generated one unified report. If you're saying you are doing runs on a per-directory basis, then there's an easy way to avoid overwrites: use the timestamp switch!
  2. That's a little vague. Not sure what you're trying to accomplish here.
  3. Presumably, you're referring to the Selenium Library (which isn't part of the RF core). There's a reference to it here. To implement it, see the section on Importing. To make this drop-dead simple:
*** Settings ***
# various library imports, etc.
Library    SeleniumLibrary    run_on_failure=Nothing

Remember: the official documentation is your friend! 😄

@bobbysteels214
Copy link

bobbysteels214 commented Oct 10, 2021

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

@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