rkevx21
rkevx21

Reputation: 3949

Robot Framework : Random Selection of Drop downs

I need some help, I want to create a test that will randomly get the value during test case since in my case I declared it in my code, how can I make this randomly?

Heres my code

html

<select name="gender">
    <option>Please Select</option>
    <option value='Male'>Male</option>
    <option value='Female'>Female</option>
</select> 

robot

*** Test Cases ***
Select From List By Value    xpath://select[@name='gender']    Male

Upvotes: 0

Views: 1836

Answers (1)

Sameem
Sameem

Reputation: 849

You can use the 'Random Element' from the Faker Library. Random Element returns a random item from the list of items provided.

*** Settings *** 
Library    FakerLibrary

*** Test Cases ***
Randomise gender selection
    ${gender}    Select random gender    
    Select from list by value   xpath://select[@name='gender']    ${gender}   

*** Keywords ***
Select random gender
    ${randomValue}    Random Element    ['Male', 'Female']

    [Return]    ${randomValue}

This will randomise gender selection in the test case. In case you want to add more items to your list, you can add it in the list argument following the Random Element keyword.

Note: Make sure to install and import the FakerLibrary

Upvotes: 2

Related Questions