RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
806 stars 235 forks source link

Using the sikulixapi classes from python (using jnius) #226

Open mzbedat opened 7 years ago

mzbedat commented 7 years ago

Hi, I want to use the sikulixapi classes from python to implement a scroll functionality... I'm totally new with robot and python and trying to find a way to do it.

What I tried is: `import subprocess from jnius import autoclass

from subprocess import call

subprocess.call(['java', '-jar', 'sikulixapi.jar']) #temporary I put the jar is at the same location of the python class

Location = autoclass('org.sikuli.script.Location') Mouse = autoclass('org.sikuli.script.Mouse') Button = autoclass('org.sikuli.script.Button')

def scroll_right(self):

setting begin - end

    x1, y1, x2, y2 = (640, 512, 640, 412)
    start = Location(x1, y1)
    end = Location(x2, y2)
    # moving left
    stepX = 10
    stepY = 0
    run = start
    Mouse.mouseMove(start); #wait(0.5)
    Mouse.mouseDown(Button.LEFT); #wait(0.5)
    for i in range(20):
            run = run.right(stepX).above(stepY)
            Mouse.mouseMove(run)
            #wait(0.1)
    Mouse.mouseUp()`

Not sure if this will work, am not able to test it yet cause am getting this error: Importing test library '/<...>/resources/SikuliApi.py' failed: KeyError: 'JAVA_HOME'

I edited my .bash_profile this way:

export ANDROID_HOME=/Appium/android-sdk-macosx export JAVA_HOME=$(/usr/libexec/java_home) export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$JAVA_HOME

when printing the path am getting:

$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Appium/android-sdk-macosx/tools:/Appium/android-sdk-macosx/platform-tools:/Appium/android-sdk-macosx/tools:/Appium/android-sdk-macosx/platform-tools:/Appium/android-sdk-macosx/tools:/Appium/android-sdk-macosx/platform-tools:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home

But still facing the same. Please advice if am on the right direction... and if yes what is the problem with JAVA_HOME?

Regards.