Изменить значение переменной в Robot Framework

Содержание
Введение
Внутри одного ключа
Set Global Variable
Похожие статьи

Введение

В Robot Framework нельзя просто объявить переменную с помощью = прямо в коде теста, как это делается в Python

Внутри одного ключа

Переменную, объявленную ранее в *** Variables *** можно изменить с помощью Set Variable

Область видимости - внутри ключевого слова (только в том же Keyword)

*** Settings *** Documentation Working With Variables *** Variables *** ${x}= '7' *** Test Cases *** Verify That Variables Can Be Changed [Documentation] This test case verifies variable reassignment [Tags] Functional Start TestCase Verify Search Results Finish TestCase *** Keywords *** Start TestCase Log To Console Start Verify Search Results Log To Console Verify Log To Console ${x} ${x}= Set Variable '8' Log To Console ${x} Should Be Equal ${x} '8' Finish TestCase Log To Console Done

robot -d results var.robot

============================================================================== Var :: Working With Variables ============================================================================== Verify That Variables Can Be Changed :: This test case verifies va... Start .Verify '7' '8' .Done Verify That Variables Can Be Changed :: This test case verifies va... | PASS | ------------------------------------------------------------------------------ Var :: Working With Variables | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /home/andrei/robot/tests/var/results/output.xml Log: /home/andrei/robot/tests/var/results/log.html Report: /home/andrei/robot/tests/var/results/report.html

Set Global Variable

Чтобы изменённую переменную было видно в других ключах, можно использовать Set Global Variable

*** Settings *** Documentation Working With Variables *** Variables *** ${x}= '7' *** Test Cases *** Verify That Variables Can Be Changed [Documentation] This test case verifies variable reassignment [Tags] Functional Start TestCase Change RPM Version Verify RPM Version Finish TestCase *** Keywords *** Start TestCase Log To Console Start Change RPM Version Log To Console ${x} Set Global Variable ${x} '8' Log To Console ${x} Verify RPM Version Log To Console Verify Log To Console ${x} Should Be Equal ${x} '8' Finish TestCase Log To Console Done

robot variables.robot

============================================================================== Variables :: Working With Variables ============================================================================== Verify That Variables Can Be Changed :: This test case verifies va... Start .'7' '8' .Verify '8' .Done Verify That Variables Can Be Changed :: This test case verifies va... | PASS | ------------------------------------------------------------------------------ Variables :: Working With Variables | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /home/andrei/robot/tests/variables/output.xml Log: /home/andrei/robot/tests/variables/log.html Report: /home/andrei/robot/tests/variables/report.html

Article author: Andrei Olegovich

Похожие статьи
Robot Framework
Declare a variable
Change a variable value
Get Variable Value
Passing arguments to a keyword
Evaluate

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: