if else в Robot Framework

Содержание
Введение
Пример
Пример с Run Keyword If
Похожие статьи

Введение

В этой статье вы можете изучить различные способы применения логических операторов в RobotFramework

Пример

Небольшой пример работы с настроенным фреймворком

*** Settings *** Documentation IF / ELSE IF / ELSE example using Robot Framework 3 and 4. ... Generate a random number. ... Do if-else logic based on the generated number. ... Stop (pass) when the condition is met. *** Variables *** ${MAX_TRIES}= ${50} ${NUMBER_TO_PASS_ON}= 7 *** Keywords *** Robot Framework 4: IF, ELSE IF, ELSE condition FOR ${i} IN RANGE ${MAX_TRIES} ${random}= Evaluate random.randint(0, 10) IF ${random} == ${NUMBER_TO_PASS_ON} Pass Execution "${random} == ${NUMBER_TO_PASS_ON}" ELSE IF ${random} > ${NUMBER_TO_PASS_ON} Log To Console Too high. ELSE Log To Console Too low. END END *** Keywords *** Robot Framework 3: Use IF, ELSE IF, ELSE condition FOR ${i} IN RANGE ${MAX_TRIES} ${random}= Evaluate random.randint(0, 10) ${is_expected}= Evaluate ${random} == ${NUMBER_TO_PASS_ON} Run Keyword Unless ... ${is_expected} ... Log To Console Condition not met. Run Keyword If ... ${is_expected} ... Pass Execution "${random} == ${NUMBER_TO_PASS_ON}" ... ELSE IF ... ${random} > ${NUMBER_TO_PASS_ON} ... Log To Console Too high. ... ELSE ... Log To Console Too low. END *** Tasks *** Use if - else if - else conditions in Robot Framework Robot Framework 4: Use IF, ELSE IF, ELSE condition Robot Framework 3: Use IF, ELSE IF, ELSE condition

Пример с Run Keyword If

В данном примере используется RFBrowser на основе Playwright

*** Settings *** Documentation Example that opens single page Library Browser ... enable_playwright_debug=${True} ... auto_closing_level=TEST ... retry_assertions_for=0:00:03 *** Variables *** ${url} https://eth1.ru *** Keywords *** Start Chromium Browser New Browser browser=chromium headless=False slowMo=1 New Context viewport={'width': 1920, 'height': 1080} ignoreHTTPSErrors=True *** Test Cases *** Starting a browser with a page Start Chromium Browser New Page https://eth1.ru ${sample_title} = Set Variable eth1.ru ${actual_title} = Get Title # With Run Keyword If Run Keyword If "${actual_title}" == "${sample_title}" Log To Console "1: Actual title is equal to sample title" # With IF IF "${actual_title}" == "${sample_title}" Log To Console "2: Actual title is equal to sample title" END IF "${actual_title}" != None Log To Console "3: Title exists" END IF "${actual_title}" != "heihei.ru" Log To Console "4: visited url is not heihei.ru" END Close Browser

robot if.robot

============================================================================== If :: Example that opens single page ============================================================================== Starting a browser with a page ...eth1.ru .."1: Actual title is equal to sample title" ."2: Actual title is equal to sample title" ."3: Title exists" ."4: visited url is not heihei.ru" Starting a browser with a page | PASS | ------------------------------------------------------------------------------ If :: Example that opens single page | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /home/andrei/python/robot/rfbrowser/output.xml Log: /home/andrei/python/robot/rfbrowser/log.html Report: /home/andrei/python/robot/rfbrowser/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
Banner image

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: