How to create new Keywords on Roboframework integrated with Sikuli

Asked by Test App on 2017-05-12

Hi RaiMan,

I am new to SikuliX and learning to write scripts in Sikuli integrated with Robo famework.I have read your doc on using Robot framework with Sikuli .(http://sikulix-2014.readthedocs.io/en/latest/scenarios.html#using-robotframework)

I have executed the example you have given and it works great and i can generate the report. I am trying to implement the same on excuting my test cases.

Buy when i try to run my case it says "Non-existing setting 'Library " and "Test case contains no Keywords" . From your doc it has been mentioned that except for setting up Sikulix we do not have to do anything else for Roboframework integration.

Please let me know

1. How to set up new Keywords
2.Do i have to download Robot IDE or anything else.

I Know this is a very basic question , but i am unable to find an answer and overcome the Issue

Please help.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Test App
Solved:
2017-05-18
Last query:
2017-05-18
Last reply:
2017-05-18
masuo (masuo-ohara) said : #1

Robot Framework test cases are created using a simple tabular syntax.
So you can create test cases by using text editor.
Robot IDE is not absolutely necessary when you learn Robot Framework.

First of all, you have to learn tabular syntax of Robot Framework test cases.
Have you seen the following URL?
Have you already learned tabular syntax of Robot Framework test cases?

If you have not seen this page yet, I recommend to see this page and learn tabular syntax.
https://github.com/robotframework/QuickStartGuide/blob/master/QuickStart.rst#test-cases

I suggest to read RF tutorials and other documentation. I created own keywords once, but, too bad, now don't remember where that my source code is.

What I can say is that:
1) You have run RF with Jython to work with sikuli
2) Creating own keywords is creating Python modules. You define functions in module and then that module file may be used as library and functions from it may be used as keywords.

Test App (laxmisaketha) said : #3

Hi ,

Thankyou Masuo and Roman

Yes, i did read a lot of docs and also tried understandig the tabular syntax of Robo framework.

I am trying to create my own library and have my own keywords,

I have executed the following script :

runScript("""
robot
***Settings***
Library calc.LoginLibrary WITH NAME Calculator

***Test Cases***
Verify that 2 + 2 = 4
 Start App
 Verify App

Verify that 2 + 2 = 5
 Start App
 Verify App
""")

class LoginLibrary(object):

    def __init__(self):
  self.appCoordinates = (0, 0, 1024, 768)

    def startApp(self):
        calcApp = App("Calculator")
        if not calcApp.window():
            App.open("calc.exe");
            wait(2)
            calcApp.focus();
            wait(1)

    def verifyApp(self):
        if exists ("CalcApp.png"):
            print("Calc window appeared")
        else:
            print("No Calc window")

    def runTest(self):
  self.startApp()
  self.verifyApp()
if __name__ == "__main__":
 calc = LoginLibrary()
 calc.runTest()

In the html report it says "No keyword with name 'Start App' found"

How do i create my own library and keyword?
Can you please give me a sample script on how to create my own library and keywords and in which folder do i place theese scripts

I tried reading a lot of documentation but still need help.
Please help

Thank you

masuo (masuo-ohara) said : #4

(1)Function name needs underscore.

If you want to use Keyword "Start App", function "Start_App" is needed.

(2)I also am not familiar with RobotFramework, your codes may be correct.
But you had modified the following codes.
I recommend that you should modify sample codes step by step.

[sample codes:]
http://sikulix-2014.readthedocs.io/en/latest/scenarios.html#using-robotframework

*** Settings ***
Library ./inline/LoginLibrary

[your codes:]
***Settings***
 Library calc.LoginLibrary WITH NAME Calculator

Test App (laxmisaketha) said : #5

Hi Masuo,

I have corrected the code as below and tried to run it . I get the same error saying "No keyword with name 'Start App' found"
Please tell me if i have to add something else.

runScript("""
robot
***Settings***
Library ./inline/LoginLibrary

***Test Cases***
Verify that 2 + 2 = 4
 start App
 verify App

Verify that 2 + 2 = 5
 start App
 verify App
""")

class LoginLibrary(object):

    def __init__(self):
  self.appCoordinates = (0, 0, 1024, 768)

    def start_App(self):
        calcApp = App("Calculator")
        if not calcApp.window():
        App.open("calc.exe");
           wait(2)
           calcApp.focus();
            wait(1)

    def verify_App(self):
        if exists ("CalcApp.png"):
            print("Calc window appeared")
        else:
            print("No Calc window")

    def runTest(self):
  self.start_App()
  self.verify_App()
if __name__ == "__main__":
 calc = LoginLibrary()
 calc.runTest()

RaiMan (raimund-hocke) said : #7

