Parse a list of files and load them, instead than take a snapshot for each file

Asked by Lucio

Hi,

I would like to automate an application, which read a file, perform a filter on that file and then load the next.

I can do the whole end to end workflow but I have a lots of files, so I was hoping that there is a way to load the files as variable, instead than take a snapshot of each and have Sikuli to find them. The files are loaded through a generic load pane in OSX; the same that you find in almost any application when you use the "file" menu and choose to open a file.

Is there a way to do that, but instead of use a snapshot for each file, to load the content of a folder as a list of strings and pass that to sikuli to find and open? Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

just look here:
https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

... and read the files directly in your script (no need to use any GUI automation)

for examples just use this prepared google search
http://www.lmdfdg.com/?q=python+read+file

Revision history for this message
Lucio (theshinyknight) said :
#2

Hi RaiMan, Thanks for the reply.

The problem here is that I need to open a file from the "open" menu of the application; and I am not aware of a way to do so in pure python.
I do not have to simulate opening in the default app, like I would do in finder for example, clicking on it; which is why I am not sure how to deal with this.

With Sikuli I can perform the task, but if you need to process 30 files, you need 30 screenshot, one for each file; and if the file list change, you have to create new screenshots; while I was hoping that I could pass a string with the file name to Sikuli, and it would find it in the current open directory. Not sure if I did state my problem clearly; this is the first time that I attempt UI automation...I've been working most of the time doing unit tests, not UI tests. Thanks!

Revision history for this message
RaiMan (raimund-hocke) said :
#3

ok, understood.

In any case you could first evaluate the filenames with pure Python code and
https://docs.python.org/2/library/os.html#os.listdir

then if it is a standard mac open dialog it should be possible to enter the filename textually (simulated with paste()) into the appropriate field of the open dialog and type enter.

Revision history for this message
Lucio (theshinyknight) said :
#4

Thanks, so I can create a list of files and save it, to be used by Sikuli? I do not have problems to deal with pure python, but I have problems to understand how the code has to be merged in the Sikuli script, without an example.

Should I type the python code directly in the Sikuli IDE? Should I modify the py file inside the Sikuli package?

Thanks!

Revision history for this message
Best RaiMan (raimund-hocke) said :
#5

the script code in Sikuli(X) scripts is in fact Python language (language level 2.7).

The interpreter used is the Java based Jython 2.7 (with SikuliX version 1.1.0+).
So you can just write down valid standard Python code.

No need to write the file list into a file so.

Just make a loop to fill a list and the make a loop with this list, to do what you want with the filenames.

Revision history for this message
Lucio (theshinyknight) said :
#6

Thanks RaiMan, that solved my question.