how do i for create one switch test in sikuli?

Asked by Raphael Silva

I would like to run several test cases in a switch, there is this possibility?

Question information

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

If you are talking about "test cases" being separate .sikuli scripts, just make a batch file, that runs each .sikuli one after the other using Sikuli-IDE-w.bat (see http://doc.sikuli.org/faq/010-command-line.html).

If this is not true, come back with a more information on what your "test cases" look like.

Revision history for this message
Raphael Silva (raphaelcoel) said :
#2

I want to join several test cases and executes them.

eg
Test Case 1
Test Case 2

run both in sequence.

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

pls. give more info on what your "test cases" are in the moment.

Revision history for this message
Raphael Silva (raphaelcoel) said :
#4

My test case are the scripts created for test my app.

for example:

LancarItem.sikuli
Login.sikuli
FecharConta.sikuli

I want execute in sequence with only one command. Some script then can execute.

eg

in sikuli

exe LancarItem.sikuli and Login.sikuli and FecharConta.sikuli

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

There is no "one-command" solution for running other scripts from a main script.

You have to organize/script this on your own, based on the existing Python/Jython features:

1. execfile()
no changes needed in your script, but a bit more complicated to implement, because you have to tell Sikuli where to locate the used images.

2. import
the executed scripts must be changed to importable modules (the code to run has to be in functions ( def runMe(): ). But the usage is much easier, since it automatically gives access to the related images.
(see http://doc.sikuli.org/globals.html#importing-other-sikuli-scripts-reuse-code-and-images)

--- a general solution for 1.

- supposing all scripts are in the same folder

# main script

import os
dir = os.path.dirname(getBundlePath()) # our working dir with the scripts

# run some scripts in sequence
for script in ("LancarItem", "Login", "FecharConta"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik) # folder for images
    execfile(os.path.join(dir, scriptpy)) # runs the code

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

sorry, missed a bracket:

# run some scripts in sequence
for script in ("LancarItem", "Login", "FecharConta"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik)) # folder for images
    execfile(os.path.join(dir, scriptpy)) # runs the code

Revision history for this message
Raphael Silva (raphaelcoel) said :
#7

Is right ?

my dir = c:\mylib

import os
dir = os.path.c:\mylib(getBundlePath()) # our working dir with the scripts

# run some scripts in sequence
# run some scripts in sequence
for script in ("LancarItem", "Login"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik)) # folder for images
    execfile(os.path.join(dir, scriptpy)) # runs the code

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

supposing all scripts are in c:\mylib.

then make one script c:\mylib\main.sikuli containing:

import os
dir = os.path.dirname(getBundlePath()) # the dir with the scripts

# run some scripts in sequence
for script in ("LancarItem", "Login"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik)) # folder for images
    execfile(os.path.join(dir, scriptpy)) # runs the code

Revision history for this message
Raphael Silva (raphaelcoel) said :
#9

when I run the script displays the following error. can you helpe me

#main.sikuli
import os
dir = os.path.dirname(getBundlePath()) # our working dir with the scripts

# run some scripts in sequence
# run some scripts in sequence
for script in ("LancarItem", "Login"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik)) # folder for images
[error in line] execfile(os.path.join(dir, scriptpy)) # runs the code

[error] Mensagem de erro: Traceback (most recent call last):
 File "C:\DOCUME~1\RAPHAE~1.SIL\CONFIG~1\Temp\sikuli-tmp2386847713184182220.py", line 10, in
 execfile(os.path.join(dir, scriptpy)) # runs the code
SyntaxError: Non-ASCII character in file 'C:\mylib\LancarItem.sikuli\LancarItem.py', but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

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

In every script, you want to run this way, put the following line as the first line:

# coding=utf-8

Revision history for this message
Raphael Silva (raphaelcoel) said :
#11

Ok thank you RaiMan, but i run the script (main.sikuli) and nothing happens. you know why?

Revision history for this message
Raphael Silva (raphaelcoel) said :
#12

RaiMan pplease disregard the above comment.

It's working.

thank you very much.