Строки в Robot Framework
Введение | |
Catenate: объединение строк | |
Перенос на новую строку | |
Похожие статьи |
Введение
Catenate: объединение строк
Соединить несколько переменных типа string можно с помощью Catenate
Пример: скрипт
caten.robot
*** Settings *** *** Test Cases *** Caten ${site}= Set Variable heihei ${proto}= Set Variable https ${url}= Catenate ${proto}://www.${site}.ru Log To Console \n${url}
robot caten.robot
============================================================================== Caten ============================================================================== Caten ... https://www.heihei.ru Caten | PASS | ------------------------------------------------------------------------------ Caten | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /opt/robot/src/tests/pam/rbac/output.xml Log: /opt/robot/src/tests/pam/rbac/log.html Report: /opt/robot/src/tests/pam/rbac/report.html
Перенос на новую строку в Robot Framework
Для переноса нужно в начале новой строки поставить три точки
Перенос в коде
Длинная строка
Run Keyword If ${major_version} == 20 or ${major_version} == 21 Log To Console Version 20 or 21
После переноса выглядит так
Run Keyword If ${major_version} == 20 or ${major_version} == 21 ... Log To Console Version 20 or 21
Перенос в выводе
Если нужно добавить переход на новую строку в выводе лога в консоль - нужно воспользоваться ${\n}
New line demo Log To Console ${\n}TEMPDIR : Log To Console ${TEMPDIR} Log To Console ${\n}ROOOT : Log To Console ${/}
TEMPDIR : .C:\Users\ANDREI~1\AppData\Local\Temp . ROOOT : .\
Dividing data to several rows
Выдержки из официальной документации
If there is more data than readily fits a row, it is possible to split it and start continuing rows with ellipsis (...).
Ellipses can be indented to match the indentation of the starting row and they must always be followed by the normal test data separator.
In most places split lines have exact same semantics as lines that are not split.
Exceptions to this rule are
suite
,
test
and
keyword
documentation as well
suite metadata
.
With them split values are automatically
joined together with the newline character
to ease creating multiline values.
The ... syntax allows also splitting variables in the
Variable section
. When long scalar variables (e.g. ${STRING}) are split to multiple rows, the final value is got by concatenating the rows together.
The separator is a space by default, but that can be changed by starting the value with SEPARATOR=
Splitting lines is illustrated in the following two examples containing exactly same data without and with splitting.
Пример без использования …
*** Settings *** Documentation Here we have documentation for this suite.\nDocumentation is often quite long.\n\nIt can also contain multiple paragraphs. Default Tags default tag 1 default tag 2 default tag 3 default tag 4 default tag 5 *** Variables *** ${STRING} This is a long string. It has multiple sentences. It does not have newlines. ${MULTILINE} This is a long multiline string.\nThis is the second line.\nThis is the third and the last line. @{LIST} this list is quite long and items in it can also be long &{DICT} first=This value is pretty long. second=This value is even longer. It has two sentences. *** Test Cases *** Example [Tags] you probably do not have this many tags in real life Do X first argument second argument third argument fourth argument fifth argument sixth argument ${var} = Get X first argument passed to this keyword is pretty long second argument passed to this keyword is long too
Гораздо лучше читаемый вариант с использованием …
*** Settings *** Documentation Here we have documentation for this suite. ... Documentation is often quite long. ... ... It can also contain multiple paragraphs. Default Tags default tag 1 default tag 2 default tag 3 ... default tag 4 default tag 5 *** Variables *** ${STRING} This is a long string. ... It has multiple sentences. ... It does not have newlines. ${MULTILINE} SEPARATOR=\n ... This is a long multiline string. ... This is the second line. ... This is the third and the last line. @{LIST} this list is quite long and ... items in it can also be long &{DICT} first=This value is pretty long. ... second=This value is even longer. It has two sentences. *** Test Cases *** Example [Tags] you probably do not have this many ... tags in real life Do X first argument second argument third argument ... fourth argument fifth argument sixth argument ${var} = Get X ... first argument passed to this keyword is pretty long ... second argument passed to this keyword is long too
Collections: списки, словари | |
Списки | |
Словари | |
Строки | |
Robot Framework |