Списки в Robot Framework

Содержание
Введение
Проверка на принадлежность к списку
Пример
Похожие статьи

Введение

Создать список можно с помощью @

*** Settings *** Documentation Creating List *** Variables *** @{versions}= 18 19 20 21

Часто бывает нужно определить принадлежит ли элемент к списку или нет

С помощью in можно проверить входит ли такой объект в список или нет.

Такой оператор присутствует в Python и других языках программирования.

in отделяется отступами в один пробел

$var in $list

Проверка на принадлежность к списку

Рассмотрим тест list.robot сделаем простую проверку принадлежит ли наша версия PostreSQL списку разрешённых или нет. Тест падать не будет.

** Variables *** ${PG_VERSION} 11 @{versions}= 11 13 *** Test Cases *** Test1 Log To Console ${PG_VERSION} Log To Console ${versions} IF "${PG_VERSION}" in ${versions} Log To Console "IN" ELSE Log To Console "NOT IN" END

robot list.robot

============================================================================== List ============================================================================== Test1 11 .['11', '13'] ."IN" Test1 | PASS | ------------------------------------------------------------------------------ List | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /home/andrei/robot/output.xml Log: /home/andrei/robot/log.html Report: /home/andrei/robot/report.html

Если ELSE вам не нужен его можно убрать или воспользоваться ключевым словом Run Keyword If

Test2 Run Keyword If "${PG_VERSION}" in ${versions} Log To Console Version ${PG_VERSION} is OK

Test2 Version 11 is OK Test2 | PASS |

Banner image

Пример

Рассмотрим тест in.robot сделаем не просто проверку, а обязательное условие чтобы версия была из списка разрешённых.

Теперь нужно, чтобы тест падал при посторонней версии.

*** Settings *** Documentation Testing in operator *** Variables *** @{versions}= 18 19 20 21 ${current_version}= 21 *** Keywords *** Start TestCase Log To Console "Starting Test Case" Compare Versions Log To Console ${current_version} Should Be True $current_version in $versions Finish TestCase Log To Console "Finishing Test Case" *** Test Cases *** Verify that in is working [Documentation] This test case verifies that "in" can be used [Tags] Functional Start TestCase Compare Versions Finish TestCase

robot in.robot

============================================================================== Example :: Testing in operator ============================================================================== Verify that in is working :: This test case verifies that "in" can... "Starting Test Case" .21 ."Finishing Test Case" Verify that in is working :: This test case verifies that "in" can... | PASS | ------------------------------------------------------------------------------ Example :: Testing in operator | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /home/andrei/tests/Example/output.xml Log: /home/andrei/tests/Example/log.html Report: /home/andrei/tests/Example/report.html

Article author: Andrei Olegovich

Похожие статьи
Collections: списки, словари
Списки
Словари
Robot Framework

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: