Wednesday, 15 August 2012

robotframework - Read a file from a position in Robot Framework -



robotframework - Read a file from a position in Robot Framework -

how can read file specific byte position in robot framework?

let's have process running long time writing long log file. want current file size, execute affects behaviour of process , wait until message appears in log file. want read portion of file starting previous file size.

i new robot framework. think mutual scenario, haven't found how it.

there no built-in keywords this, writing 1 in python pretty simple.

for example, create file named "readmore.py" following:

from robot.libraries.builtin import builtin class readmore(object): robot_library_scope = "test suite" def __init__(self): self.fp = {} def read_more(self, path): # if don't know file, # set file pointer 0 if path not in self.fp: builtin().log("setting fp zero", "debug") self.fp[path] = 0 # open file, move pointer stored # position, read file, , reset pointer open(path) f: builtin().log("seeking %s" % self.fp[path], "debug") f.seek(self.fp[path]) info = f.read() self.fp[path] = f.tell() builtin().log("resetting fp %s" % self.fp[path], "debug") homecoming info

you can utilize this:

*** settings *** | library | readmore.py | library | operatingsystem *** test cases *** | illustration of "tail-like" reading of file | | # read current contents of file | | ${original}= | read more | /tmp/junk.txt | | # add together more info file | | append file | /tmp/junk.txt | new content\n | | # read new info | | ${new}= | read more | /tmp/junk.txt | | should equal | ${new.strip()} | new content

file-io robotframework

No comments:

Post a Comment