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
Snapshot:
- Click the jnlp file link in webdriver, save jnlp file to disk;
- Run the webstart app from jnlp;
- 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
- Jemmy Tutorial
- Jemmy Samples
- NetBeans Platform Test Infrastructure Tutorial