問題描述
我需要在機(jī)器人框架中有條件地執(zhí)行一些關(guān)鍵字,但我不知道該怎么做,它不起作用.我嘗試了很多選項(xiàng),但我想我的IF-ELSE"語句完全錯(cuò)誤..
I need to execute some keywords conditionally in robot framework, but I dont know how to do it, it does not work. I tried many options, but I guess I have the "IF-ELSE" statement completely wrong..
Choose Particular Filter ${FILTER} And Uncheck All Values
${bool}= is filter opened ${AVAILABLE FILTERS} ${FILTER}
${uncheck_all_button}= run keyword if "${bool}" == "True" uncheck all in filter ${AVAILABLE FILTERS} ${FILTER}
... click element ${uncheck_all_button}
... ELSE
... Set variable ${particular_filter}: find particular filter ${AVAILABLE FILTERS} ${FILTER}
... click element ${particular_filter}
... Set variable ${uncheck_all_button}: uncheck all in filter ${AVAILABLE FILTERS} ${FILTER}
... click element ${uncheck_all_button}
它失敗了:Variable '${particular_filter}' not found.
但是如果我運(yùn)行它,它甚至不應(yīng)該去 ELSE 分支,因?yàn)?${bool} 是 True...我的自定義函數(shù) is filter opens
只是檢查過濾器是否已經(jīng)打開 - 如果是,則返回 True.我的自定義函數(shù) uncheck all in filter
只返回uncheck all"按鈕的 XPATH.我的自定義函數(shù) find specific filter
返回filter dropdown"按鈕的 XPATH.在這整個(gè)關(guān)鍵字中,我需要檢查過濾器下拉菜單是否已經(jīng)打開 - 如果是,那么我必須直接點(diǎn)擊 ${uncheck_all_button}
,否則如果過濾器下拉菜單尚未打開,我需要首先點(diǎn)擊過濾器本身 ${particular_filter}
然后我可以點(diǎn)擊 ${uncheck_all_button}
It fails with: Variable '${particular_filter}' not found.
But in case I run it it should not even go to ELSE branch because ${bool} is True...
My custom function is filter opened
just checks whether filter is already opened - if so, returns True.
My custom function uncheck all in filter
just returns XPATH of "uncheck all" button.
My custom function find particular filter
returns XPATH of "filter dropdown" button.
In this whole keyword I need to check whether the filter dropdown is already opened - if so, then I have to click directly on ${uncheck_all_button}
, else if the filter dropdown is not opened yet, I need to first click on the filter itself ${particular_filter}
and after that I can click on ${uncheck_all_button}
我還嘗試了運(yùn)行關(guān)鍵字"這一行:
I also tried the "run keyword" line to have like this:
${uncheck_all_button}= run keyword if "${bool}" == "True" Set Variable uncheck all in filter ${AVAILABLE FILTERS} ${FILTER}
或者這個(gè):
run keyword if "${bool}" == "True" ${uncheck_all_button}= uncheck all in filter ${AVAILABLE FILTERS} ${FILTER}
我也試過 ${bool} == "True"
和 ${bool} == True
但沒有什么真正起作用,仍然是同樣的錯(cuò)誤:(
But nothing really works, still the same error :(
非常感謝您的幫助!
推薦答案
在每個(gè)塊中使用帶有多個(gè)語句的 IF/THEN/ELSE 在 Robot 中不起作用(或者我想您將不得不使用運(yùn)行關(guān)鍵字",但是將變得不可讀).所以我會(huì)用這種方式重構(gòu)你的代碼:
Having IF/THEN/ELSE with multiple statements in each block does not work in Robot (or you would have to use "Run Keywords" I suppose, but that would become unreadable). So I would refactor your code this way:
Choose Particular Filter ${FILTER} And Uncheck All Values
${is_filter_opened}= is filter opened ${AVAILABLE FILTERS} ${FILTER}
run keyword if ${is_filter_opened} actions_when_unchecked
... ELSE actions_when_checked
actions_when_unchecked
uncheck all in filter ${AVAILABLE FILTERS} ${FILTER}
click element ${uncheck_all_button}
actions_when_checked
${particular_filter}: find particular filter ${AVAILABLE FILTERS} ${FILTER}
click element ${particular_filter}
${uncheck_all_button}: uncheck all in filter ${AVAILABLE FILTERS} ${FILTER}
click element ${uncheck_all_button}
希望這會(huì)有所幫助.
這篇關(guān)于帶有變量分配的機(jī)器人框架中的 IF ELSE的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!