Create Unique string in robot framework - robotframework

I want to create a unique string in robot framework each time I run my script.
*** Settings***
Library Selenium2Library
Library String
*** Variables ***
${RANUSER} Generate Random String 10 [LETTERS]
*** Test Cases ***
Enter Random Username
Input Text //input[#id='userInput'] ${RANUSER}
Using this, I always get Generate Random String 10 [LETTERS] as my output but I want unique output all the time. Can anyone please help me.
TY

Generate Random String is a keyword. So you need to call it as a keyword. E.g. like this:
*** Test Cases ***
Enter Random Username
${RANUSER} Generate Random String 10 [LETTERS]
Input Text //input[#id='userInput'] ${RANUSER}
Or by the custom keyword:
*** Keywords ***
Create Random User
${RANUSER} Generate Random String 10 [LETTERS]
[Return] ${RANUSER}

Related

How to generate random string only on certain time through excel file?

#I need to generate random test strings for pass case and for fail case I need to give manual vale through excel file
#I have tried:
#Give input to new bill cycle
[Arguments] ${CYCLE_NAME}
${ret}= Generate Random String 12
input text ${XPATH_TO_CYCLE_NAME_TEXTBOX} ${CYCLE_NAME}
#and when I give ${ret} on my excel file it says variable not found error.
#thank all for you support i got the answer
*** Settings ***
Suite Setup Initialize Random Variables
*** Keywords ***
Initialize Random Variables
${RANDOM_STRING}= Generate random string 15
Set global variable ${RANDOM_CYCLE_NAME}
#Then i was able to call ${RANDOM_STRING} through my excel when ever i want random string

Input Random Value In Search Box In ROBOT FRAMEWORK

I'm able to select a random value from a list but I'm not able to enter that value in the search box. The thing is input text requires two arguments i.e the locator & the value. I'm stuck with the value part now
*** Variables ***
#{cin} U74999KA2016PTC096782 U22012CH1993PTC012939 U65999MH2016PTC287488
*** Test Cases ***
Search
input text ${SEARCH_BAR}
${value} Evaluate random.choice($cin) random
log to console \nvalue: ${value}
click element ${SEARCH_BUTTON}
You are trying to generate a random value after you try to input blank text into the box
Change your code to
*** Variables ***
#{cin} U74999KA2016PTC096782 U22012CH1993PTC012939 U65999MH2016PTC287488
*** Test Cases ***
Search
${value} = Evaluate random.choice($cin) random
input text ${SEARCH_BAR} ${value}
log to console \nvalue: ${value}
click element ${SEARCH_BUTTON}

Generate Random string is not recognised as keyword in robot framework

I tried
random stuff
${commentText} = Generate Random String 100 [LETTERS]
The user enters text to a text field id=textId ${commentText}
I have placed Library String at the suite level too but when ran the test, it says no keyword with name ${commentText} = Generate Random String 100 [LETTERS] found
it says no keyword with name ${commentText} = Generate Random String 100 [LETTERS] found
Take a close look at the error message. I'll add emphasis to make it more clear:
no keyword with name ${commentText} = Generate Random String 100 [LETTERS] found
In other words, it's not complaining about a keyword named Generate Random String, it's complaining about a keyword named ${commentText} = Generate Random String 100 [LETTERS]
This happens when you don't separate the individual parts of the statement with two or more spaces, causing robot to think the entire line is the name of the keyword.
The correct syntax is this:
${commentText}= Generate Random String 100 [LETTERS]
Notice that there are two spaces between ${commentText}, Generate Random String, 100, and [LETTERS]
Could you place exactly the same code that you use? I would say that you are not using proper delimiter, like 4 spaces:
${commentText} = Generate Random String 100 [LETTERS]

Creating a unique string value from keyword and using it for Input Text keyword

I am trying to create a unique string by embedding epoch time stamp after a static string as:
*** Keywords ***
Unique Title
[Return] ${title}
${secs}= Get Time epoch
${time}= Convert To String ${secs}
{title}= Catenate SEPRATOR=- Title ${time}
*** Test Cases ***
Test_Enter_Unique_Text
Open Browser #{urlUnderTest}
Input Text name=alertTitle Unique Title
Its not working I am not able to get the return value of Unique Title keyword, in the input box text is getting entered as "Unique Title".
Any suggestions will be really helpful.
You have to call the keyword and save what it returns, then use the saved value in the test case:
*** Test Cases ***
Test_Enter_Unique_Test
${title}= Unique Title
...
Input Text name=alertTitle ${title}

Create and use a random string in Robot

I want to create a random string, assign it to a variable and enter that variable into a text box. How can I do this?
Don't know how to use SELENIUM.SETTEXT with the assigned variable. I've done the following so far:
${RANUSER} = Generate Random String 6 [LETTERS]
Have you imported the correct libraries :
*** Settings***
Library Selenium2Library
Library String
*** Variables ***
${RANUSER} Generate Random String 10 [LETTERS]
*** Test Cases ***
Enter Random Username
Input Text //input[#id='userInput'] ${RANUSER}

Resources