ok, sorry, again, since you cannot edit an answer here:

if __name__ == "__main__":
 calc = LoginLibrary()
 calc.runTest()

... is not needed generally in SikuliX scripts and not reached in this case anyways.

Go back and read carefully about how this magic feature of SikuliX works:
http://sikulix-2014.readthedocs.io/en/latest/scenarios.html#using-robotframework

... then you will understand, that this is the final script code, that is run:
runScript("""
robot
***Settings***
Library ./inline/LoginLibrary

***Test Cases***
Verify that 2 + 2 = 4
 start App
 verify App

Verify that 2 + 2 = 5
 start App
 verify App
""")

by internally handing this over to robot.

... and this is the keywords-defining class, that is temporarily stored somewhere and the pointer is placed instead of ./inline/LoginLibrary, so robot can import it. This class definition is not part of the final internal script code, since everything after the """) is stripped off.

class LoginLibrary(object):

    def __init__(self):
  self.appCoordinates = (0, 0, 1024, 768)

    def start_App(self):
        calcApp = App("Calculator")
        if not calcApp.window():
        App.open("calc.exe");
           wait(2)
           calcApp.focus();
            wait(1)

    def verify_App(self):
        if exists ("CalcApp.png"):
            print("Calc window appeared")
        else:
            print("No Calc window")

So as mentioned in the docs, it is simply this:
runScript("""
robot
***Settings***
Library ./inline/LoginLibrary

***Test Cases***
Verify that 2 + 2 = 4
 start App
 verify App

Verify that 2 + 2 = 5
 start App
 verify App
""")

class LoginLibrary(object):

    def __init__(self):
  self.appCoordinates = (0, 0, 1024, 768)

    def start_App(self):
        calcApp = App("Calculator")
        if not calcApp.window():
        App.open("calc.exe");
           wait(2)
           calcApp.focus();
            wait(1)

    def verify_App(self):
        if exists ("CalcApp.png"):
            print("Calc window appeared")
        else:
            print("No Calc window")

might be a copy&paste problem: since this is Python language, you have to take care for correct and consistent indentation.

Test App (laxmisaketha) said : #8

Hi RaiMan,

Thank you for the reply .My script works much better now with less errors . But my major issue is the html report says " Test case contains no keywords. " and the following errors below

"ERROR
Error in file 'C:\Users\E4D User\Documents\LoginLibrary.sikuli.robot\LoginLibrary.robot': Non-existing setting 'Library C:/Users/E4D User/Documents/LoginLibrary.sikuli.robot/LoginLibrary.py'.

20170518 11:40:30.674
WARN
Multiple test cases with name 'start App' executed in test suite 'LoginLibrary'.

20170518 11:40:30.674
WARN
Multiple test cases with name 'verify App' executed in test suite 'LoginLibrary'.

So this is my setup :

----JRE 8
---- Installed SikuliX 1.1.1
----Jython 2.7.0
---Python 2.7.13

Since you said robot is bundled with sikuli i did not download and install robo jar.I have executed the below script .
But my robo report always fails .Please let me know hot to execute this script with a sucessfull report

runScript("""
robot
***Settings***
Library ./inline/LoginLibrary

***Test Cases***
Verify that 2 + 2 = 4
 start App
 verify App

Verify that 2 + 2 = 5
 start App
 verify App
""")

class LoginLibrary(object):
    def __init__(self):
        self.appCoordinates = (0, 0, 1024, 768)

    def start_App(self):
        calcApp = App("Calculator")
        if not calcApp.window():
            App.open("calc.exe");
            wait(2)
            calcApp.focus();
            wait(1)
    def verify_App(self):
        if exists ("CalcApp.png"):
            print("Calc window appeared")
        else:
            print("No Calc window")

Please help Raiman

masuo (masuo-ohara) said : #9

See this page and learn tabular syntax.
https://github.com/robotframework/QuickStartGuide/blob/master/QuickStart.rst#test-cases

This is excerpt from article "Workflow tests"

Test cases are constructed from keywords and their possible arguments. The syntax requires that keywords and arguments, as well as settings and their values, are separated by at least two spaces or by a tab character. It is generally recommended to use four spaces to make the separator more explicit, and in some cases aligning arguments or other values may make the data easier to understand. For more details about the syntax see Robot Framework User Guide.

Now, number of space character is one, isn't it?
Correct the following lines.
For convenience I inserted "@" at the delimiter position.
Replace "@" with space.

(1)Library@@@@./inline/LoginLibrary
(2)@@@@start App
(3)@@@@verify App

Test App (laxmisaketha) said : #10

Hi RaiMan and Masuo,

Thank you so much
I am now able to generate a proper html report with new Keywords name and Library name

Thank you for all the patience

Regards,
Saketha