install robotframework |
-
To also generate a Surefire report
#> robot -x foo.xml .
#> robot --xunit foo.xml .
-
Declaring test setup and teardown in the settings
*** Settings ***
Test Setup Log To Console test startup
Test Teardown Log To Console test shutdown -
Retrieve the value of an environment variable:
%{ENV_VAR_NAME}
Using the OperatingSystem library:Get Environment Variable ENV_VAR_NAME
In botch cases, it is possible to define a default value:%{ENV_VAR_NAME=default_value}
andGet Environment Variable ENV_VAR_NAME default_value
-
Sleep for 42 seconds
Sleep 42
-
Loop on a list
${root} = Parse XML ${CURDIR}${/}surefire_report.xml
@{failure_elements} = Get Elements ${root} .//testcase/*[.!='grep']
${f} = Set Variable ${EMPTY}
FOR ${failure} IN @{failure_elements}
${f} = Catenate SEPARATOR=\n ${f} \ntype: ${failure.tag}\ndetails: ${failure.text}
END -
Get length of a list
${root} = Parse XML ${CURDIR}${/}surefire_report.xml
@{skipped_elements} = Get Elements ${root} .//testcase/*[.='grep']
@{all_elements} = Get Elements ${root} .//testcase
${skipped_count} = Get length ${skipped_elements}
${total_count} = Get length ${all_elements}
Should Not Be Equal As Integers ${skipped_count} ${total_count} All tests have been skipped -
Running a test in an other technology and parsing the Surefire report
*** Settings ***
Documentation Running an Intern test from Robot Framework
Library Process
Library XML
*** Test Cases ***
Run Intern Test
Run Process npm.cmd test
@{elements} = Get Elements truc.xml .//failure
${f} = Set Variable Errors:
FOR ${failure} IN @{elements}
${f} = Catenate SEPARATOR=\n ${f} ${failure.text}
END
Should be empty ${elements} An error has been found\n${f} -
Converting a test into json
-
test sample (
test.robot
):*** Settings ***
Library DateTime
*** Test Cases ***
Simple Test Case
[Documentation] Shows some assertion keywords
Should Be Equal Text123 Text123
Should Be True 5 + 5 == 10
Test for the year 2022
[Documentation] Tests if it is still 2022...
${date}= Get Current Date result_format=datetime
Log ${date}
Should Be Equal As Strings ${date.year} 2022 -
Python script to perform the conversion (
convert.py
):from robot.running import TestSuite
import sys
suite = TestSuite.from_file_system(sys.argv[1])
suite.to_json(sys.argv[2]) -
convert the file
#> python3 convert.py test.robot test.rbt
-
run the test
#> robot test.rbt
-
test sample (
-
Setting tags
-
Test Tags
in theSetting
section.
All tests in a test case file with this setting always get specified tags. -
[Tags]
with each test case.
Tests get these tags in addition to tags specified using the Test Tags setting.
It is possible to use a variable in a tag definition:[Tags] host: ${HOST}
. -
--settag
command line option.
All tests get tags set with this option in addition to tags they got elsewhere. -
Set Tags
keyword.
Adds given tags for the current test or all tests in a suite. -
Set Tags
keyword.
Adds given tags for the current test or all tests in a suite. -
Remove Tags
keyword.
Removes given tags from the current test or all tests in a suite. Glob patterns can be used. -
Fail
,Pass Execution
, andPass Execution If
keywords allow adding and removing tags at the end of a test execution. -
Force Tags
in theSetting
section. Do not use, it is deprecated.
All tests unconditionally get these tags. This is exactly the same as Test Tags nowadays. -
Default Tags
in theSetting
section. Do not use, it is deprecated.
All tests get these tags by default. If a test has[Tags]
, it will not get these tags.
-
-
Selecting tests to run
-
If the
--include
(or-i
) option is used, only test cases having a matching tag are selected, and with the--exclude
(or-e
) option test cases having a matching tag are not. If both are used, only tests with a tag matching the former option, and not with a tag matching the latter. -
Both
--include
and--exclude
can be used several times to match multiple tags. In that case a test is selected if it has a tag that matches any included tags, and also has no tag that matches any excluded tags. -
In addition to specifying a tag to match fully, it is possible to use tag patterns where
*
and?
are wildcards andAND
,&
,OR
, andNOT
operators can be used for combining individual tags or patterns together. - Tag matching itself is case-insensitive.
-
If the
-
Install SeleniumLibrary
pip install robotframework-seleniumlibrary
pip install webdrivermanager
webdrivermanager firefox chrome --linkpath /c/Users/lmazure/bin -
Example of Selenium script
*** Settings ***
Documentation An example to discover Robot Framework
...
... Some smoke test of my homepage
Library SeleniumLibrary
*** Keywords ***
Click Map Link Node
[Arguments] ${linkText}
Click Link xpath://A[text()='${linkText}']/following-sibling::A[1]
Click Map Text Node
[Arguments] ${nodeText}
Click Link xpath://SPAN[contains(text(),'${nodeText}')]/A
*** Test Cases ***
Redirection
Open Browser https://mazure.fr
Wait Until Location Is https://mazure.fr/perso/main.html
[Teardown] Close Browser
Access to site map
Open Browser https://mazure.fr/perso/main.html
Click Link id:goToMap
Title Should Be Site map
[Teardown] Close Browser
Open and close site map nodes
Open Browser https://mazure.fr/content/map.html
Wait Until Page Contains Homepage
Element Should Not Be Visible link:Mathematicians
Click Map Link Node Homepage
Element Should Not Be Visible link:Mathematicians
#Click Link id:toggleDiv1
Click Map Text Node Links / articles
Element Should Not Be Visible link:Mathematicians
Click Map Link Node Encyclopedia
Element Should Not Be Visible link:Mathematicians
Click Map Link Node Mathematics
Element Should Be Visible link:Mathematicians
Click Map Link Node Encyclopedia
Element Should Not Be Visible link:Mathematicians
[Teardown] Close Browser -
Saving the HTML source in a Selenium script
Library OperatingSystem
…
${source} = Get Source
OperatingSystem.Create File ${EXECDIR}/map_source.html ${source}
-
to change the Browser language
New Context locale=en-US
does not work
New Browser chromium headless=false args=['--lang=en']
works for Chrome
-
To install allure, run the following command:
pip install allure-robotframework
-
To run tests with allure, use the following command:
robot --listener "allure_robotframework;fubar" case.robot
UUID-result.json
files.
Allure’s attachment done withAttach "I attach kuux"
, are saved inUUID-attachment.attach
files.
Variable setting, such as${snake} = Set Variable python
, are saved inUUID-attachment.html
files, but special characters are not escaped!
Errors, such as using a non-existent keyword, are saved inUUID-attachment.html
files. -
To generate and display the Allure report, use the following command:
allure serve fubar
-
create the HTML doc of a resource/robot file
python -m robot.libdoc -f html ./resources/page_objects/site/generic_page_object.resource report.html
libdoc -f html ./resources/page_objects/site/generic_page_object.resource report.html