Focus on a app running as a java process from an IDE

Asked by Rev Kapuganti on 2018-10-06

Hello! Firstly great work. Really excited to use 1.1.4 api jar (love that its cross-platform!).

I'm trying to use sikulix's latest 1.1.4 api jar in my Jruby test framework(for interacting with a Java Swing GUI) and it works pretty good - except I have to always get my APP to the foreground and run the tests. I did refer some of the recommendations in here (for the prior versions) but none seem to work.

Here is how my app is getting launched as(on my mac):

window "<app's main window name>" of application process "java" of application "System Events", #Notice the app name is java

So I tried several different options but none seem to work -

Option 1:

test_app = App.new("java")
test_app.focus("app's main window name")

Option 2:

# Find an image on the app window and
test_app = App.focused_window

Option 3:

test_app = App.new('System Events')
App.focus("my app's main window")

[error] App.focus failed: [-1:Oracle ()] My app's main window

Option3 - works only when my app window is the only window active,

Any suggestions on how to get the App focused without manual intervention and some tips on using the api directly in my tests.

Thanks

Question information

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

I am mainly working and developing on Mac and have to admit, that until now I did nor succeed either, to focus on something, that was started as a new process from inside an IDE (I use IntelliJ IDEA CE).

A possible solution is to find out some AppleScript snippet (already now used inside the App implementation partly), that does the job.

A track might be (SikuliX IDE started from inside IDEA)
set myapp to "Sikulix"
tell application "System Events"
 repeat with aProc in (processes)
  if visible of aProc then
   set dispname to displayed name of (get properties of aProc)
   if dispname is equal to myapp then
    log (dispname)
    #log ((get properties of aProc))
    set mywin to first item of windows of aProc
    set focused of mywin to true # this does not work
    delay 3
    log (get properties of mywin)
   end if
   #break
  end if
 end repeat
end tell

... but until now I did not yet find out, how to tell the process, to come to front ;-)

How to run AppleScripts from inside a script:
https://sikulix-2014.readthedocs.io/en/latest/scripting.html#running-scripts-and-snippets-from-within-other-scripts-and-run-scripts-one-after-the-other
... the variant runScript(snippet)

Can you help with this problem?

Provide an answer of your own, or ask Rev Kapuganti for more information if necessary.

To post a message you must log in.