Robotframework: How to read a random row in csv file? -


i made code in python read row in csv file:

import csv  class csvlibrary(object):     robot_library_scope = 'global'      def __init__(self):         print 'read cell value in csv file'      def read_cell_value_by_row(self,filename,rownumber):         #read existing csv file         userdata=[]         user={}         open(filename,'rb') csvfile:             #read csv file dictionary object             reader=csv.dictreader(csvfile)             #read , store list of dictionary items             userdata=list(reader)             #get specific list item dictionary object             user=userdata[rownumber-1]             #return dictionary object             return user 

then in robotframework script:

    ${row_number}=    convert integer    1     ${user_info}=    read_cell_value_by_row    userinfo.csv    ${row_number}     ${username}    dictionary    ${user_info}    username     log    ${username}     ${password}    dictionary    ${user_info}    password     log    ${password}     input text    ${login_username_textbox}    ${username}     input text    ${login_password_textbox}    ${password} 

but don't know how can read random row on csv file, can me?

it seems you're of way there, need generate random number? recommend using string library simplicity, though need control number ensure within bounds want.

http://robotframework.org/robotframework/latest/libraries/string.html

${random_number}=    generate random string    2    [numbers] 

the above offer number between 00 , 99, ensure 00 handled of course.

a nice alternative found via search if need unique numbers @ombre42 - robot framework: generating unique random number

however, doesn't sound need them unique.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -