An introduction to. Robot Framework Generic test automation framework. – Utilizes the User Guide. – portal7.info#user- guide. PDF | Manual testing is a time consuming process. In addition, regression testing, because of its repetitive nature, is error-prone, so automation is highly. use Robot Framework to build tests that perform automation testing of an sary step in software testing to eliminate unnecessary documentation bugs and to en- URL: portal7.info
|Language:||English, Spanish, Portuguese|
|ePub File Size:||30.51 MB|
|PDF File Size:||18.83 MB|
|Distribution:||Free* [*Sign up for free]|
Robot Framework documentation such as this User Guide use the Creative Tasks *** Process invoice Read information from PDF Validate information. This page contains links to version specific Robot Framework User Guide, standard library, and built-in tool documentation. See portal7.info and. This documentation describes the public API of Robot Framework. Installation, basic usage and wealth of other topics are covered by the Robot.
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together. See the web demo project for executable versions of the above examples. The web demo project contains an executable version of this example too. Skip to content. Permalink Dismiss Join GitHub today GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together. Sign up.
Its development is sponsored by the Robot Framework Foundation. This User Guide still talks mainly about creating tests, test data, and test libraries, but same concepts apply also when creating tasks. Robot Framework is a generic, application and technology independent framework. It has a highly modular architecture illustrated in the diagram below. The test data is in simple, easy-to-edit tabular format. When Robot Framework is started, it processes the data, executes test cases and generates logs and reports.
The core framework does not know anything about the target under test, and the interaction with it is handled by libraries. Libraries can either use application interfaces directly or use lower level test tools as drivers. Following screenshots show examples of the test data and created reports and logs. The number one place to find more information about Robot Framework and the rich ecosystem around it is http: Robot Framework itself is hosted on GitHub.
There are several Robot Framework mailing lists where to ask and search for more information. The mailing list archives are open for everyone including the search engines and everyone can also join these lists freely. Only list members can send mails, though, and to prevent spam new users are moderated which means that it might take a little time before your first message goes through.
Robot Framework is open source software provided under the Apache License 2. Most libraries and tools in the larger ecosystem around the framework are also open source, but they may use different licenses. These instructions cover installing and uninstalling Robot Framework and its preconditions on different operating systems.
If you already have pip installed, it is enough to run:. NET and PyPy.
Before installing the framework, an obvious precondition is installing at least one of these interpreters. Different ways to install Robot Framework itself are listed below and explained more thoroughly in the subsequent sections.
Using pip is the recommended way to install Robot Framework. As the standard Python package manager it is included in the latest Python, Jython and IronPython versions. If you already have pip available, you can simply execute:. Prior to Robot Framework 3. Because Python 2. The recommend installation approach also on Windows is using pip. The interpreter you want to use should be installed before installing the framework itself.
Which interpreter to use depends on the needed test libraries and test environment in general. Some libraries use tools or modules that only work with Python, while others may use Java tools that require Jython or need. NET and thus IronPython. There are also many tools and libraries that run fine with all interpreters.
If you do not have special needs or just want to try out the framework, it is recommended to use Python. It is the most mature implementation, considerably faster than Jython or IronPython especially start-up time is faster , and also readily available on most UNIX-like operating systems.
Another good alternative is using the standalone JAR distribution that only has Java as a precondition. Python 2 and Python 3 are mostly the same language, but they are not fully compatible with each others. The main difference is that in Python 3 all strings are Unicode while in Python 2 strings are bytes by default, but there are also several other backwards incompatible changes. The last Python 2 release is Python 2. See Should I use Python 2 or 3? Robot Framework 3. It supports also Python 2, and the plan is to continue Python 2 support as long as Python 2 itself is officially supported.
We hope that authors of the libraries and tools in the wider Robot Framework ecosystem also start looking at Python 3 support now that the core framework supports it.
If you are on Windows or otherwise need to install Python yourself, a good place to start is http: There you can download a suitable installer and get more information about the installation process and Python in general.
If you need to use older versions, Robot Framework 2. After installing Python, you probably still want to configure PATH to make Python itself as well as the robot and rebot runner scripts executable on the command line. This is disabled by default, but Add python. Installing either of these Java distributions is out of the scope of these instructions, but you can find more information, for example, from http: Installing Jython is a fairly easy procedure, and the first step is getting an installer from http: Depending on the system configuration, it may also be possible to just double-click the installer.
If older Jython or Java versions are needed, Robot Framework 2. After installing Jython, you probably still want to configure PATH to make Jython itself as well as the robot and rebot runner scripts executable on the command line.
IronPython allows running Robot Framework on the. NET platform and interacting with C and other. Only IronPython 2. If not using IronPython 2. This is required because the ElementTree module distributed with older IronPython versions was broken. Once you have pip activated for IronPython , you can easily install ElementTree using this command:. Alternatively you can download the zip package, extract it, and install it by running ipy setup.
After installing IronPython, you probably still want to configure PATH to make IronPython itself as well as the robot and rebot runner scripts executable on the command line. PyPy is an alternative implementation of the Python language with both Python 2 and Python 3 compatible versions available. Its main advantage over the standard Python implementation is that it can be faster and use less memory, but this depends on the context where and how it is used.
If execution speed is important, at least testing PyPY is probably a good idea. Installing PyPy is a straightforward procedure and you can find both installers and installation instructions at http: After installation you probably still want to configure PATH to make PyPy itself as well as the robot and rebot runner scripts executable on the command line.
The PATH environment variable lists locations where commands executed in a system are searched from. To make using Robot Framework easier from the command prompt, it is recommended to add the locations where the runner scripts are installed into the PATH. It is also often useful to have the interpreter itself in the PATH to make executing it easy.
What directories you need to add to the PATH depends on the interpreter and the operating system. The first location is the installation directory of the interpreter e. Both Python and IronPython install scripts to Scripts directory under the installation directory on Windows e.
Notice that the Scripts and bin directories may not be created as part of the interpreter installation, but only later when Robot Framework or some other third party module is installed. Notice that the exact setting names may be different on different Windows versions, but the basic approach should still be the same.
Notice that if you have multiple Python versions installed, the executed robot or rebot runner script will always use the one that is first in the PATH regardless under what Python version that script is installed. To avoid that, you can always execute the installed robot module directly like C: Notice also that you should not add quotes around directories you add into the PATH e.
Quotes can cause problems with Python programs and they are not needed in this context even if the directory path would contain spaces. On UNIX-like systems you typically need to edit either some system wide or user specific configuration file. Which file to edit and how depends on the system, and you need to consult your operating system documentation for more details.
It is needed both when installing pip itself and when using it to install Robot Framework and other Python packages. The value of this variable must be an URL of the proxy, for example, http: These instructions only cover using pip, but other package managers ought be able to install Robot Framework as well.
Which versions contain it and how to possibly activate it is discussed in sections below. See pip project pages if for the latest installation instructions if you need to install it.
It is possible to install both using pip, but installing wheels is a lot faster. Only Robot Framework 2. If you need an older version, you must use other installation approaches. Starting from Python 2. With Python 3. Outside Windows and with older Python versions you need to install pip yourself. You may be able to do it using system package managers like Apt or Yum on Linux, but you can always use the manual installation instructions found from the pip project pages.
If you have multiple Python versions with pip installed, the version that is used when the pip command is executed depends on which pip is first in the PATH. An alternative is executing the pip module using the selected Python version directly:.
Jython 2. Does running pip install robotframework actually use it or possibly some other pip version depends on which pip is first in the PATH. An alternative is executing the pip module using Jython directly:. IronPython 2. With IronPython 2. Frames command line option when activating pip like ipy -X: Frames -m ensurepip and also when using it.
Prior to IronPython 2. Using IronPython 2. An alternative is executing the pip module using IronPython directly:. Also PyPy contains pip bundled in. It is not activated by default, but it can be activated similarly as with the other interpreters:.
An alternative is executing the pip module using PyPy directly:. The easiest way to use pip is by letting it find and download packages it installs from the Python Package Index PyPI , but it can also install packages downloaded from the PyPI separately. The most common usages are shown below and pip documentation has more information and examples. Notice that pip 1. If you want to install an alpha, beta or release candidate, you need to either specify the version explicitly or use the --pre option:.
Notice that on Windows pip, by default, does not recreate robot. This mainly causes problems when using virtual environments , but is something to take into account also if doing custom installations using pip. A workaround if using the --no-cache-dir option like pip install --no-cache-dir robotframework. Alternatively it is possible to ignore the start-up scripts altogether and just use python -m robot and python -m robot. This installation method can be used on any operating system with any of the supported interpreters.
Installing from source can sound a bit scary, but the procedure is actually pretty straightforward. You typically get the source code by downloading a source distribution from PyPI.
Starting from Robot Framework 3. The directory contains the source code and a setup. An alternative approach for getting the source code is cloning project's GitHub repository directly. By default you will get the latest code, but you can easily switch to different released versions or other tags. Robot Framework is installed from source using Python's standard setup.
The script is in the directory containing the sources and you can run it from the command line using any of the supported interpreters:. The setup. It is also used for creating different distribution packages.
Run python setup. Robot Framework is also distributed as a standalone Java archive that contains both Jython and Robot Framework and only requires Java a dependency. It is an easy way to get everything in one package that requires no installation, but has a downside that it does not work with the normal Python interpreter. After downloading the package, you can execute tests with it like:.
If you want to post-process outputs using Rebot or use other built-in supporting tools , you need to give the command name rebot , libdoc , testdoc or tidy as the first argument to the JAR file:. If you do not want to use any automatic way of installing Robot Framework, you can always install it manually following these steps:. After a successful installation, you should be able to execute the created runner scripts with --version option and get both Robot Framework and interpreter versions as a result:.
If running the runner scripts fails with a message saying that the command is not found or recognized, a good first step is double-checking the PATH configuration. If that does not help, it is a good idea to re-read relevant sections from these instructions before searching help from the Internet or as asking help on robotframework-users mailing list or elsewhere.
When an automatic installer is used, Robot Framework source code is copied into a directory containing external Python modules. The actual Robot Framework code is in a directory named robot. Robot Framework runner scripts are created and copied into another platform-specific location. On Windows and with Jython and IronPython, the scripts are typically either in Scripts or bin directory under the interpreter installation directory. The easiest way to uninstall Robot Framework is using pip:. A nice feature in pip is that it can uninstall packages even if they are installed from the source.
If you do not have pip available or have done a manual installation to a custom location, you need to find where files are installed and remove them manually. If you have set PATH or configured the environment otherwise, you need to undo those changes separately. If you are using pip , upgrading to a new version requires either specifying the version explicitly or using the --upgrade option.
If upgrading to a preview release, --pre option is needed as well. When using pip, it automatically uninstalls previous versions before installation. If you are installing from source , it should be safe to just install over an existing installation. If you encounter problems, uninstallation before installation may help.
When upgrading Robot Framework, there is always a change that the new version contains backwards incompatible changes affecting existing tests or test infrastructure. Such changes are very rare in minor versions like 2. Backwards incompatible changes and deprecated features are explained in the release notes, and it is a good idea to study them especially when upgrading to a new major version.
Both of these scripts are installed as part of the normal installation and can be executed directly from the command line if PATH is set correctly. They are implemented using Python except on Windows where they are batch files. Older Robot Framework versions do not have the robot script and the rebot script is installed only with Python. Instead they have interpreter specific scripts pybot , jybot and ipybot for test execution and jyrebot and ipyrebot for post-processing outputs.
These scripts still work, but they will be deprecated and removed in the future. An alternative way to run tests is executing the installed robot module or its sub module robot. This is especially useful if Robot Framework is used with multiple Python versions:. The support for python -m robot approach is a new feature in Robot Framework 3. The latter must also be used with Python 2. Post-processing outputs using the same approach works too, but the module to execute is robot.
If you know where Robot Framework is installed, you can also execute the installed robot directory or the run. Running the directory is a new feature in Robot Framework 3. Executing Robot Framework this way is especially handy if you have done a manual installation. Python virtual environments allow Python packages to be installed in an isolated location for a particular system or application, rather than installing all packages into the same global location.
Virtual environments can be created using the virtualenv tool or, starting from Python 3. Robot Framework in general works fine with virtual environments. The only problem is that when using pip on Windows, robot. This means that if Robot Framework is installed into multiple virtual environments, the robot. A workaround is using the --no-cache-dir option when installing. Alternatively the start-up scripts can be ignored and python -m robot and python -m robot. This section covers Robot Framework's overall test data syntax.
The following sections will explain how to actually create test cases, test suites and so on. Although this section mostly uses term test , the same rules apply also when creating tasks. Test case files, test suite initialization files and resource files are all created using Robot Framework test data syntax. Test libraries and variable files are created using "real" programming languages, most often Python.
Different sections are recognized by their header row. In addition to using the plural format, also singular variants like Setting and Test Case are accepted. The header row can contain also other data than the actual section header. The extra data must be separated from the section header using the data format dependent separator, typically two or more spaces. These extra headers are ignored at parsing time, but they can be used for documenting purposes. This is especially useful when creating test cases using the data-driven style.
TestCases or extra spaces added e. This is now deprecated and only the format in the table above, case-insensitively, is supported. Comments sections can be used if sections not containing actual test data are needed. In Robot Framework 3. The support for the HTML format has bee deprecated in general it will be removed altogether in the future. The plain text format is the base for all supported Robot Framework data formats. Test data is parsed line by line, but long logical lines can be split if needed.
In a single line different data items like keywords and their arguments are separated from each others using a separator. The most commonly used separator is two or more spaces, but it is also possible to use a pipe character surrounded with spaces.
Depending on the separator we can talk about the space separated format and the pipe separated format , but same file can actually contain lines with both separators. Possible literal tab characters are converted to two spaces before parsing lines otherwise. This allows using a single tab as a separator instead of multiple spaces. Notice, however, that multiple consecutive tabs are still considered to be a single separator.
In the space separated format two or more spaces or one or more tab characters act as a separator between different data items. The number of spaces used as separator can vary, as long as there are at least two, making it possible to align the data nicely in settings and elsewhere if it makes sense. Although using two spaces as a separator is enough, it is recommend to use four spaces to make the separator easier to notice. The biggest problem of the space delimited format is that visually separating keywords from arguments can be tricky.
In such cases the pipe delimited variant can work better because it makes the separator more visible. One file can contain both space separated and pipe separated lines. Pipe separated lines are recognized by the mandatory leading pipe character, but the pipe at the end of the line is optional. There must always be at least one space on both sides of the pipe except at the beginning and at the end of the line.
There is no need to align the pipes, but that often makes the data easier to read. There is no need to escape empty cells other than the trailing empty cells when using the pipe separated format. Possible pipes surrounded by spaces in the actual test data must be escaped with a backslash, though:. Plain text files can be easily edited using normal text editors and IDEs.
Many of these tools also have plugins that support syntax highlighting Robot Framework test data and may also provide other features such as keyword completion.
The recommended extension for test case files in the plain text format is. Files using this extension are parsed automatically. Also the. When creating resource files , it is possible to use the special.
This way resource files and test cases files are easily separated from each others. Files in the tab-separated values TSV format are typically edited in spreadsheet programs and, because the syntax is so simple, they are easy to generate programmatically. They are also pretty easy to edit using normal text editors and they work well in version control, but the plain text format is even better suited for these purposes.
The TSV format and the space separated variant of the plain text format are nearly identical, but earlier Robot Framework versions had slightly different parser for these formats. The differences were:. It is still possible to use the TSV format, but files must be fully compatible with the plain text format.
This basically requires escaping all empty cells and configuring spreadsheet program or other tool saving TSV files not to add surrounding quotes to cells. Select the tab-separated format when you save the file. It is also a good idea to turn all automatic corrections off and configure the tool to treat all values in the file as plain text.
As explained above, TSV files should also be saved so that no quotes are added around the cells. TSV files are relatively easy to edit with any text editor, especially if the editor supports visually separating tabs from spaces.
Files in the TSV format are customarily saved using the. Another possibility is saving also these files using the the. Using reST with Robot Framework allows you to mix richly formatted documents and test data in a concise text format that is easy to work with using simple text editors, diff tools, and source control systems.
When using reST files with Robot Framework, test data is defined using code blocks. When these documents are compiled into HTML or other formats, the code blocks are syntax highlighted using Pygments.
In standard reST code blocks are started using the code directive, but Sphinx uses code-block or sourcecode instead. The name of the programming language in the code block is given as an argument to the directive. For example, following code blocks contain Python and Robot Framework examples, respectively:. When Robot Framework parses reStructuredText files, it first searches for possible code , code-block or sourcecode blocks containing Robot Framework test data.
If such code blocks are found, data they contain is written into an in-memory file and executed. All data outside the code blocks is ignored. The test data in the code blocks must be defined using the plain text format. As the example below illustrates, both space and pipe separated variants are supported:. Earlier Robot Framework versions supported using reStructuredText also so that test data was defined in tables.
These files were then internally converted to HTML format before parsing them. This functionality was deprecated in Robot Framework 3. Test data in reStructuredText files can be edited with any text editor, and many editors also provide automatic syntax highlighting for it. Robot Framework supports reStructuredText files using both. This may hide also real errors, but they can be seen when processing files using reStructuredText tooling normally.
All test data in HTML format should be converted to the plain text format or other supported formats. This is typically easiest by using the built-in Tidy tool. When Robot Framework ignores some data, this data is not available in any resulting reports and, additionally, most tools used with Robot Framework also ignore them.
To add information that is visible in Robot Framework outputs, place it to the documentation or other metadata of test cases or suites, or log it with the BuiltIn keywords Log or Comment. Different escaping mechanisms are discussed in the sections below. The backslash character can be used to escape special characters so that their literal values are used. The backslash character also allows creating special escape sequences that are recognized as characters that would otherwise be hard or impossible to create in the test data.
This behavior may change in the future, though. The motivation for this is to allow wrapping long lines containing newlines when using the HTML format, but the same logic is used also with other formats.
An exception to this rule is that the whitespace character is not ignored inside the extended variable syntax. If empty values are needed as arguments for keywords or otherwise, they often need to be escaped to prevent them from being ignored. Empty trailing cells must be escaped regardless of the test data format, and when using the space separated format all empty values must be escaped. The latter is typically recommended as it is easier to understand. All these cases are illustrated by the following examples:.
Spaces, especially consecutive spaces, as part of arguments for keywords or needed otherwise are problematic for two reasons:.
In these cases spaces need to be escaped. It is especially handy in combination with the extended variable syntax when more than one space is needed. If there is more data than readily fits a row, it possible to use ellipsis In test case and keyword tables, the ellipsis must be preceded by at least one empty cell.
In settings and variable tables, it can be placed directly under the setting or variable name. In all tables, all empty cells before the ellipsis are ignored. Also suite, test or keyword documentation and value of test suite metadata can be too long to fit into one row nicely.
These values can be split into multiple rows as well, and they will be joined together with newlines. All the syntax discussed above is illustrated in the following examples. In the first three tables test data has not been split, and the following three illustrate how fewer columns are needed after splitting the data to several rows. This section describes the overall test case syntax.
Organizing test cases into test suites using test case files and test suite directories is discussed in the next section. When using Robot Framework for other automation purposes than test automation, it is recommended to create tasks instead of tests. The task syntax is for most parts identical to the test syntax, and the differences are explained in the Creating tasks section. Test cases are constructed in test case tables from the available keywords.
Keywords can be imported from test libraries or resource files , or created in the keyword table of the test case file itself.
The first column in the test case table contains test case names. A test case starts from the row with something in this column and continues to the next test case name or to the end of the table. It is an error to have something between the table headers and the first test. The second column normally has keyword names. An exception to this rule is setting variables from keyword return values , when the second and possibly also the subsequent columns contain variable names and a keyword name is located after them.
In either case, columns after the keyword name contain possible arguments to the specified keyword. Although test case names can contain any character, using? Test cases can also have their own settings. Setting names are always in the second column, where keywords normally are, and their values are in the subsequent columns.
Setting names have square brackets around them to distinguish them from keywords. The available settings are listed below and explained later in this section. Setting names are case-insensitive, but the format used above is recommended. This is now deprecated and only the format above, case-insensitively, is supported.
Possible space between brackets and the name e. The Setting table can have the following test case related settings. These settings are mainly default values for the test case specific settings listed earlier. The earlier examples have already demonstrated keywords taking different arguments, and this section discusses this important functionality more thoroughly. How to actually implement user keywords and library keywords with different arguments is discussed in separate sections.
Keywords can accept zero or more arguments, and some arguments may have default values. What arguments a keyword accepts depends on its implementation, and typically the best place to search this information is keyword's documentation. In the examples in this section the documentation is expected to be generated using the Libdoc tool, but the same information is available on documentation generated by generic documentation tools such as javadoc.
Most keywords have a certain number of arguments that must always be given. In the keyword documentation this is denoted by specifying the argument names separated with a comma like first, second, third. The argument names actually do not matter in this case, except that they should explain what the argument does, but it is important to have exactly the same number of arguments as specified in the documentation.
Using too few or too many arguments will result in an error. Their arguments are specified as path and source, destination , which means that they take one and two arguments, respectively. The last keyword, No Operation from BuiltIn , takes no arguments. Arguments often have default values which can either be given or not. It is possible that all the arguments have default values, but there cannot be any positional arguments after arguments with default values.
Trying to use it without any arguments or more than three arguments would not work. It is also possible that a keyword accepts any number of arguments. These so called varargs can be combined with mandatory arguments and arguments with default values, but they are always given after them.
The former can be used with any number of arguments, but the latter requires at least one argument. The named argument syntax makes using arguments with default values more flexible, and allows explicitly labeling what a certain argument value means.
Technically named arguments work exactly like keyword arguments in Python. This is especially useful when multiple arguments have default values, as it is possible to name only some the arguments and let others use their defaults. If this sounds complicated, the named arguments example below hopefully makes it more clear.
The named argument syntax is both case and space sensitive. The relative order of the named arguments does not matter.
It is possible to use variables in both named argument names and values. If the value is a single scalar variable , it is passed to the keyword as-is.
This allows using any objects, not only strings, as values also when using the named argument syntax. If variables are used in named argument names, variables are resolved before matching them against argument names. The named argument syntax requires the equal sign to be written literally in the keyword call. This is important to remember especially when wrapping keywords into other keywords.
This is illustrated by the example below. If keyword needs to accept and pass forward any named arguments, it must be changed to accept free named arguments. See free named argument examples for a wrapper keyword version that can pass both positional and named arguments forward. The named argument syntax is used only when the part of the argument before the equal sign matches one of the keyword's arguments. In this case the argument foo either incorrectly gets the value quux or, more likely, there is a syntax error.
Note that escaping is not needed if there are no arguments with name foo , but because it makes the situation more explicit, it may nevertheless be a good idea. As already explained, the named argument syntax works with keywords. In addition to that, it also works when importing libraries. Naming arguments is supported by user keywords and by most test libraries. The only exception are Java based libraries that use the static library API. Library documentation generated with Libdoc has a note does the library support named arguments or not.
The following example demonstrates using the named arguments syntax with library keywords, user keywords, and when importing the Telnet test library.
Free named arguments are supported by same keyword types than normal named arguments. How keywords specify that they accept free named arguments depends on the keyword type. Free named arguments support variables similarly as named arguments.
In practice that means that variables can be used both in names and values, but the escape sign must always be visible literally.
An extra limitation is that free argument names must always be strings. As the first example of using free named arguments, let's take a look at Run Process keyword in the Process library. The example below also shows that variables work with free keyword arguments exactly like when using the named argument syntax. As the second example, let's create a wrapper user keyword for running the program. The wrapper keyword Run Program accepts all positional and named arguments and passes them forward to Run Process along with the name of the command to execute.
This syntax is inspired by the keyword-only arguments syntax supported by Python 3. For most parts named-only arguments work the same way as named arguments. The main difference is that libraries implemented with Python 2 using the static library API do not support this syntax. As an example of using the named-only arguments with user keywords , here is a variation of the Run Program in the above free named argument examples that only supports configuring shell:.
A totally different approach to specify arguments is embedding them into keyword names. This syntax is supported by both test library keywords and user keywords. A test case fails if any of the keyword it uses fails.
Normally this means that execution of that test case is stopped, possible test teardown is executed, and then execution continues from the next test case. It is also possible to use special continuable failures if stopping test execution is not desired. The error message assigned to a failed test case is got directly from the failed keyword. Often the error message is created by the keyword itself, but some keywords allow configuring them.
In some circumstances, for example when continuable failures are used, a test case can fail multiple times. In that case the final error message is got by combining the individual errors. Very long error messages are automatically cut from the middle to keep reports easier to read, but full error messages are always visible in log files as messages of the failed keywords.
By default error messages are normal text, but they can contain HTML formatting. This marker will be removed from the final error message shown in reports and logs.
Using HTML in a custom message is shown in the second example below. The test case name comes directly from the Test Case table: Test cases in one test suite should have unique names.
It is available whenever a test is being executed, including all user keywords, as well as the test setup and the test teardown. The [Documentation] setting allows you to set a free documentation for a test case.
That text is shown in the command line output, as well as the resulting test logs and test reports. It is possible to use simple HTML formatting in documentation and variables can be used to make the documentation dynamic. If documentation is split into multiple columns, cells in one row are concatenated together with spaces.
This is mainly be useful when using the HTML format and columns are narrow. If documentation is split into multiple rows , the created documentation lines themselves are concatenated using newlines. Newlines are not added if a line already ends with a newline or an escaping backslash. It is important that test cases have clear and descriptive names, and in that case they normally do not need any documentation. If the logic of the test case needs documenting, it is often a sign that keywords in the test case need better names and they are to be enhanced, instead of adding extra documentation.
Finally, metadata, such as the environment and user information in the last example above, is often better specified using tags. Using tags in Robot Framework is a simple, yet powerful mechanism for classifying test cases. Tags are free text and they can be used at least for the following purposes:. In this section it is only explained how to set tags for test cases, and different ways to do it are listed below. These approaches can naturally be used together.
Tags are free text, but they are normalized so that they are converted to lowercase and all spaces are removed. If a test case gets the same tag several times, other occurrences than the first one are removed. Tags can be created using variables, assuming that those variables exist. Users are generally free to use whatever tags that work in their context. There are, however, certain tags that have a predefined meaning for Robot Framework itself, and using them for other purposes can have unexpected results.
All special tags Robot Framework has and will have in the future have the robot: To avoid problems, users should thus not use any tag with this prefixes unless actually activating the special functionality. At the time of writing, the only special tags are robot: More usages are likely to be added in the future. Robot Framework has similar test setup and teardown functionality as many other test automation frameworks.
In short, a test setup is something that is executed before a test case, and a test teardown is executed after a test case. In Robot Framework setups and teardowns are just normal keywords with possible arguments.
Setup and teardown are always a single keyword. If they need to take care of multiple separate tasks, it is possible to create higher-level user keywords for that purpose. An alternative solution is executing multiple keywords using the BuiltIn keyword Run Keywords. The test teardown is special in two ways. First of all, it is executed also when a test case fails, so it can be used for clean-up activities that must be done regardless of the test case status.
In addition, all the keywords in the teardown are also executed even if one of them fails. This continue on failure functionality can be used also with normal keywords, but inside teardowns it is on by default. The easiest way to specify a setup or a teardown for test cases in a test case file is using the Test Setup and Test Teardown settings in the Setting table.
Individual test cases can also have their own setup or teardown. They are defined with the [Setup] or [Teardown] settings in the test case table and they override possible Test Setup and Test Teardown settings.
Having no keyword after a [Setup] or [Teardown] setting means having no setup or teardown. The name of the keyword to be executed as a setup or a teardown can be a variable. This facilitates having different setups or teardowns in different environments by giving the keyword name as a variable from the command line. Test suites can have a setup and teardown of their own. A suite setup is executed before any test cases or sub test suites in that test suite, and similarly a suite teardown is executed after them.
Test templates convert normal keyword-driven test cases into data-driven tests. Whereas the body of a keyword-driven test case is constructed from keywords and their possible arguments, test cases with template contain only the arguments for the template keyword.
Template keywords can accept both normal positional and named arguments, as well as arguments embedded to the keyword name. Unlike with other settings, it is not possible to define a template using a variable. How a keyword accepting normal positional arguments can be used as a template is illustrated by the following example test cases.
These two tests are functionally fully identical. As the example illustrates, it is possible to specify the template for an individual test case using the [Template] setting.
An alternative approach is using the Test Template setting in the Setting table, in which case the template is applied for all test cases in that test case file. The [Template] setting overrides the possible template set in the Setting table, and an empty value for [Template] means that the test has no template even when Test Template is used.
It is also possible to use value NONE to indicate that a test has no template. If a templated test case has multiple data rows in its body, the template is applied for all the rows one by one. This means that the same keyword is executed multiple times, once with data on each row. Templated tests are also special so that all the rounds are executed even if one or more of them fails. It is possible to use this kind of continue on failure mode with normal tests too, but with the templated tests the mode is on automatically.
Using arguments with default values or varargs , as well as using named arguments and free named arguments , work with templates exactly like they work otherwise. Using variables in arguments is also supported normally. Templates support a variation of the embedded argument syntax. With templates this syntax works so that if the template keyword has variables in its name, they are considered placeholders for arguments and replaced with the actual arguments used with the template.
The resulting keyword is then used without positional arguments. This is best illustrated with an example:. When embedded arguments are used with templates, the number of arguments in the template keyword name must match the number of arguments it is used with.
The argument names do not need to match the arguments of the original keyword, though, and it is also possible to use different arguments altogether:.
The main benefit of using embedded arguments with templates is that argument names are specified explicitly. When using normal arguments, the same effect can be achieved by naming the columns that contain arguments. This is illustrated by the data-driven style example in the next section.
If templates are used with for loops , the template is applied for all the steps inside the loop. The continue on failure mode is in use also in this case, which means that all the steps are executed with all the looped elements even if there are failures.
There are several different ways in which test cases may be written. Test cases that describe some kind of workflow may be written either in keyword-driven or behavior-driven style. Data-driven style can be used to test the same workflow with varying input data.
Workflow tests, such as the Valid Login test described earlier , are constructed from several keywords and their possible arguments. Their normal structure is that first the system is taken into the initial state Open Login Page in the Valid Login example , then something is done to the system Input Name , Input Password , Submit Credentials , and finally it is verified that the system behaved as expected Welcome Page Should Be Open.
Another style to write test cases is the data-driven approach where test cases use only one higher-level keyword, often created as a user keyword , that hides the actual test workflow.
It would be possible to repeat the same keyword with every test, but the test template functionality allows specifying the keyword to use only once. Naming columns like in the example above makes tests easier to understand. This is possible because on the header row other cells except the first one are ignored. When using test templates , all the rounds in a test are executed even if there are failures, so there is no real functional difference between these two styles. In the above example separate combinations are named so it is easier to see what they test, but having potentially large number of these tests may mess-up statistics.
Which style to use depends on the context and personal preferences. It is also possible to write test cases as requirements that also non-technical project stakeholders must understand.
When writing test cases in this style, the initial state is usually expressed with a keyword starting with word Given , the actions are described with keyword starting with When and the expectations with a keyword starting with Then.
Keyword starting with And or But may be used if a step has more than one action. Prefixes Given , When , Then , And and But are dropped when matching keywords are searched, if no match with the full name is found. This works for both user keywords and library keywords. For example, Given login page is open in the above example can be implemented as user keyword either with or without the word Given. Ignoring prefixes also allows using the same keyword with different prefixes.
For example Welcome page should be open could also used as And welcome page should be open. When writing concrete examples it is useful to be able pass actual data to keyword implementations.
User keywords support this by allowing embedding arguments into keyword name. In addition to test automation, Robot Framework can be used for other automation purposes, including robotic process automation RPA. It has been always been possible, bu Robot Framework 3. For most parts creating tasks works the same way as creating tests and the only real difference is in terminology.
Tasks can also be organized into suites exactly like test cases. Tasks are created based on the available keywords exactly like test cases, and the task syntax is in general identical to the test case syntax.
The main difference is that tasks are created in task sections or tables instead of test case sections:. Settings that can be used in the task section are exactly the same as in the test case section.
Robot Framework test cases are created in test case files, which can be organized into directories. These files and directories create a hierarchical test suite structure. Same concepts apply also when creating tasks , but the terminology differs. Robot Framework test cases are created using test case tables in test case files.
Such a file automatically creates a test suite from all the test cases it contains. There is no upper limit for how many test cases there can be, but it is recommended to have less than ten, unless the data-driven approach is used, where one test case consists of only one high-level keyword. All setting names can optionally include a colon at the end, for example Documentation: This can make reading the settings easier especially when using the plain text format.
SuiteSetup or extra spaces added e. Test case files can be organized into directories, and these directories create higher-level test suites. A test suite created from a directory cannot have any test cases directly, but it contains other test suites with test cases, instead.
These directories can then be placed into other directories creating an even higher-level suite.
There are no limits for the structure, so test cases can be organized as needed. When a test directory is executed, the files and directories it contains are processed recursively as follows:. If a file or directory that is processed does not contain any test cases, it is silently ignored a message is written to the syslog and the processing continues. A test suite created from a directory can have similar settings as a suite created from a test case file.
Because a directory alone cannot have that kind of information, it must be placed into a special test suite initialization file. The name format is borrowed from Python, where files named in this manner denote that a directory is a module. Initialization files have the same structure and syntax as test case files, except that they cannot have test case tables and not all settings are supported.
Variables and keywords created or imported in initialization files are not available in the lower level test suites. The interpreter you want to use should be installed before installing the framework itself. Which interpreter to use depends on the needed test libraries and test environment in general. Some libraries use tools or modules that only work with Python, while others may use Java tools that require Jython or need.
NET and thus IronPython. There are also many tools and libraries that run fine with all interpreters. If you do not have special needs or just want to try out the framework, it is recommended to use Python. It is the most mature implementation, considerably faster than Jython or IronPython especially start-up time is faster , and also readily available on most UNIX-like operating systems. Another good alternative is using the standalone JAR distribution that only has Java as a precondition.
Python 2 vs Python 3 Python 2 and Python 3 are mostly the same language, but they are not fully compatible with each others. The main difference is that in Python 3 all strings are Unicode while in Python 2 strings are bytes by default, but there are also several other backwards incompatible changes. The last Python 2 release is Python 2. See Should I use Python 2 or 3? Robot Framework 3. It supports also Python 2, and the plan is to continue Python 2 support as long as Python 2 itself is officially supported.
We hope that authors of the libraries and tools in the wider Robot Framework ecosystem also start looking at Python 3 support now that the core framework supports it. There you can download a suitable installer and get more information about the installation process and Python in general. If you need to use older versions, Robot Framework 2. After installing Python, you probably still want to configure PATH to make Python itself as well as the robot and rebot runner scripts executable on the command line.
This is disabled by default, but Add python. Depending on the system configuration, it may also be possible to just double-click the installer. If older Jython or Java versions are needed, Robot Framework 2. After installing Jython, you probably still want to configure PATH to make Jython itself as well as the robot and rebot runner scripts executable on the command line. NET platform and interacting with C and other. Only IronPython 2. If not using IronPython 2.
This is required because the ElementTree module distributed with older IronPython versions was broken. After installing IronPython, you probably still want to configure PATH to make IronPython itself as well as the robot and rebot runner scripts executable on the command line. PyPy installation PyPy is an alternative implementation of the Python language with both Python 2 and Python 3 compatible versions available.
Its main advantage over the standard Python implementation is that it can be faster and use less memory, but this depends on the context where and how it is used. If execution speed is important, at least testing PyPY is probably a good idea. After installation you probably still want to configure PATH to make PyPy itself as well as the robot and rebot runner scripts executable on the command line. To make using Robot Framework easier from the command prompt, it is recommended to add the locations where the runner scripts are installed into the PATH.
It is also often useful to have the interpreter itself in the PATH to make executing it easy. The first location is the installation directory of the interpreter e. Both Python and IronPython install scripts to Scripts directory under the installation directory on Windows e. Notice that the Scripts and bin directories may not be created as part of the interpreter installation, but only later when Robot Framework or some other third party module is installed. Notice that the exact setting names may be different on different Windows versions, but the basic approach should still be the same.
There are User variables and System variables, and the difference between them is that user variables affect only the current users, whereas system variables affect all users. Note that the semicolons ; are important as they separate the different entries.