Running Your First Robot Framework Test

Dennis Whalen - Dec 23 '22 - - Dev Community

In my first Robot Framework post I gave a brief overview of Robot Framework and described a sample test. Now it's time for you to get the tests running!

Installing Robot

As mentioned in the previous post, Robot Framework can run on Windows, Mac, or Linux. You'll need to install both Python and Robot Framework.

Instead of describing all the install steps here, it's much easier for all if you just checkout the official instructions from the Robot Framework page.

As mentioned in the install instructions, you can verify you're good to go by running robot --version.

Ok, we're getting closer to running some tests!

IDE support

I'm using Visual Studio code for my Robot Framework examples. Of course there are other IDEs that will work, and you don't need one at all, so feel free to use what makes sense for you.

If you're using Visual Studio code, I highly recommend 2 Extensions:

  • Robot Framework Language Server
  • Robot Code

VS Code extensions

My sample repo

I have a repo with sample code that I will reference. You can clone it from here.

This repo was actually forked from a Cypress sample app. I'll be using more of that in my next post, but for now you can just clone the repo and ignore about 99% of it.

Once you have it cloned, take a look at the file robot-framework/e2e/suites/BasicTest.robot.

If you read the first post, this Robot test should look familiar. This is the test for our calculator app!

Breaking the test into multiple files

This test is a bit different from what we saw in the first post. Robot test suites will usually reference keyword resources in a separate file, and that's what I've done in the sample code.

Now our test suite just has the tests, with a reference to the user keywords in a separate resource file.

This makes the test more readable and helps to encourage keyword reuse across tests suites. So here's our test suite (with some more calculation tests added):


 python
*** Settings ***
Resource        ../resources/calc.resource

*** Test Cases ***
Test some basics of my calculator application
    Log To Console    Starting test
    Verify app calculation    1 + 1    2
    Verify app calculation    14 + 8    22
    Verify app calculation    14 - 8    6
    Verify app calculation    8 - 14    -6
    Verify app calculation    8 * 14    112
    Verify app calculation    14 / 8    1.75
    Verify app calculation    4 + 8 * 2 / 4    8
    Verify app calculation    (4 + 8) * 2 / 4    6


Enter fullscreen mode Exit fullscreen mode

And our resource file:



*** Settings ***
Library    ../libraries/MyCalculatorApplication.py

*** Keywords ***
Verify app calculation 
    [Arguments]    ${term}    ${expected}
    Log To Console    Calculating: ${term}
    ${actual}    Do Math    ${term}
    Log To Console    Calculated Result: ${actual}
    Should Be Equal As Numbers    ${actual}    ${expected}


Enter fullscreen mode Exit fullscreen mode

Running the test

If you have everything installed properly and you've cloned the repo, you can run the test from the command line:



robot robot-framework/e2e/suites/BasicTest.robot


Enter fullscreen mode Exit fullscreen mode

Hopefully you'll have test results that look like this:

Image description

Reporting

In addition to the test results in the console, Robot Framework has also created an html report for the test run. After you run the test you should see the file report.html in the root directory.

If you drill into the basic test you'll see some details like this:
Image description

Of course the reporting is usually more important when we have failures. Go ahead a break the test yourself and see how Robot Framework deals with that.

What's next?

Hopefully you were able to get the test running locally. That will allow you to start experimenting, which is when things start getting real.

In the next post we will bid a fond farewell to our simple calculator app, and create Robot Framework tests for an actual website.

Thanks for reading!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .