← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #162606]: [HowTo] IDE: use sub functions (reusable code) in test cases

 

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

Description changed to:
*** Solution/workaround/hack (based on rc2)

When running a test in the IDE or from command line with option -t, the
defined functions (test cases) are currently processed in reverse order.
So if you want to use your own sub functions in the test cases, this is
the hack:

--- put all needed sub def()'s to the end of the script, so they will be
known later, when the test cases are processed. Since they are
internally packed into a class, they need self as first parameter and
have to be called with self.xxxx() (if no additional parameters are
defined) or self.xxxx(2nd-parameter, 3rd-parameter, ...) (means: when
using the function, self is omitted).

--- example:

def test1(self):
    self.login("name", "pass")
    ....

def login(self, username, password):
   ....

--------------------------------------------------------------------------------------
--- original question: 
Is there way to reuse Python function in my Sikuli test file. 

for example i want:

def login(name, pass):
    ...
    click()
    ....

def testA(self):
    login("someName", "pass");
    ...

def testB(self):
    login("someOtherName", "pass");
    ...

And I want that all this function be in the same file.
Thanks.

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