assertj / assertj/assertj-swing

JFileChooserFixture.selectFile() fails if called twice in OSX

Offen
#191 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
OS X
Vorherrschende Sprache
Java
Sterne
121
Forks
52
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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() {

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();
}
}
```

```

4.0.0
AssertJSwingTest
AssertJSwingTest
0.0.1-SNAPSHOT

src


maven-compiler-plugin
3.3

1.8
1.8






org.assertj
assertj-swing-junit
3.1.1

```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, den bereitgestellten FileChooserTest unter macOS zu reproduzieren, insbesondere den zweiten Aufruf von selectFile(), und untersuche anschließend JFileChooserFixture.selectFile() sowie die zugehörigen File-Chooser-Fixture-Tests. Als erledigt gilt die Aufgabe, wenn dieselbe Datei auch beim zweiten Aufruf wie beim ersten erfolgreich ausgewählt und bestätigt werden kann, ohne das Verhalten unter Windows zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
desktop, testing-qa
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
32/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.