Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsure of how to find JOptionPanes #237

Open
kedarabhyankar opened this issue Jul 16, 2019 · 5 comments
Open

Unsure of how to find JOptionPanes #237

kedarabhyankar opened this issue Jul 16, 2019 · 5 comments
Assignees
Labels

Comments

@kedarabhyankar
Copy link

Hi,

I'm unsure of how to set up a project built in JOptionPane - I have used reflective elements before, however, the issue lies in the fact that the program I'm testing requires certain actions to take place between frames (for example, hit the OK button on a JOptionPane before doing the next test). I know this is generally a broad question, but how would I go about doing this? Also, on a different note, I'm currently getting this error

/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=56676:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit5-rt.jar:/Users/kedarabhyankar/Documents/CS Development/180 F19/SimpleGUIF19Lab/out/production/SimpleGUIF19Lab:/Library/Java/JavaVirtualMachines/libs/jemmy-2.3.0.0.jar:/Library/Java/JavaVirtualMachines/libs/remotecontent.jar:/Library/Java/JavaVirtualMachines/libs/hamcrest-all-1.3.jar:/Library/Java/JavaVirtualMachines/libs/assertj-swing-3.9.2.jar:/Library/Java/JavaVirtualMachines/libs/assertj-core-3.12.2.jar:/Library/Java/JavaVirtualMachines/libs/assertj-swing-junit-3.9.2.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 HackathonSignupFormTest
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.assertj.swing.dependency.fest_reflect.util.Accessibles$SetAccessibleAction (file:/Library/Java/JavaVirtualMachines/libs/assertj-swing-3.9.2.jar) to method javax.swing.SwingUtilities.appContextGet(java.lang.Object)
WARNING: Please consider reporting this to the maintainers of org.assertj.swing.dependency.fest_reflect.util.Accessibles$SetAccessibleAction
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

upon running of a test, and I'm unsure of what this means. My test simply runs the main code via
application(ApplicationName.class).start();

and then runs the tests accordingly.

Any help would be appreciated. Thanks!

@croesch
Copy link
Collaborator

croesch commented Jul 17, 2019

Hi @kedarabhyankar

Thanks for your question, please open a separate issue for the illegal access - then it's easier to get the overview of the issues ;-)

Regarding JOptionPane have a look at JOptionPaneFinder - it should point you to the correct code to use.

Also have a look at the example code SimpleCopyApplication_UseBaseTest.java it should give you an understanding of how to use AssertJ Swing.

Does this answer your question?

@kedarabhyankar
Copy link
Author

I saw this, but the issue lied in the fact that one test would execute and work fine for the first screen - however, when I would run the second test, which would check the second screen, it would fail since the program would terminate (due to the end of the test), and restart, causing the test to fail since the first screen is not at all close to the second screen. Does that highlight my situation @croesch ?

@croesch
Copy link
Collaborator

croesch commented Jul 17, 2019

So you have like several pages and want to test each page separately but your test setup starts the application at page 1 and stops the application after test? So your second test does not start in the correct state of the application?

I would suggest the following:

  • allow to start your application in page 2 by changing the code
  • don't ever rely on the order of test executions
  • keep the tests separated for the different pages
  • one test might cover the navigation over all pages

@kedarabhyankar
Copy link
Author

@croesch, How do I make it so the JOptionPaneFinder will find the correct JOptionPane? Can I make it so it finds one with a specific name, or a specific message? Otherwise, wouldn't it only find the first one?

Let me re-explain:
I have a set of windows that show via JOptionPanes. Basically, the first window shows, and I want to do some tests on that. Then, that test verifies whether the name and message and type of JOptionPane match. Then, the test should end.

Now, I have another test. This test is checking the second window that shows up. This has a completely different title, completely different type of JOptionPane, and appears after I click the OK button on the JOptionPane that shows up as the first window. How can I test this second windows properties? And, would the same logic apply for testing the third, fourth, fifth, sixth, and n-th windows?

@croesch
Copy link
Collaborator

croesch commented Jul 19, 2019

Tests get a lot worse (in terms of stability) if you make a chain of them. So if the test of the second window would rely on the first window to show up and pass properly you would make both tests fail if window one has a problem.

In general I would suggest making a change to your application: Allow to start window two programmatically and start only this window for your test. Do so for all windows and keep the test short, simple and stable.

Please read the JavaDoc to see the usage and how to find JOptionPanes by name, type, text or whatever you can imagine. It's possible - but I'm not going to write the code here, because it's well documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants