RaiMan / SikuliX1

SikuliX version 2.0.0+ (2019+)
https://sikulix.github.io
MIT License
2.78k stars 357 forks source link

JRuby support needs to be revised/updated #566

Closed HoudayerPierre closed 1 year ago

HoudayerPierre commented 1 year ago

Hello, I playing with JRuby as it seems to be a bit more supported for the latest version of ruby (3.1) as Jython is still in 2.7.3. So I just adding some libs in JRuby 9.4.0.0 (BTW the 9.4.1.0 seems to hangs with sikuli)

I have installed gems like this : java -jar jruby-complete-9.4.0.0.jar -S gem install -i .\gemsdl webdrivers selenium-webdriver jruby-win32ole capybara jar uf jruby-complete-9.4.0.0.jar -C gemsdl .

and run this simple code :

require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'

Capybara.configure do |config|
  config.run_server = false
  config.default_driver = :selenium_chrome
  config.app_host = 'https://lambdatest.github.io/sample-todo-app/'
end

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

include Capybara::DSL

visit('/')
fill_in('sampletodotext', with: 'Hello, world!')

click_button('addbutton') 
#Capybara::click_button('addbutton') 

Result :

[error] script] stopped with error at line --unknown--
[error] Could not evaluate error source nor reason. Analyze StackTrace!
[error] (TypeError) cannot convert instance of class org.jruby.gen.RubyObject2 to class org.sikuli.script.Region

I think there is a confilt with capybara & sikuli on click_button or Capybara::click_button (BTW, why error at line --unknown--?)

RaiMan commented 1 year ago

Sorry for the inconvenience, but I did not do anything to test in a Ruby env since years.

What version of SikuliX?

Please more info on your environment. I have available Windows 11, macOS Intel/Mx and Ubuntu 22.04.

HoudayerPierre commented 1 year ago

Using last SikuliX 2.0.5, Windows 10&11, java version "1.8.0_181". Lots of python libs are dropping python 2.7 (like selenium, splinter...) so just testing JRuby as it seems to be more alive (last Ruby 3.2, JRuby 9.4.0.0 -> Ruby 3.1). I will prefer a Jython 3 but seems to be dead.

RaiMan commented 1 year ago

@HoudayerPierre Thanks for the info. I agree, that it is worth to give Ruby a new chance. Another option (also left behind :-( is to make the SikuliX features available in real Python

HoudayerPierre commented 1 year ago

I think SikuliX features available in real Python (&Ruby) will be better as we can use C extensions required in some other libs and frameworks it's very limited/unavailable in Jython/JRuby.

RaiMan commented 1 year ago

@HoudayerPierre Thanks for feedback. I will surely not implement the SikuliX features in Python or Ruby. There are Python-to-Java bridges available. My favorite is https://github.com/py4j/py4j (already played with it - works https://github.com/RaiMan/sikulix4python). Another one is https://github.com/jpype-project/jpype.

Another possibility is to run SikuliX as a server with a Restful API, which in turn could be wrapped in a native API in any environment/language. The base for such a server is available, but currently not useable.

The 2.0.6 will have support for JRuby 9.4.x (currently busy with the setup).

HoudayerPierre commented 1 year ago

Thanks for your tips and your work, https://github.com/adrian-evo/robotframework-sikulixlibrary (as RF is opt.) I think it seems to be what I need for using SikuliX with python 3+ via py4j or jpype.

RaiMan commented 1 year ago

@HoudayerPierre Great thanks for this tipp. Looks promising. I will have a look into it and see how to make it work with 2.0.6 (still snapshot ;-)

Would be fine to hear from you again on success (preferably: sikulix---at---outlook---dot---com)

RaiMan commented 1 year ago

@HoudayerPierre The Python case now has a follow-up at: https://github.com/RaiMan/SikuliX1/issues/570