Question

I have a variable ${var} and it has a value (either 'true' or 'false')

and i have a test case (consists of 4 steps)

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 

OR Vice-Versa

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

I Know run keyword if and run keyword unless inbuilt keywords but having no clue how to use here,in this particular situation.

PS: If this be True-False combination I would've written a simple script, but thats the main problem, I have other combo also ....like Valid-Invalid, Yes-No, Is-a - Has-a etc.

What I've tried so far . . . I created my own keyword 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()

and then used it as

Run My Test
        Select Radio Button    CSS_ID   False
        Correct window should popup 
        SelectRadioBtn    CSS_ID   False  #"True"
        InCorrect window should popup

But it's not working :(

Was it helpful?

Solution

Check Run Keyword If and Run Keyword Unless keywords from the documentation.

OTHER TIPS

I did it by creating my own keyword.

Select Radio Button Otherwise    CSS_ID   True

This will select all radio buttons with value other than True.

This is my final code

Run My Test
    Select Radio Button    CSS_ID   True
    Correct window should popup 
    Select Radio Button Otherwise    CSS_ID   True  
    InCorrect window should popup
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top