【发布时间】:2023-03-26 08:30:01
【问题描述】:
我有一个变量 ${var} 它有一个值(“真”或“假”)
我有一个测试用例(由 4 个步骤组成)
Run My Test
Select Radio Button CSS_ID ${var} #right now here value of ${var} is 'True'
Correct window should popup
Select Radio Button CSS_ID False #Here I've to manually write 'False' which I dont want to do
#Instead of writing False I want to execute this keyword 'Select Radio Button' on any value other than 'True'
#Like we have in traditional Programming language, 'not ${var}' or '!${var}' or similar thing
InCorrect window should popup
反之亦然
Run My Test
Select Radio Button CSS_ID False
Correct window should popup
Select Radio Button CSS_ID "ELSE" #True #here "ELSE" means anything else which is not "False"
InCorrect window should popup
我知道 run keyword if 和 run keyword unless 内置关键字,但不知道如何在这里使用,在这种特殊情况下。
PS:如果这是True-False 组合,我会编写一个简单的脚本,但这是主要问题,我还有其他组合......比如Valid-Invalid、Yes-No、Is-a - Has-a 等。
到目前为止我已经尝试过。 . .
我创建了自己的关键字SelectRadioBtn
from Selenium2Library import Selenium2Library
class test(Selenium2Library):
def SelectRadioBtn(self, group_name, value):
elements = self._get_radio_buttons(group_name) #here I find all radio buttons with given ID
for element in elements:
val = element.get_attribute('value') #and then check if value of current element doesn't match with given value thats mean it's counter value we are looking for
if val != value:
break
element = self. _get_radio_button_with_value(group_name, val) #and then use above found counter value to select radio button
if not element.is_selected():
element.click()
然后把它当作
Run My Test
Select Radio Button CSS_ID False
Correct window should popup
SelectRadioBtn CSS_ID False #"True"
InCorrect window should popup
但它不起作用:(
【问题讨论】:
标签: python python-2.7 selenium selenium-webdriver robotframework