Mojave : SikuliX IDE : I need to create a Keyword for invoking my app with Robotramework (from the SikuliX IDE)

Asked by Melvin Raymond on 2019-02-08

-- SikulixIDE-1.1.4--SNAPSHOT
- Mac Mojave OS
- Robotframework
- Python 2.7.10

In a previous question I had learned I could invoke my application straight out of the SikuliX IDE (without Robot Framework) by using this command:

App.open("/Applications/Viewer.app")

MY CURRENT GOAL is to try and create a Keyword with Robot Framework that will invoke my application from inside the SikuliX IDE and running a Robot Framework script. I'd like to start out by doing this as an .inline library. I'm struggling with how to do this. But I do see there is a "process" collection for Robot Framework that might work? Maybe there's an easier way, but I really need a concrete example of turning that above command into a legitimate Keyword.

FUTURE GOALS: (not for now though)
- I want to change that Keyword to an external Keyword
- I want to learn how to organize folders and subfolders by running all my previous working examples from one Robot Framework script (so I can simulate as if I were doing those with my own application once I figure out how to do it all). Note that I've gone through a lot of simple examples and have a bunch of single Robot Framework scripts I can run individually.
- Where I'm going with this is I eventually want to be able to test my own app by invoking it from the SikuliIDE within RobotFramework and write a bunch of Test Cases and Keywords. But at this point I have no clue how to do any of this. I'm picking at it in my spare time.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Melvin Raymond
Solved:
2019-02-12
Last query:
2019-02-12
Last reply:
2019-02-12
Melvin Raymond (fribian) said : #1

I was able to invoke my app using this chunk of code which a developer gave me. I will attempt to see if I can get the Robot Framework to use it with a Keyword somehow.

#!/usr/bin/python

import subprocess
subprocess.call(["/usr/bin/open", "-a", "Labquest Viewer"])

Click to expand inline (7 lines)

3:08 PM
chmod 0777 thing.py
3:08 PM
./thing.py

RaiMan (raimund-hocke) said : #2

All you need to learn how to implement your own keywords see here:
https://sikulix-2014.readthedocs.io/en/latest/scenarios.html#using-robotframework

start with the inline class definition and then you might store the class file outside, to use it more than once in different tests.

In the keyword def just use the normal SikuliX Python scripting (class App in this case).

Melvin Raymond (fribian) said : #3

I don't seem to have a grip on using the syntax for that class App. This is the last one I tried. It's one of many attempts that keep returning this error.

robot.run returned: 252
robot.run output is here:
/Users/labquest_automation/Desktop/SikuliX_Scripts/InvokeViewer.sikuli.robot

1.1.4-SNAPSHOT-2019-02-07_09:10/Mac10.14.2/Java8(64)1.8.0_201-b09

I dug around a bit to see if I could figure out what that means and found: "DATA_ERROR = 252 # Invalid data or cli args", which I guess means I've got a bad argument passed or something. I got that from here: "https://robot-framework.readthedocs.io/en/2.9.2/_modules/robot/errors.html"

This is the final Script I attempted:

runScript("""
robot
*** Variables ***
${TESTAPP} "/Applications/Viewer.app"
*** Settings ***
Library ./inline/AppLibrary
Test Setup start my application ${TESTAPP}
*** Test Cases ***

""")

class AppLibrary(object):
  def start_my_application(self, myApp):
    someApp = App.open(myApp)

Melvin Raymond (fribian) said : #4

I forgot to add the link to the page where I'm trying to figure out how to use the Sikuli Class app

https://sikulix-2014.readthedocs.io/en/latest/appclass.html#App.setUsing

RaiMan (raimund-hocke) said : #5

I will come back to this later today.

RaiMan (raimund-hocke) said : #6

this works:

runScript("""
robot
*** Variables ***
${TESTAPP} "preview"
*** Settings ***
Library ./inline/AppLibrary
*** Test Cases ***
Test Setup start my application ${TESTAPP}

""")

class AppLibrary(object):
  def start_my_application(self, myApp):
    someApp = App.open(myApp)

BE AWARE as already mentioned:
to fill the next column in a line, you have to use at least 2 spaces:

wrong:
Test Setup start my application ${TESTAPP}

correct:
Test Setup start my application ${TESTAPP}

Melvin Raymond (fribian) said : #7

I'm sorry Raiman but that didn't work for me. When I copy and paste this from Sikuli here or from here to Sikuli, it doesn't always seem to copy spaces correctly (I think).

When you have time, could you please add some "@" characters in that script where you're putting the spaces? I will remove them after copy and paste into Sikuli. That would be very helpful and I think I saw on the forums where you had done that for someone else.

In the meantime I'll continue to try and figure out where I'm messing up those spaces. I'm aware of the spacing but not always aware of what defines a column, and there's so much documentation to get through that I have a difficult time locating it.

Melvin Raymond (fribian) said : #8

I forgot to mention also that the error has changed. I'm getting "robot.run returned: 1"

Melvin Raymond (fribian) said : #9

OK. I finally got your script to run by putting tabs behind these lines of code in your script, so maybe I can do the same with mine and get it working. Here's what I put in (substituting "@" symbols where I have spaces:

runScript("""
robot
*** Variables ***
${TESTAPP}@@@@@@@@"preview"
*** Settings ***
Library@@@@@@@@./inline/AppLibrary
*** Test Cases ***
Test Setup@@@@@@@@start my application@@@@@@@@${TESTAPP}

""")

class AppLibrary(object):
  def start_my_application(self, myApp):
    someApp = App.open(myApp)

Melvin Raymond (fribian) said : #10

OK, I got my app to launch, so looks like that works Railman. For those interested in being able to get a jump start on invoking an app on Mojave using the Robot Framework inside SikuliX, I've included the code here. This shows an inline class app Keyword. Note also that here I have substituted "@" symbols where there are spaces. I used 2 TABS in those areas so I could better see where the "columns" are located. Theoretically you should be able to copy and paste to SikuliX and then remove those "@" symbols and replace with a couple TABS. You would also want to replace the variable ${TESTAPP} with the path to the Application you want to invoke on the Mac Mojave.

runScript("""
robot
*** Variables ***
${TESTAPP}@@@@@@@@ "/Applications/Viewer.app""
*** Settings ***
Library@@@@@@@@./inline/AppLibrary
*** Test Cases ***
Test Setup@@@@@@@@ start my application@@@@@@@@${TESTAPP}

""")

class AppLibrary(object):
  def start_my_application(self, myApp):
    someApp = App.open(myApp)

Once again, thank you very much for your help with this Railman. Took me a bit to get this off the ground, but I learned a lot.

~ Mel

Melvin Raymond (fribian) said : #12

RaiMan.