Robot Framework 5

Intro

You can learn a lot of useful information about the previous version and Robot Framework itself in our article: Robot Framework 4 — Tesena.

In this article, we will focus on new features in the last major release of Robot Framework 5.0.

Robot Framework is a popular tool for a large number of projects Teseners are working on. Upgrading to the new version of this tool can be very useful because of the new features and functionality it brings.

First look

New features were implemented according to a community survey previously created by developers. Let’s see what was introduced to us in this release.

TRY/EXCEPT

Robot Framework 5.0 adds native TRY/EXCEPT syntax, which is the same as Python's exception handling syntax, making handling errors that arise during execution much more convenient than it was previously. The TRY, EXCEPT, ELSE, and FINALLY branches are identical to those in Python, and they function mainly in the same way. One distinction is that while Robot Framework requires all this type of syntax to use upper case letters, Python uses lower case try, except, etc.

*** Test Cases ***

First example

    TRY

        Some Keyword

    EXCEPT    Error message

        Error Handler Keyword

    END

    Keyword Outside

More useful examples can be found here.

WHILE

The new WHILE loops in Robot Framework was one of the most needed features in community for long time. It functions mainly in the same way as similar loops in other languages. Basically, the loop runs until either the loop condition is satisfied, the loop is explicitly terminated using BREAK or RETURN, or one of the loop's keywords fails.

*** Variables ***

${x}              10

*** Test Cases ***

Loop as long as condition is True

    WHILE    ${x} > 0

        Log    ${x}

        ${x} =    Evaluate    ${x} - 1

    END

More useful examples can be found here.

Inline IF

Simplification of usage of basic IF/ELSE structure for straightforward situations.

*** Keyword ***

Normal IF

    IF    $condition1

        Keyword    argument

    END

    IF    $condition2

        RETURN

    END

Inline IF

    IF    $condition1    Keyword    argument

    IF    $condition2    RETURN

BREAK and CONTINUE

*** Test Cases ***

Example

    FOR    ${x}    IN RANGE    1000

        IF    ${x} > 10    BREAK

        Log    Executed only when ${x} < 11

        IF    ${x} % 2 == 0    CONTINUE

        Log    Executed only when ${x} is odd.

    END

RETURN

A universal way to return user keywords has been added by the new RETURN statement. It can be used to return values after the keyword has been executed, as with the old [Return] setting, as well as to return before the keyword has been executed, as supported by the old Return From Keyword keyword

*** Keywords ***

Return at the end

    Some Keyword

    ${result} =    Another Keyword

    RETURN    ${result}

Return conditionally

    IF    ${condition}

        RETURN    Something

    ELSE

        RETURN    Something else

    END

Early return

    IF    ${not applicable}    RETURN

    Some Keyword

    Another Keyword

Another important change: Python 2 is not supported anymore. Robot Framework 5.0 requires Python 3.6 or newer. Unfortunately, this also means that Jython and IronPython are not supported anymore because they do not have Python 3 compatible releases available. If you are using Python 2, Jython, or IronPython, you can continue using Robot Framework 4 series.

Also, there are a lot of other changes and improvements you can read about here

Autor: Dmytro Borysov

Dmytro has almost five years of experience in the testing field. The last two and half years, he is mainly focused on automation testing. He is specialised in programming tests in Python and Robot framework and is also familiar in using Postman for manual API testing.