run sikuli from command line

Asked by Joe Loyzaga

I'd like to know if I can create a sikuli test that prompts for 2 image paths and compares if they are the same
Then I'd like to call that via python

possible?

Joe

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Do you mean prompts for user input?

Revision history for this message
Eugene S (shragovich) said :
#2

Do you mean prompts for user input?

Revision history for this message
Joe Loyzaga (joseph-loyzaga) said :
#3

yes input the path to the images

Revision history for this message
Eugene S (shragovich) said :
#4

So something like this?

path1 = raw_input('Enter path 1: ')
path2 = raw_input('Enter path 2: ')

print path1 == path2

Revision history for this message
Joe Loyzaga (joseph-loyzaga) said :
#5

I'd like to return the result to the python program that calls it providing the input paths(2) and result(1)
Is that possible?

Revision history for this message
Eugene S (shragovich) said :
#6

I am not sure I understand. In the above way you can use the result of the evaluation "path1 == path2" as you wish as it return True or False.

So you can assign it to another variable like that:

result = path1 == path2

if result == True:
    print "result is True"
elif result == False:
    print "result is False"

Revision history for this message
Joe Loyzaga (joseph-loyzaga) said :
#7

I want to run it as part of a test automation test stream where I have a list od image paths that I send to sikuli as above and write pass or fail in the same list alongside the pairs that fail and then keep processing until end of file/list - its part of a map site that needs to reflect the originating map from a custodian but we are allowed to render it using a different file format

Revision history for this message
Eugene S (shragovich) said :
#8

I'm sorry but I think I lost you here as I am not sure what exactly are you asking.

Revision history for this message
Joe Loyzaga (joseph-loyzaga) said :
#9

your last comment makes sense but if I call this as a function and I send 3 args - 2 as the file paths and the third one as the result of the compare
 1. what would the call look like
2. what would I get as the third arg(what woulkd be returned?)

Revision history for this message
Eugene S (shragovich) said :
#10

Generally, what you ask can look like this (if I understand your question correctly):

path1 = "C:\\temp"
path2 = "C:\\temp"

compareResult = path1 == path2

def someFunction(arg1, arg2, arg3):
    print arg1
    print arg2
    print arg3

    #some other logic...

#usage
someFunction(path1, path2, compareResult)

However I really struggle to understand why would you want something like that as it's not a very good practice. It will make more sense to evaluate the comparison between the two paths inside the same function rather than passing the comparison result together with paths.

Revision history for this message
Joe Loyzaga (joseph-loyzaga) said :
#11

can you outline the best practice by showing me the code? don't understnad waht you mean...

Revision history for this message
Eugene S (shragovich) said :
#12

I meant something this:

def comparePaths(arg1, arg2):
    return arg1 == arg2

def someFunction(arg1, arg2):
    #call comparePath() function from here when needed

Revision history for this message
Joe Loyzaga (joseph-loyzaga) said :
#13

If you could expand on how to code it being used on command line then I'm pretty sure you've answered the question

Revision history for this message
Eugene S (shragovich) said :
#14

Assume the below code is stored in file named "testFile.py"

import sys

path1 = sys.argv[1]
path2 = sys.argv[2]

def comparePaths(arg1, arg2):
    return arg1 == arg2

def someFunction(arg1, arg2):
    print comparePaths(arg1,arg2)

    #some other logic...

someFunction(path1, path2)

Then from command line you can run it like this:
testFile.py "C:\temp" "C:\temp2"

Can you help with this problem?

Provide an answer of your own, or ask Joe Loyzaga for more information if necessary.

To post a message you must log in.