#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
Related
I want to create csv file which contains:
Header1,Header2,Header3
Value1,Value2,Value3
Value11,Value22,Value33
I also want to dynamically generate the values and append to the file; How can this be achieved in robotframework?
You could do this with a number of helper keywords, although it's not clear exactly what you need but you can create a number of header values dynamically by appending to a list based on a specified number of columns as well as two other keywords where the first creates a list of random values based on the header count and another that appends that list of values to a list which would effectively be your row. You can have that also in a for loop which calls the keyword to generate the row values until reaching the specified number of rows.
You can probably do without the csv library if you just convert the list of headers/rows to a comma seperated string and then use standard Append to File keyword to append this string.
So in summary, you could define keywords like the following:
Generate Header
Generate Set of Random Rows
Generate Random Row of Values
Convert List to Comma Seperated String
Generate CSV File
You will also need:
The test case itself which calls some of the keywords (Generate Header, Generate Set of Random Rows and Generate CSV File)
In Variable section a defined header count and row count
Libraries (String, Collections and OperatingSystem)
*** Settings ***
Library String
Library Collections
Library OperatingSystem
*** Variables ***
${header_count} 5 # Change this for a different number of headers
${row_count} 20 # Change this for a different number of rows
*** Test Cases ***
Scenario: Create CSV With Random Data
${header} Generate Header ${header_count}
${data} Generate Set of Random Rows ${header_count} ${row_count}
Generate CSV File ${header} ${data}
*** Keywords ***
Generate Header
[Documentation] Generate a number of headers, stored in a list with prefix "Header" and Suffixed with the current index of the iteration
[Arguments] ${header_count}
#{header_list} Create List
FOR ${header_num} IN RANGE 1 ${header_count}+1
Append To List ${header_list} Header${header_num}
END
[Return] ${header_list}
Generate Set of Random Rows
[Documentation] Takes the header count and row count which is used to create a list of lists containing randomly generated strings
[Arguments] ${header_count} ${row_count}
#{random_row_list} Create List
FOR ${row} IN RANGE 0 ${row_count}
${values} Generate Random Row Of Values ${header_count}
Append To List ${random_row_list} ${values}
END
[Return] ${random_row_list}
Generate Random Row Of Values
[Documentation] Takes header count to derive the amount of random strings to append to a list
[Arguments] ${header_count}
#{random_value_list} Create List
FOR ${column} IN RANGE 0 ${header_count}
${value} Generate Random String
Append To List ${random_value_list} ${value}
END
[Return] ${random_value_list}
Convert List To Comma Seperated String
[Documentation] Converts list values to string so they can be appended to csv file
[Arguments] ${values}
${converted_values} Evaluate ", ".join(${values})
[Return] ${converted_values}
Generate CSV File
[Documentation] Takes header (list of column headers) and data (List containing nested list of row values)
[Arguments] ${header} ${data}
Create File test.csv
${header_string} Convert List To Comma Seperated String ${header}
# Create the header
Append To File test.csv ${header_string}
# Append all the values row by row
FOR ${row} IN #{data}
${row_values} Convert List To Comma Seperated String ${row}
Append To File test.csv \n${row_values}
END
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}
I'm trying to create a keyword that will export a list as a suite variable, but I can't figure out how to pass a name to turn into a variable name.
*** Test Cases ***
Get Ref
${list} = Create List k l m n e
Rename List myName ${list}
log #{myName}
*** Keywords ***
Rename List
[Arguments] ${name} ${values}
log first: ${values[1]}
#{name}= Create List ${values[1]} ${values[3]}
set suite variable #{name}
The keyword takes a string and a list, creates a smaller list and exports it with the name string provided.
As a use-case, you want a generic function that can take values from a dropdown list on a webpage and return you just item 1, 3, and 5 as a new list with the name you provide. This way you could call it multiple times with different names, exporting different lists that you could use later.
Is there any way to make this work?
This seems to do what you want, if I understand the question correctly:
*** keywords ***
rename list
[Arguments] ${name} ${values}
${new}= create list #{values}
set suite variable ${${name}} ${new}
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}
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}