← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #188042]: Using common functions across scripts

 

Question #188042 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/188042

    Status: Open => Answered

RaiMan proposed the following answer:
some tips for a new bee:

- before structuring things into more complexity, just implement the bits and peaces, so they work as you expect
- leave the Class construct for the moment and concentrate on workflow and functions (things to be reused more than once)
- put all defs in e.g. functions.sikuli
- put the workflow  in NewTestScript.sikuli (as you have started with)
- read carefully through the docs chapter http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images and decide, how you want to handle your captured images.
- for the start have all your .sikuli in one folder (no need to deal with sys.path)
- name your images yourself using a naming concept (Sikuli settings) (with this setup and using import, all your images will be found automagically)

# --- Function.sikuli
from sikuli import *

def setUp():
    pass # your lots of awesome stuff, you want to do as general setup

def tearDown():
    pass # your stuff, you want to do as general termination

# for testing purposes
testing = True
if testing:
    setUp()
    # some stuff in between only for testing
    tearDown()

develop and run this script until both functions are basically doing what you want.
Then change the line
testing = True
to
testing = False
If you run the script now, it will do nothing any more - now it is a module to be imported
Save the script and even close it.
When you are sure what you are doing later on, you might delete these lines of course.


Then start to work out your main flow:

# --- NewTestScript.sikuli
import Function
reload(Function)
from Function import *
# this imports the names defined in Function and refreshes on each rerun

setUp() # this will execute setUp from module functions

# put some stuff here

tearDown() # as for setUp

When this script setup works, you can start to develop further (add more
test cases and workflow elements) having both scripts simultaneously
open in the IDE. Additional functions would go to Function.sikuli (if
you make changes here, save it before running your NewTestScript.sikuli.

You might generally from the start structure your main scripts according
to the unit test feature of Jython/Python. Then you should look at faq
1804 first.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.