Unable to use the new friendly text methods through api 1.1.4

Asked by Rev Kapuganti on 2018-10-06

I'm using Jruby as my platform of choice for my tests with newly dowloaded Sikulix 1.1.4

I'm not able to find text methods (other than findText) to use with the Screen/Region instance.

NoMethodError: undefined method `collect_words' for #<Java::OrgSikuliScript::Region:0xc20be82>

NoMethodError: undefined method `collect_words' for #<Java::OrgSikuliScript::Screen:0x19868320>

It errors for all these new text features: existsText, waitText, collectWords, collectWordsText, collectLines, collectLinesText. (except findText(string))

Please let me know if I'm doing anything wrong? How can I enable these features to use with my tests?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-10-08
Last query:
2018-10-08
Last reply:
2018-10-08
RaiMan (raimund-hocke) said : #1

I suppose, you are running Ruby scripts from some IDE (not the SikuliX IDE).

I have to admit, that I did not look into JRuby support for more than 3 years.

When running scripts from the SikuliX IDE, this is added to top of script at runtime:
 "# coding: utf-8\n"
 "require 'Lib/sikulix'\n"
 "include Sikulix\n"

This works in the IDE on Mac:
reg = Region(0,0,300,20);
print(reg);
print(reg.collectWordsText())

... and prints:
R[0,0 300x20]@S(0) E:Y, T:3,0
[é, Sikulix, File, Edit, Run, View, ']

Rev Kapuganti (rev-rocks) said : #2

Thanks Raiman.

Yes I'm using just the sikulixapi.jar(1.1.4) with my cucumber(jruby) suite. My development IDE is Rubymine.

Here is how I'm loading sikulix api into my test project -

class Platform
    def self.sikulix_path
      path = "#{ENV['SIKULIX_HOME']}"
      if ENV['SIKULIX_HOME'].nil?
        raise LoadError, "Failed to load 'sikuli-api1.4.jar'\nMake sure SIKULIX_HOME is set!, Refer instructions on the git repo"
      end
      return path
    end
end

And then load as(as you suggested) :

require Platform.sikulix_path

java_import 'org.sikuli.script.Screen'
java_import 'org.sikuli.script.Region'
java_import('org.sikuli.script.App')

<Find an image on my app under test> . # Using mac - cannot focus on the app directly! A workaround you suggested in your other answers

app_window = App.focused_window.

# All the below errored out. (just the find_text or print_text works!)

        app_window.collect_words.each do |match|
          puts match.get_text
        end

       or

        Region.new(app_window).collect_lines.each do |match|
          puts match.get_text
        end

    or

        Region.new(@screen).collect_words_text.each do |wt|
          puts wt
        end

   or

         @screen.collect_lines_text.each do |lwt|
          puts lw
        end

I will try with java_importing all the script packages classes like you suggested.

Rev Kapuganti (rev-rocks) said : #3

importing the whole package didn't work either. On a debugger, I don't see the new methods(on Region instance) in the list of public methods.

May be I'm missing something.

I did notice this statement in the README.md on the git repo for 1.1.4 sikulix

Sikuli API 2014 (version 1.1.x)
===

The ready-to-use package `sikulixapi.jar` provides this API for Java programming and any Java aware scripting languages.

When using Jython or JRuby, this module provides special support to conveniently use the SikuliX features in your scripts. They are exported additionally on the fly to the folder `Lib` in the folder containing `sikulixapi.jar`.

I don't see a Lib folder and additional support getting created on the fly in the directory containing the api jar. Any suggestions here @Raiman?

Rev Kapuganti (rev-rocks) said : #4

This didn't work as well - with api.jar in the CLASSPATH and doing -

 "# coding: utf-8\n"
 "require 'Lib/sikulix'\n"
 "include Sikulix\n"

reg = Region(0,0,300,20);
print(reg);
print(reg.collectWordsText()) / or collect_words_text with jruby syntax :(

Best RaiMan (raimund-hocke) said : #5

ok, saying:
 "# coding: utf-8\n"
 "require 'Lib/sikulix'\n"
 "include Sikulix\n"
.... might have been unfair:

should read in a script (with sikulixapi.jar on Java class path)

require 'Lib/sikulix'
include Sikulix

... the coding line should not be needed in your case

RaiMan (raimund-hocke) said : #6

you say:
I did notice this statement in the README.md on the git repo for 1.1.4 sikulix

Sikuli API 2014 (version 1.1.x)
===

looks odd, because the current repo for 1.1.4 is
https://github.com/RaiMan/SikuliX1

... so are you really sure, you have the latest build of sikulixapi.jar version 1.1.4
https://raiman.github.io/SikuliX1/downloads.html

Rev Kapuganti (rev-rocks) said : #7

Sorry for the confusion.

Readme I was referring to is inside the API folder under 1.1.4 - https://github.com/RaiMan/SikuliX1/blob/master/API/README.md

Rev Kapuganti (rev-rocks) said : #8

Thanks @Raiman -

Now I'm able to access the new Text methods with your suggestion.

require 'Lib/sikulix'
include Sikulix

... the coding line should not be needed in your case

App.focused_window.public_methods.grep /collect/ => results in:

Array (8 elements):

collectLines collectLinesText collect_words collect_lines_text collect_lines collectWords collect_words_text collectWordsText

However when using it - its erroring out with:

        App.focused_window.collect_words_text.each {|w| puts w}

[error] RunTimeAPI: *** terminating: TextRecognizer: start: native libraries not found. Do I need any other libs along with just the api jar?

Thanks

Rev Kapuganti (rev-rocks) said : #10

Thank you @Raiman, it worked. I was missing tesseract setup on my mac.

brew install tesseract # did the trick

Rev Kapuganti (rev-rocks) said : #11

Thanks RaiMan, that solved my question.

RaiMan (raimund-hocke) said : #12

That is really odd - are you sure, you have the latest build of 1.1.4 running?

On Mac there is no need to install anything, because everything is bundled.

Rev Kapuganti (rev-rocks) said : #13

Hmm interesting, not sure why it wouldn't work on my mac. And yes, it is the latest 1.1.4 from https://raiman.github.io/SikuliX1/downloads.html.

All I'm doing is - plain import of the sikuli api jar - like you suggested -

require $PROJECT_PATH + 'sikulixapi.jar'
require 'Lib/sikulix'
include Sikulix

RaiMan (raimund-hocke) said : #14

ok, thanks.

I guess, I have to test it myself ;-)