Switch to JUnit testing app

Asked by Martin D

I have a button in my application when pressing will open a link in Firefox. How can I switch back to my JUnit program? My test
Class calls the main method of a certain class which then launches the GUI of that application where the mentioned button is. Does the JUnit application have a name which I can switch to or any other workaround?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Martin D
Solved:
Last query:
Last reply:
Revision history for this message
Martin D (martin+sikuli) said :
#1

I was thinking maybe a possibility to switch back to the last app. Holy shit. Maybe cmd + tab. Gotta try.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

What system?

How do you run JUnit? e.g from inside Netbeans, Eclipse? or from commandline using a built jar?

Revision history for this message
Martin D (martin+sikuli) said :
#3

Sorry.
I'm on Mac os x mountain lion.
Running JUnit from within eclipse.

The other suggestion: cmd + tab doesn't seem to work. At lest I can't find the correct command.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Ok, same as my standard environment ;-)

The solution is the App class (look into Sikuli's JavaDocs ;-)

aEcl = new App("Eclipse");

// some code

aEcl.focus(); // brings you back to Eclipse

But why do you want to switch back to Eclipse?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

sorry, Java :-(

App aEcl = new App("Eclipse");

Revision history for this message
Martin D (martin+sikuli) said :
#6

Ok, I think I wasn't quite clear.
When I run my test class a GUI of the program being tested is opened. In that app I have a button to open a link in a browser. I then want to confirm that the content of the opened link is correct an ten go back to the GUI to do more tests. So I don't want to go back to eclipse, but rather the GUI.

In my case the top left says that it's name is "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner".

Revision history for this message
Martin D (martin+sikuli) said :
#7

My code is something along this line:

@Before
public void testApp() {
    app.main(); // GUI opens here
}

@Test
//Different test cases...

Revision history for this message
Neo (simamhussain) said :
#8

As app is your object, you can use app.focus(), after you visit the external link to get back the focus. helps ?

Revision history for this message
RaiMan (raimund-hocke) said :
#9

@ Neo
I guess app is some application object created by the user (his GUI app) and a Sikuli App object.

@ Martin
I guess, it is not possible, to switch to your GUI app, using Sikuli's app switching features.
I made some tests, but did not succeed using switchApp()/App.focus().

Even using AppleScripts Sytem Events feature i did not find a way, to make the process frontmost again.

So I guess the only way would be, to make your GUI a real Mac app (like Sikuli IDE), and start it from Java using the open command with Runtime.exec().

Then Sikuli's app switching features should work.

Revision history for this message
Martin D (martin+sikuli) said :
#10

Yes, I noticed. I'm just using CMD+TAB now. Works fine for my needs.