JFileChooserFixture.selectFile() fails if called twice in OSX
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- desktop, testing-qa
Research direction
Start by reproducing the supplied FileChooserTest on macOS, especially the second call to selectFile(), then inspect JFileChooserFixture.selectFile() and the related file-chooser fixture tests. Done means the same file can be selected and approved successfully on the second invocation as well as the first, without breaking Windows behavior.
Written by the indexing model from the issue text.
Description
Hi,
The following second Test fails on OSX. On Windows it works like expected. It might be a Swing issue in the MAC VM.
import java.io.File;
import org.assertj.swing.core.Robot;
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.edt.GuiQuery;
import org.assertj.swing.finder.JFileChooserFinder;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.fixture.JFileChooserFixture;
import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
import org.junit.Test;
public class FileChooserTest extends AssertJSwingJUnitTestCase {
protected FrameFixture window;
protected Robot robot;
@Override
protected void onSetUp() {
FileChooserFrame mainFrame = GuiActionRunner
.execute(new GuiQuery<FileChooserFrame>() {
protected FileChooserFrame executeInEDT() {
return new FileChooserFrame();
}
});
robot = robot();
window = new FrameFixture(robot, mainFrame);
}
@Test
public void openFileChooser() {
selectFile();
}
@Test
public void openFileChooserAgain() {
selectFile();
}
private void selectFile() {
String seperator = System.getProperty("file.separator");
String currentDir = new File("").getAbsolutePath() + seperator + "src";
String filePath = currentDir + seperator + "FileChooserFrame.java";
window.button().click();
JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser()
.using(robot);
fileChooser.setCurrentDirectory(new File(currentDir));
fileChooser.selectFile(new File(filePath));
fileChooser.approve();
window.textBox().requireText(filePath);
}
}
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class FileChooserFrame extends JFrame {
public FileChooserFrame() {
setSize(200, 100);
setTitle(getClass().getCanonicalName());
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new FlowLayout());
JTextField textField = new JTextField();
textField.setPreferredSize(new Dimension(200, 20));
JButton button = new JButton("FileChooser");
JFrame parentFrame = this;
button.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
int returnVal = fileChooser.showOpenDialog(parentFrame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
textField.setText(file.getAbsolutePath());
}
}
});
add(textField);
add(button);
setVisible(true);
}
public static void main(String[] args) {
new FileChooserFrame();
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>AssertJSwingTest</groupId>
<artifactId>AssertJSwingTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-swing-junit</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
</project>
- Dominant language
- Java
- Stars
- 121
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from assertj/assertj-swing
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
assertj/assertj-swing#279 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
assertj/assertj-swing#278 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
assertj/assertj-swing#276 · 1 comment ·
-
Update unit test to avoid deprecated `ExpectedException.none()` by using `Assert.assertThrows()` Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
assertj/assertj-swing#275 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
assertj/assertj-swing#277 · 1 comment ·
All issues in assertj/assertj-swing
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
1.0.0-alpha2 Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#272 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
apache/rocketmq-dashboard#4860 · 1 comment ·
-
agent-audit bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Vault-Web/cloud-page#144 ·