Store Generate Random String as a Variable

Skip to first unread message

Almost Two

Sep 30, 2014, 2:30:42 PM9/30/14

I'm using Robot Framework with Selenium2Library and i can't figure out how to implement the Generate Random String in order to fill a field in a webform.

Thanks for your support.

Bryan Oakley

Sep 30, 2014, 2:50:41 PM9/30/14
to, robotframework-users
What don't you understand? The documentation includes working examples.

Here's a complete example; save it to a file and run it with robot to see the strings that are generated:

*** Settings ***
| Library | String

*** Test Cases ***
| Examples of generating random strings
| | ${ret} = | Generate Random String |    | 
| | ${low} = | Generate Random String | 12 | [LOWER]
| | ${bin} = | Generate Random String | 8  | 01
| | ${hex} = | Generate Random String | 4  | [NUMBERS]abcdef
| | 
| | Log to console | ret = '${ret}'
| | Log to console | low = '${low}'
| | Log to console | bin = '${bin}'
| | Log to console | hex = '${hex}'

You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Bryan Oakley

Sep 30, 2014, 5:22:52 PM9/30/14
to Miguel Guardado, robotframework-users
I don't understand what part you don't understand. Did you try the following?

    ${loan-number}=   Generate Random String   12   [LOWER]
    Input Text    j_id0:j_id3:j_id30:j_id61:loanNumber    ${loan-number}  

I don't know what format you want the random string to be in, so the above just gives you 12 random lowercase letters.

On Tue, Sep 30, 2014 at 3:44 PM, Miguel Guardado <> wrote:
Hi Bryan,

Thanks for your time.

This is the example of my Robot Framework code:

*** Settings ***
Documentation     Test suite created with FireRobot.
Library           Selenium2Library    15.0    5.0
Library           String

*** Variables ***
${BROWSER}        FireFox
${password}       currentpassword
${new-foreignkeyinputelementj_id0j_id3j_id30j_id35clientfield_uic}    Test Account
${street-address}    659 Tornhll Lane
${city}           Garland
${zip-code}       75040
${county}         Dallas
${borrower-1-first-name}    TEST
${borrower-1-last-name}    USER

*** Test Cases ***
Valid Login
    Open Browser    ${BROWSER}
    Input Text    username    ${user-name}
    Input Password    password    ${password}
    Click Button    Login

Create Order
    Wait Until Page Contains    Orders
    Click Link    Orders
    Click Button    new
    Input Text    j_id0:j_id3:j_id30:j_id35:clientField    ${new-foreignkeyinputelementj_id0j_id3j_id30j_id35clientfield_uic}
    Input Text    j_id0:j_id3:j_id30:j_id35:address    ${street-address}
    Input Text    j_id0:j_id3:j_id30:j_id35:city    ${city}
    Input Text    j_id0:j_id3:j_id30:j_id35:zip    ${zip-code}
    Select From List By Label    j_id0:j_id3:j_id30:j_id35:state    TX
    Input Text    j_id0:j_id3:j_id30:j_id35:county    ${county}
    Select From List By Label    j_id0:j_id3:j_id30:j_id35:ocupancyType    --None--
    Select From List By Label    j_id0:j_id3:j_id30:j_id35:addressType    --None--
    Select From List By Label    j_id0:j_id3:j_id30:j_id35:buildingStatus    --None--
    Select From List By Label    j_id0:j_id3:j_id30:j_id35:propertyType    --None--
    Select From List By Label    j_id0:j_id3:j_id30:j_id43:product    TestProduct
    Select From List By Label    j_id0:j_id3:j_id30:j_id61:loanPurpose    --None--
    Select From List By Label    j_id0:j_id3:j_id30:j_id61:loanType    --None--
    Input Text    j_id0:j_id3:j_id30:j_id61:loanNumber    ${loan-number}  // This is the field i want to generate a random string
    Select Radio Button    reuseLender    1
    Input Text    j_id0:j_id3:j_id30:j_id81:j_id82    ${borrower-1-first-name}
    Input Text    j_id0:j_id3:j_id30:j_id81:j_id84    ${borrower-1-last-name}
    Select Checkbox    j_id0:j_id3:j_id30:j_id141:automaticClientNotification
    Input Text    j_id0:j_id3:j_id30:j_id141:clientEmail    ${client-default-email}
    Click Button    j_id0:j_id3:j_id30:j_id31:bottom:j_id32

Place Order
    Click Button    place_order
    Confirm Action
    Wait Until Element Is Visible    xpath=(.//div[contains(normalize-space(.), 'New')])[12]


Maybe im wrong in the way I try to code my test.

Thanks again.


Oct 1, 2014, 11:51:36 AM10/1/14
As an alternative I can propose: 
Reply all
Reply to author
0 new messages