Data Driver Robot Framework

Введение

Библиотека DataDriver — это расширение для Robot Framework.

DataDriver создает новые тест кейсы на основе файла с данными. Можно использовать .csv, .xls или .xlsx файлы.

Документация

Официальная документация

Установка

python -m pip install robotframework-datadriver

Пример

Разберём пример с официальной страницы.

Нам предлагается следующий код

*** Settings *** Library DataDriver Test Template Login With User And Password *** Test Cases *** Login with user ${username} and password ${password} Default UserData *** Keywords *** Login With User And Password [Arguments] ${username} ${password} Log Many ${username} ${password}

И содержимое для .csv файла.

*** Test Cases ***;${username};${password};[Tags];[Documentation] Right user empty pass;demo;${EMPTY};1;This is a test case documentation of the first one. Right user wrong pass;demo;FooBar;2,3,foo;This test case has the Tags 2,3 and foo ;${EMPTY};mode;1,2,3,4;This test case has a generated name based on template name. ;${EMPTY};${EMPTY};; ;${EMPTY};FooBar;; ;FooBar;mode;foo,1; ;FooBar;${EMPTY};foo; ;FooBar;FooBar;foo,2;

Авторы забыли написать, что для запуска в таком виде .csv файл нужно назвать так же как и .robot файл.

Назовём файлы datadriver_demo.robot и datadriver_demo.csv

robot_data_driver_demo/ ├── datadriver_demo.csv └── datadriver_demo.robot

Также ничего не сказано про аргументы Default и UserData.

Их можно просто удалить

*** Settings *** Library DataDriver Test Template Login With User And Password *** Test Cases *** Login with user ${username} and password ${password} *** Keywords *** Login With User And Password [Arguments] ${username} ${password} Log Many ${username} ${password}

Из директории robot_data_driver_demo выполним

python -m robot .\datadriver_demo.robot

============================================================================== Datadriver Demo ============================================================================== Right user empty pass :: This is a test case documentation of the ... | PASS | ------------------------------------------------------------------------------ Right user wrong pass :: This test case has the Tags 2,3 and foo | PASS | ------------------------------------------------------------------------------ Login with user and password mode :: This test case has a generat... | PASS | ------------------------------------------------------------------------------ Login with user and password | PASS | ------------------------------------------------------------------------------ Login with user and password FooBar | PASS | ------------------------------------------------------------------------------ Login with user FooBar and password mode | PASS | ------------------------------------------------------------------------------ Login with user FooBar and password | PASS | ------------------------------------------------------------------------------ Login with user FooBar and password FooBar | PASS | ------------------------------------------------------------------------------ Datadriver Demo | PASS | 8 tests, 8 passed, 0 failed ==============================================================================

Название тест кейса

Следующий интересный момент - название тест кейса. Если его заменить например на Some Test, все тесты по-прежнему будут выполняться.

Единственной разницей будет появление предупреждения об идентичных названиях тестов.

*** Settings *** Library DataDriver Test Template Login With User And Password *** Test Cases *** Some Test *** Keywords *** Login With User And Password [Arguments] ${username} ${password} Log Many ${username} ${password}

python -m robot .\datadriver_demo.robot

============================================================================== Datadriver Demo ============================================================================== Right user empty pass :: This is a test case documentation of the ... | PASS | ------------------------------------------------------------------------------ Right user wrong pass :: This test case has the Tags 2,3 and foo | PASS | ------------------------------------------------------------------------------ Some Test :: This test case has a generated name based on template... | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ Datadriver Demo | PASS | 8 tests, 8 passed, 0 failed ==============================================================================

Из логов видно, что название тест кейса из .csv файла имеет приоритет над базовым названием в .robot файл.

Banner image

Article author: Andrei Olegovich

Похожие статьи
Operating System
RequestsLibrary
XML
Libraries
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: