[1.1.0] Mac: Sikuli App object throws java.lang.ArrayIndexOutOfBoundsException

Asked by midwesthawkeye

Running the following script to manage whether Google Chrome is open from a previously running script. I want to test if it is open. If it is, close it and start a fresh instance of Chrome...

Sikuli Code:
from sikuli.Sikuli import *
# Above: using import because I eventually want to build a callable routine in here that does this,
# and call is from variuous scripts to launch Chrome, and hav it ready to have a URL typed in.

# App to work with is Google Chrome
browsername = "Google Chrome"

# First see if a previous session of Chrome is open. If so, close it.
myBrowser = App(browsername)
if myBrowser.window() :
    myBrowser.close()

# Now launch a fresh Chrome session.
newBrowser = App(browsername)
newBrowser.open() # this is line 15!
wait(3)

# End of SIkuli code

Mac OS 10.11.4 El Capitan
Google Chrome Version 50.0.2661.86 (64-bit)
Sikuli 1.1.0
Jython 2.7

SIKULI_HOME=/Users/macuser/Sikulix
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

Error is thrown both in the IDE and from command line. (Error from IDE below)
[error] script [ launchChrome ] stopped with error in line 15
[error] java.lang.ArrayIndexOutOfBoundsException ( java.lang.ArrayIndexOutOfBoundsException: 2 )

This is a very new install I am putting together. Sikuli ran great on it last week, and I actually was teaching myself how to make this a subscript in Sikuli, but as I kept working on installing the Python/MySQL drivers on the machine, and updating Java, I managed to break Sikuli.

Also I created a little script in the IDE to check those environment variables (SIKULI_HOME and JAVA_HOME) as the IDE ran, and they were accurate. I completely removed Sikuli and re-installed it, and it did not change the behavior.

After the crash, Sikuli has managed to corrupt the instance of the browser it just launched. It no longer has the name "Chrome" in the upper left, near the Apple menu, but instead says "Sikuli". Very weird.

Question information

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

just tested with your environment:
works with SikuliX 1.1.1

Revision history for this message
midwesthawkeye (midwesthawkeye) said :
#2

I know this is a newbie question, but could you direct me as to where I should go to get a copy of 1.1.1?

Revision history for this message
midwesthawkeye (midwesthawkeye) said :
#3

Nevermind. I think I found 1.1.1 as the Nightly build? I used Spotlight to be sure I was eradicating all previous build info, then stepped through the install with the nightly build, allowing it to download new sources for everything that it asked about.

Once I went back to run my script, I had the same java.lang.ArrayIndexOutOfBoundsException get thrown.

I am building this installation specifically to use Sikuli on a project, and I know I had this working last week. Is there anything you would suggest that I do to align the configuration with a more reliable set of tools?

I mean, would backing down my Java to 1.7 be "helpful"? I'll do anything you suggest since I am really excited to get past these configuration issues and start coding!

--> Jake

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

Do you have a 2nd monitor attached?

Try to run the script from commandline:
runsikulix -d 3 -c -r path to your script

btw: no need for a new App object:

# First see if a previous session of Chrome is open. If so, close it.
myBrowser = App(browsername)
if myBrowser.window() :
    myBrowser.close()
# Now launch a fresh Chrome session.
myBrowser.open()
wait(3)

Revision history for this message
midwesthawkeye (midwesthawkeye) said :
#5

Interesting. I edited the script as you suggested...

from sikuli.Sikuli import *
# Above: using import because I eventually want to build a callable routine in here that does this,
# and call is from variuous scripts to launch Chrome, and hav it ready to have a URL typed in.

# App to work with is Google Chrome
browsername = "Google Chrome"

# First see if a previous session of Chrome is open. If so, close it.
myBrowser = App(browsername)
if myBrowser.window() :
    myBrowser.close()

# Now launch a fresh Chrome session.
myBrowser.open()
wait(3)

Works reliably if Google Chrome is not already open. Here is the terminal window as it WORKS!

labmac:sikuliScripts macuser$ runsikulix -d 3 -c -r launchChrome.sikuli
running SikuliX: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar -d 3 -c -r launchChrome.sikuli
[debug] RunTimeINIT: loadOptions: check: /Users/macuser/code/pythonProjects/reaper/sikuliScripts
[debug] RunTimeINIT: loadOptions: check: /Users/macuser
[debug] RunTimeINIT: loadOptions: check: /Users/macuser/Library/Application Support/Sikulix/SikulixStore
[debug] RunTimeINIT: global init: entering as: IDE
[debug] RunTimeINIT: ScreenDevice 0 has (0,0) --- will be primary Screen(0)
[debug] RunTimeINIT: Monitor 0: (0, 0) 1680 x 1050
[debug] RunTimeINIT: runs as sikulix.jar in: /Users/macuser/Sikulix/SikuliX.app/Contents/Java
[debug] RunTimeINIT: exists libs folder at: /Users/macuser/Library/Application Support/Sikulix/SikulixLibs_201603300100
***** show environment for IDE (build 201603300100)
user.home: /Users/macuser
user.dir (work dir): /Users/macuser/code/pythonProjects/reaper/sikuliScripts
user.name: macuser
java.io.tmpdir: /var/folders/bj/6z20hv1156j1qq2_v64vzvw80000gn/T
running 64Bit on Mac OSX (10.11.4) as application .app (not from /Applications folder)
java 8-64 version 1.8.0_91-b14 vm 25.91-b14 class 52.0 arch x86_64
app data folder: /Users/macuser/Library/Application Support/Sikulix
libs folder: /Users/macuser/Library/Application Support/Sikulix/SikulixLibs_201603300100
executing jar: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar
*** classpath dump sikulix
  0: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar
*** classpath dump end
***** show environment end
[debug] RunTimeIDE: global init: leaving
[debug] RunTimeIDE: initIDEbefore: entering
[debug] RunTimeIDE: initIDEbefore: leaving
[debug] RunTimeIDE: initAPI: entering
[debug] RunTimeIDE: initAPI: leaving
[debug] init user preferences
[debug] IDE: running with Locale: en_US
[debug] IDE: initNativeSupport: starting
[debug] IDE: initNativeSupport: success
[debug] IDE: Switching to ScriptRunner with option -r, -t or -i
[debug] Runner: commandline: -d 3 -c -r launchChrome.sikuli
[debug] --- Sikuli parameters ---
[debug] 1: -d
[debug] 2: 3
[debug] 3: -c
[debug] 4: -r
[debug] 5: launchChrome.sikuli
[debug] ScriptingSupport: givenScriptName:
launchChrome.sikuli
[debug] ScriptingSupport: Trying to run script:
/Users/macuser/code/pythonProjects/reaper/sikuliScripts/launchChrome.sikuli/launchChrome.py
[debug] ScriptingSupport: initScriptingSupport: enter
[debug] JythonSupport: init: starting
[debug] JythonSupport: init: success
[debug] JythonSupport: ***** Jython sys.path
 0: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/Lib
 1: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar/Lib
 2: __classpath__
 3: __pyclasspath__/
[debug] JythonSupport: ***** Jython sys.path end
[debug] Jython: sikuli: Sikuli: starting init
[debug] RunTimeIDE: loadLib: libVisionProxy.dylib
[debug] Mouse: init
[debug] KeyBoard: init
[debug] RunTimeIDE: loadLib: libMacUtil.dylib
[debug] Jython: requested to use as default region: R[0,0 1680x1050]@S(0)
[debug] Jython: sikuli: Sikuli: ending init
[debug] JythonScriptRunner: running Jython 2.7.0
[debug] ScriptingSupport: initScriptingSupport: added: jython
[debug] ScriptingSupport: initScriptingSupport: exit with defaultrunner: jython (py)
[debug] ImagePath: new BundlePath:
/Users/macuser/code/pythonProjects/reaper/sikuliScripts/launchChrome.sikuli/
[debug] Jython: requested to use as default region: R[0,0 1680x1050]@S(0)
[debug] JythonScriptRunner: runPython: running script:
/Users/macuser/code/pythonProjects/reaper/sikuliScripts/launchChrome.sikuli
[debug] App.create: [-1:Google Chrome]
[debug] App.open [659:Google Chrome]
[debug] RunTimeIDE: final cleanup
[debug] FileManager: deleteFileOrFolder:
/var/folders/bj/6z20hv1156j1qq2_v64vzvw80000gn/T/Sikulix_334681089
labmac:sikuliScripts macuser$

However, if Google Chrome is already opened, it often fails (but not ALWAYS) like this...

labmac:sikuliScripts macuser$ runsikulix -d 3 -c -r launchChrome.sikuli
running SikuliX: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar -d 3 -c -r launchChrome.sikuli
[debug] RunTimeINIT: loadOptions: check: /Users/macuser/code/pythonProjects/reaper/sikuliScripts
[debug] RunTimeINIT: loadOptions: check: /Users/macuser
[debug] RunTimeINIT: loadOptions: check: /Users/macuser/Library/Application Support/Sikulix/SikulixStore
[debug] RunTimeINIT: global init: entering as: IDE
[debug] RunTimeINIT: ScreenDevice 0 has (0,0) --- will be primary Screen(0)
[debug] RunTimeINIT: Monitor 0: (0, 0) 1680 x 1050
[debug] RunTimeINIT: runs as sikulix.jar in: /Users/macuser/Sikulix/SikuliX.app/Contents/Java
[debug] RunTimeINIT: exists libs folder at: /Users/macuser/Library/Application Support/Sikulix/SikulixLibs_201603300100
***** show environment for IDE (build 201603300100)
user.home: /Users/macuser
user.dir (work dir): /Users/macuser/code/pythonProjects/reaper/sikuliScripts
user.name: macuser
java.io.tmpdir: /var/folders/bj/6z20hv1156j1qq2_v64vzvw80000gn/T
running 64Bit on Mac OSX (10.11.4) as application .app (not from /Applications folder)
java 8-64 version 1.8.0_91-b14 vm 25.91-b14 class 52.0 arch x86_64
app data folder: /Users/macuser/Library/Application Support/Sikulix
libs folder: /Users/macuser/Library/Application Support/Sikulix/SikulixLibs_201603300100
executing jar: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar
*** classpath dump sikulix
  0: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar
*** classpath dump end
***** show environment end
[debug] RunTimeIDE: global init: leaving
[debug] RunTimeIDE: initIDEbefore: entering
[debug] RunTimeIDE: initIDEbefore: leaving
[debug] RunTimeIDE: initAPI: entering
[debug] RunTimeIDE: initAPI: leaving
[debug] init user preferences
[debug] IDE: running with Locale: en_US
[debug] IDE: initNativeSupport: starting
[debug] IDE: initNativeSupport: success
[debug] IDE: Switching to ScriptRunner with option -r, -t or -i
[debug] Runner: commandline: -d 3 -c -r launchChrome.sikuli
[debug] --- Sikuli parameters ---
[debug] 1: -d
[debug] 2: 3
[debug] 3: -c
[debug] 4: -r
[debug] 5: launchChrome.sikuli
[debug] ScriptingSupport: givenScriptName:
launchChrome.sikuli
[debug] ScriptingSupport: Trying to run script:
/Users/macuser/code/pythonProjects/reaper/sikuliScripts/launchChrome.sikuli/launchChrome.py
[debug] ScriptingSupport: initScriptingSupport: enter
[debug] JythonSupport: init: starting
[debug] JythonSupport: init: success
[debug] JythonSupport: ***** Jython sys.path
 0: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/Lib
 1: /Users/macuser/Sikulix/SikuliX.app/Contents/Java/sikulix.jar/Lib
 2: __classpath__
 3: __pyclasspath__/
[debug] JythonSupport: ***** Jython sys.path end
[debug] Jython: sikuli: Sikuli: starting init
[debug] RunTimeIDE: loadLib: libVisionProxy.dylib
[debug] Mouse: init
[debug] KeyBoard: init
[debug] RunTimeIDE: loadLib: libMacUtil.dylib
[debug] Jython: requested to use as default region: R[0,0 1680x1050]@S(0)
[debug] Jython: sikuli: Sikuli: ending init
[debug] JythonScriptRunner: running Jython 2.7.0
[debug] ScriptingSupport: initScriptingSupport: added: jython
[debug] ScriptingSupport: initScriptingSupport: exit with defaultrunner: jython (py)
[debug] ImagePath: new BundlePath:
/Users/macuser/code/pythonProjects/reaper/sikuliScripts/launchChrome.sikuli/
[debug] Jython: requested to use as default region: R[0,0 1680x1050]@S(0)
[debug] JythonScriptRunner: runPython: running script:
/Users/macuser/code/pythonProjects/reaper/sikuliScripts/launchChrome.sikuli
[debug] App.create: [755:Google Chrome]
[debug] App.close: [755:Google Chrome]
[error] App.open failed: Google Chrome not found
[debug] RunTimeIDE: final cleanup
[debug] FileManager: deleteFileOrFolder:
/var/folders/bj/6z20hv1156j1qq2_v64vzvw80000gn/T/Sikulix_1017752462
labmac:sikuliScripts macuser$

Should I maybe put a wait() in to allow Google Chrome more time to fully close? I mean the goal here is for the script to check if there is a left over Chrome session hanging out there, and get rid of it before starting with a new one.

BTW - THANKS SO MUCH!!! for helping out here.

--> Jake

Revision history for this message
midwesthawkeye (midwesthawkeye) said :
#6

Oh, and NO second monitor attached. Just a Mac and a screen.

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

this seems to be the most reliable sequence (the wait()s do the trick - might even need to be longer on slow machines)

b = App("Google Chrome")
if b.isRunning():
  b.close()
  wait(1)
b.open(); wait(1)
b.close();wait(1)

more info:
http://sikulix-2014.readthedocs.org/en/latest/appclass.html#App

Revision history for this message
midwesthawkeye (midwesthawkeye) said :
#8

So I made the suggested changes to my code, and at first tried to run it in the IDE. Our old friend the ArrayIndexOutOfBoundsException came back.

At that point, I took the same code, but ran it from the command line as we were doing earlier. With that change it was 100% working. Brainstorming about how I might author going forward (as I try to avoid testing in the IDE), I tested having the IDE open (to model me writing the code from within there), but running the script in a separate window from the command line. It worked 100% that way as well.

I have decided I will modify how I test my software and do that from a separate terminal window going forward. With that work-around, this bug is fixed. I will mark it closed, but I wanted you to be aware that I was still seeing when running from within the SikuliX-IDE app.

Thanks so much for all of your help! --> Jake

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

ok, thanks for the detailed information.

I will check it again and surely make it more robust (available with the next nightly 1.1.1 the next days).

I am working on a solution, that allows, to edit and run Sikuli scripts (Python) in the JetBrains IDE PyCharms (images still should be managed in parallel with the SikuliX IDE).

This gives you a full blown IDE including debug mode.

This will be available with the mentioned nightly and in the docs then.
So watch out ;-)

Revision history for this message
midwesthawkeye (midwesthawkeye) said :
#10

Thanks, I will watch the nightly builds and give strong consideration to modifying the way I am developing to be the way you are suggesting. So far, my needs have been so simple that the IDE was suitable. If I get into bigger projects though, I'll need a debugger. ;)

--> Jake