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

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

Введение

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

Переменную, объявленную ранее в *** 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/robotframework/tests/var/results/output.xml Log: /home/andrei/robotframework/tests/var/results/log.html Report: /home/andrei/robotframework/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/test/robotframework/tests/variables/output.xml Log: /home/andrei/test/robotframework/tests/variables/log.html Report: /home/andrei/test/robotframework/tests/variables/report.html

Article author: Andrei Olegovich

Похожие статьи
Robot Framework
Basics
RFBrowser
Set Variable
if else: conditionals
in: check if smth belongs to list
Loops
Change Variable Value
New Line
[Tags]
Collections: lists, dicts
JSON
Pass Argument to a Keyword
Evaluate
Robot in PyCharm
Список открытых API

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: