16

I need to create some gui tests using Jemmy but I have no idea how to launch it with javaws application. In tutorials/examples/etc is something like that:

new ClassReference("org.netbeans.jemmy.explorer.GUIBrowser")
                                                        .startApplication();

This code opens an example window, but how can I, using ClassReference object open *.jnlp file? Or is it another way to "connect" jemmy with java web start application?

Thanks for advance.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
mlethys
  • 436
  • 9
  • 29

3 Answers3

5

You can achieve this by preparing special build with Jemmy included and call Jemmy from the app run in jnlp mode itself.

Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
  • 1
    Could you please provide a little bit more information about this solution: "special build with Jemmy included" - do i need to do any coding in AUT or just need to add jemmy.jar to build path; "call Jemmy from the app run in jnlp mode" - what do you mean by this, any code examples? – Ivan Gerasimenko Jun 27 '16 at 09:22
  • @IvanGerasimenko, I meant bundling jemmy.jar with your application. Not only on build phase, but on deploy as well. It's an easiest way to overcome the security complexities of the web start. After that you can call Jemmy whatever way you want from your code. – Sergey Grinev Jun 27 '16 at 14:45
  • "After that you can call Jemmy whatever way you want from your code" you mean call Jemmy from code of Application Under Test? – Ivan Gerasimenko Jun 28 '16 at 15:15
2

The solution is:

  1. Place build files into any folder on your PC.
  2. Add .jar files from this build to your testing project.
  3. Open .jnlp file in text editor and search for main application class
    application-desc main-class="[Main application class]"/>
  4. Call it from you test to launch app
    new ClassReference("[Main application class]").startApplication();

Now you can access elements of this Java app from test environment

Ivan Gerasimenko
  • 2,381
  • 3
  • 30
  • 46
1

You can use Jemmy with JUnit in NetBeans IDE.

For the GUI testing we are using Jemmy, a library that comes with the NetBeans IDE and is very useful for testing Swing applications.

JUnit tests that utilize Jemmy so for example:

@Test
public void JunitTest() {
JFrameOperator mainFrame = new JFrameOperator();
JTextFieldOperator textField = new JTextFieldOperator(mainFrame, "textIn");
int x = 10;
assertEquals(x, textField.getLocationOnScreen().x);
}

Adding the @Test annotation and making use of JUnit's assertEquals() and fail() if needed.


Another Approach:

You can also do it using jnlp. Already suggested @Sergey Grinev

A good example and running code is given in this link:

Snapshot:

  1. Click the jnlp file link in webdriver, save jnlp file to disk;
  2. Run the webstart app from jnlp;
  3. Capture opened app and use it for test.

This process can be done by using following libraries:

  • netx - for running webstart application from jnlp.
  • uispec4j - for intercepting created webstart window and manipulating window elements.

You can probably do the same trick with other AWT/Swing testing tool, but uispec4j allows to intercept webstart app executed from jnlp, you don't need to run the app by calling main() and you don't need to have your webstart app source code in your testing code repo.

Credit goes to tporeba

For learning more about Jemmy, you can go through this link

  1. Jemmy Tutorial
  2. Jemmy Samples
  3. NetBeans Platform Test Infrastructure Tutorial
Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132