JComboBoxFixture.selectItem don't always work as expected

Open
#211 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java
Domain
desktop, testing

Research direction

Reproduce the loop from the issue, including selection by index and text and the explicit-click workaround. Start at the JComboBoxFixture.selectItem entry point and investigate why selection sometimes remains at index 0. Done means repeated runs select the requested item reliably without requiring a preceding click.

Written by the indexing model from the issue text.

Description

Hi Joel.
First of all, thank you for your very interesting work. I've been using assertJ-core and assertJ-swing for several weeks now (and I like it a lot), but I'm experiencing random failures in my tests when playing with comboboxes.

Consider the following loop :

for (int i = 0; i < 10; i++) {
	GuiActionRunner.execute(() -> {
		JComboBox<String> combo = new JComboBox<>();
		combo.addItem("item_1");
		combo.addItem("item_2");
		jFrame = Containers.frameFor(combo);
		jFrame.setName(this.getClass().getName());
		jFrame.setVisible(true);
	});
	
	FrameFixture frame = new FrameFixture(jFrame);
	frame.comboBox().selectItem(1);
	frame.comboBox().requireSelection(1);    // **** randomly fails *****
	frame.cleanUp();
}

A ComparisonFailure is thrown most of the time, after a random number of iterations.

org.junit.ComparisonFailure: [javax.swing.JComboBox[name=null, selectedItem='item_1', contents=["item_1", "item_2"], editable=false, enabled=true, visible=true, showing=true] - property:'selectedIndex'] expected:<[1]> but was:<[0]>

I found a workaround by explicitly clicking on combo before selecting item.

	frame.comboBox().click().selectItem(1);

I noticed the problem whenever selecting items using index or text.
What do you think ? Am I missing something or is it actually an issue ?
Regards

Dominant language
Java
Stars
121
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-swing

All issues in assertj/assertj-swing

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.