Словари в Robot Framework

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

Введение

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

Рассмотрим тест dict.robot

*** Variables *** &{url} hh=https://www.heihei.ru tb=https://www.topbicycle.ru uu=https://www.urn.su *** Test Cases *** Test1 Log To Console ${url.hh} Log To Console ${url.tb} Log To Console ${url.uu}

robot dict.robot

============================================================================== Dict ============================================================================== Test1 https://www.heihei.ru .https://www.topbicycle.ru .https://www.urn.su Test1 | PASS | ------------------------------------------------------------------------------ Dict | 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

Ключ можно записать в переменную

*** Variables *** ${site} tb &{url} hh=https://www.heihei.ru tb=https://www.topbicycle.ru uu=https://www.urn.su *** Test Cases *** Test1 Log To Console ${url.hh} Log To Console ${url.tb} Log To Console ${url.uu} Test2 Log To Console ${url.${site}}

robot dict.robot

============================================================================== Dict ============================================================================== Test1 https://www.heihei.ru .https://www.topbicycle.ru .https://www.urn.su Test1 | PASS | ------------------------------------------------------------------------------ Test2 https://www.topbicycle.ru Test2 | PASS | ------------------------------------------------------------------------------ Dict | PASS | 2 tests, 2 passed, 0 failed ============================================================================== Output: /home/andrei/robot/output.xml Log: /home/andrei/robot/log.html Report: /home/andrei/robot/report.html

При таком задании ключа можно указать нужный сайт во время вызова теста из терминала

robot -v site:uu dict.robot

============================================================================== Dict ============================================================================== Test1 https://www.heihei.ru .https://www.topbicycle.ru .https://www.urn.su Test1 | PASS | ------------------------------------------------------------------------------ Test2 https://www.urn.su Test2 | PASS | ------------------------------------------------------------------------------ Dict | PASS | 2 tests, 2 passed, 0 failed ============================================================================== Output: /home/andrei/robot/output.xml Log: /home/andrei/robot/log.html Report: /home/andrei/robot/report.html

DotDict

Объект, который создаётся роботом как словарь имеет тип DotDict

Об этом важно помнить, если вы передаёте его дальше в Python

Convert To Dictionary

Чтобы передалать DotDict его в обычный словарь нужно использовать ключевое слово Convert To Dictionary

&{dict} topic=qa lang=python frame=robot ${python_dict}= Convert To Dictionary ${dict}

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: