Read from file

Asked by shaihulud

Im new to Sikuli and have tried to figure this out but cannot find a tutorial or expanation simple enough for me :/
So I want to have a external file where i type a bunch of usernames and passwords which i want to loop and sign into the application under test.
This is what I tried:
Create a csv file and typed this into the script:

f = open(C\\Users\\caan\\Documents\\SikuliTests\\SikuliTest.sikuli\\input.csv,'r')
print f

But it doesnt work and says error "no viable alternateive at input "users"
I am supposed to write: f = open(filename, 'w')
But im not sure what filename means? i have tried writing the directory in different ways....

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
Best RaiMan (raimund-hocke) said :
#1

f = open("C:\\Users\\caan\\Documents\\SikuliTests\\SikuliTest.sikuli\\input.csv") # r = read is default
for line in f.readlines():
   print line.strip()

BTW. for this thera are tons of questions and examples around her and in the net.

*** Im new to Sikuli
this is of course one aspect, but the challenge for more complex things (like reading from a file and evaluating the lines into processable items) you have to learn some Python

Revision history for this message
shaihulud (cal-a) said :
#2

I understand that I am not skilled enough in Python to get this to work. Unfortunately I don´t have the time to learn Python in order to get this to work.

I have looked at other documentation on how to do this, such as:
http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
https://answers.launchpad.net/sikuli/+question/169128
https://answers.launchpad.net/sikuli/+question/189827
https://answers.launchpad.net/sikuli/+question/132445
https://answers.launchpad.net/sikuli/+question/194613

But it´s all just bits and pieces of a puzzle I cannot put together.
The thing is that data driven tests such as this (login on a homepage by repeating one test that uses an external file for username and password) is a very important feature of a automatic testing tool, I personally think a guide for this would be nice in the "complete guide to sikuli script" documentation.

But thanks alot for your answer. Maybe I can come back to this some other time when I have more knowledge or time!

Revision history for this message
shaihulud (cal-a) said :
#3

Thanks RaiMan, that solved my question.