【问题标题】:executing "else" value in RobotFrameWork在 RobotFrameWork 中执行“else”值
【发布时间】: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 ifrun keyword unless 内置关键字,但不知道如何在这里使用,在这种特殊情况下。

PS:如果这是True-False 组合,我会编写一个简单的脚本,但这是主要问题,我还有其他组合......比如Valid-InvalidYes-NoIs-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


    【解决方案1】:

    我通过创建自己的关键字来做到这一点。

    Select Radio Button Otherwise    CSS_ID   True
    

    这将选择除True之外的所有单选按钮。

    这是我的最终代码

    Run My Test
        Select Radio Button    CSS_ID   True
        Correct window should popup 
        Select Radio Button Otherwise    CSS_ID   True  
        InCorrect window should popup
    

    【讨论】:

      【解决方案2】:

      检查文档中的 Run Keyword IfRun Keyword Unless 关键字。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-18
        • 2018-02-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多