sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #03305
Re: [Question #160003]: Global variables and functions argument in unittest
Question #160003 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/160003
Status: Answered => Open
Sebastian is still having a problem:
OK thanks for reply.
I am newbie in Sikuli and Python (Jython) therefore I don't know some features (I wrong found its as limitations). As you wrote, I checked possibility to run script directly with Jython interpreter; I run following example :
import os
import sys
import unittest
class Test(unittest.TestCase):
def setUp(self):
switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")
print("pass")
print(os.getcwd()) #only for test if can I use OS module
pass
def tearDown(self):
print(sys.executable) #only for test if can I use SYS module
print("end")
pass
def testl(self):
print("test1 pass")
wait(2)
pass
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
unittest.TextTestRunner(verbosity=2).run(suite)
I run script above using command :
java -Dpython.path=Lib -jar sikuli-script.jar mytest.sikuli > test.log
Test was executed with no problems.
But I want to group some simple functions to my own library and use its in my tests.
Maybe I will explain it by example; I want to have open and close my testing application in separate method in separate file runIE.py e.g :
import sys
import os
def runIE():
print("run IE")
switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")
def closeIE():
print("close IE")
type(Key.F4,KEY_ALT)
closeApp("windows internet explorer")
And I want to use these method in my setup and teardown :
import os
import sys
import unittest
import runIE
class Test(unittest.TestCase):
def setUp(self):
runIE.runIE()
print("pass")
pass
def tearDown(self):
runIE.closeIE()
print("end")
pass
def testl(self):
print("test1 pass")
wait(2)
pass
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
unittest.TextTestRunner(verbosity=2).run(suite)
But seems that that despite runIE is imported correctly, it can't see
Sikuli functions, I got error :
ERROR: testl (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\Program Files (x86)\Sikuli X\mytest.sikuli\mytest.py", line 8, in set
Up
runIE.runIE()
File ".\runIE.py", line 6, in runIE
switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")
NameError: global name 'switchApp' is not defined
Idea is I want to have pack of simple functions (run testing application, close it, open project, create new project, save project etc) that will be used to test application.
How can I use my own library that will use Sikuli functionality in another scripts that are running directly from Jython interpreter ?
Regards
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.