-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Scrollingthroughentrylisttest #1361
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package net.sf.jabref.gui; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import net.sf.jabref.JabRefMain; | ||
|
||
import org.assertj.swing.fixture.AbstractWindowFixture; | ||
import org.assertj.swing.fixture.FrameFixture; | ||
import org.assertj.swing.fixture.JFileChooserFixture; | ||
import org.assertj.swing.fixture.JTableFixture; | ||
import org.assertj.swing.image.ScreenshotTaker; | ||
import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; | ||
import org.assertj.swing.timing.Pause; | ||
import org.junit.Assert; | ||
|
||
import static org.assertj.swing.finder.WindowFinder.findFrame; | ||
import static org.assertj.swing.launcher.ApplicationLauncher.application; | ||
|
||
public abstract class AbstractUITest extends AssertJSwingJUnitTestCase { | ||
|
||
protected final static int SPEED_NORMAL = 50; | ||
|
||
protected AWTExceptionHandler awtExceptionHandler; | ||
protected FrameFixture mainFrame; | ||
|
||
@Override | ||
protected void onSetUp() { | ||
awtExceptionHandler = new AWTExceptionHandler(); | ||
awtExceptionHandler.installExceptionDetectionInEDT(); | ||
application(JabRefMain.class).start(); | ||
|
||
robot().waitForIdle(); | ||
|
||
robot().settings().timeoutToFindSubMenu(1_000); | ||
robot().settings().delayBetweenEvents(SPEED_NORMAL); | ||
|
||
mainFrame = findFrame(JabRefFrame.class).withTimeout(10_000).using(robot()); | ||
robot().waitForIdle(); | ||
} | ||
|
||
/** | ||
* Returns the absolute Path of the given relative Path | ||
* The backlashes are replaced with forwardslashes b/c assertJ can't type the former one on windows | ||
* @param relativePath the relative path to the resource database | ||
*/ | ||
protected String getAbsolutePath(String relativePath) { | ||
final URL resource = this.getClass().getClassLoader().getResource(relativePath); | ||
try { | ||
return Paths.get(resource.toURI()).toAbsolutePath().toString().replace("\\", "/"); | ||
} catch (URISyntaxException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* opens a database and gives JabRef a second to open it before proceeding | ||
*/ | ||
protected void importBibIntoNewDatabase(String path) { | ||
mainFrame.menuItemWithPath("File", "Import into new database").click(); | ||
JFileChooserFixture openFileDialog = mainFrame.fileChooser(); | ||
robot().settings().delayBetweenEvents(1); | ||
openFileDialog.fileNameTextBox().enterText(path); | ||
openFileDialog.approve(); | ||
Pause.pause(1_000); | ||
} | ||
|
||
protected void exitJabRef() { | ||
mainFrame.menuItemWithPath("File", "Quit").click(); | ||
awtExceptionHandler.assertNoExceptions(); | ||
} | ||
|
||
protected void newDatabase() { | ||
mainFrame.menuItemWithPath("File", "New BibTeX database").click(); | ||
} | ||
|
||
protected void closeDatabase() { | ||
mainFrame.menuItemWithPath("File", "Close database").click(); | ||
} | ||
|
||
protected void takeScreenshot(AbstractWindowFixture<?, ?, ?> dialog, String filename) throws IOException { | ||
ScreenshotTaker screenshotTaker = new ScreenshotTaker(); | ||
Path folder = Paths.get("build", "screenshots"); | ||
// Create build/srceenshots folder if not present | ||
if (!Files.exists(folder)) { | ||
Files.createDirectory(folder); | ||
} | ||
Path file = folder.resolve(filename + ".png").toAbsolutePath(); | ||
// Delete already present file | ||
if (Files.exists(file)) { | ||
Files.delete(file); | ||
} | ||
screenshotTaker.saveComponentAsPng(dialog.target(), file.toString()); | ||
} | ||
|
||
protected void assertColumnValue(JTableFixture table, int rowIndex, int columnIndex, String selectionValue){ | ||
String[][] tableContent; | ||
tableContent = table.contents(); | ||
|
||
String value = tableContent[rowIndex][columnIndex]; | ||
Assert.assertEquals(value, selectionValue); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.sf.jabref.gui; | ||
|
||
import java.awt.event.KeyEvent; | ||
import java.util.regex.Pattern; | ||
|
||
import org.assertj.swing.fixture.JTableCellFixture; | ||
import org.assertj.swing.fixture.JTableFixture; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Specific Use-Case: | ||
* I import a database. Then I doubleclick on the first entry in the table to open the entry editor. | ||
* Then I click on the first entry again, and scroll through all of the lists entries, without having to click | ||
* on the table again. | ||
*/ | ||
public class EntryTableTest extends AbstractUITest{ | ||
|
||
private final static int SCROLL_ACTION_EXECUTION = 5; | ||
private final static String TEST_FILE_NAME = "testbib/testjabref.bib"; | ||
private final static int DOWN = KeyEvent.VK_DOWN; | ||
private final static int UP = KeyEvent.VK_UP; | ||
private final static int TITLE_COLUMN_INDEX = 5; | ||
|
||
@Test | ||
public void scrollThroughEntryList() { | ||
String path = getAbsolutePath(TEST_FILE_NAME); | ||
|
||
importBibIntoNewDatabase(path); | ||
|
||
JTableFixture entryTable = mainFrame.table(); | ||
|
||
//use a pattern from the first row to select it since it seems to be the best way to get the cell object | ||
Pattern pattern = Pattern.compile("256.*"); | ||
JTableCellFixture firstCell = entryTable.cell(pattern); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice if you would found out a way to always select the first cell and that it not depends on the content. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried using entryTable().selectRows(0) but that did not set the focus right. The pattern seems to be the easiest way to get the cell object. |
||
|
||
entryTable.selectRows(0).doubleClick(); | ||
//delay has to be shortened so that double click is recognized | ||
robot().settings().delayBetweenEvents(0); | ||
firstCell.doubleClick(); | ||
robot().settings().delayBetweenEvents(SPEED_NORMAL); | ||
|
||
firstCell.click(); | ||
//is the first table entry selected? | ||
assertColumnValue(entryTable, 0, TITLE_COLUMN_INDEX, entryTable.selectionValue()); | ||
|
||
//go throught the table and check if the entry with the correct index is selected | ||
for (int i=0; i < SCROLL_ACTION_EXECUTION; i++) { | ||
robot().pressAndReleaseKey(DOWN); | ||
Assert.assertTrue(entryTable.selectionValue() != null); | ||
assertColumnValue(entryTable, i+1, TITLE_COLUMN_INDEX, entryTable.selectionValue()); | ||
} | ||
//do the same going up again | ||
for (int i = SCROLL_ACTION_EXECUTION; i > 0; i--) { | ||
robot().pressAndReleaseKey(UP); | ||
Assert.assertTrue(entryTable.selectionValue() != null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you assert that the selected value is the actual number X from the bib file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it sufficient to check if the value in the selected row is the same as in the row with the next index? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you need to be sure that the next entry is selected, not that any entry is selected. |
||
assertColumnValue(entryTable, i-1, TITLE_COLUMN_INDEX, entryTable.selectionValue()); | ||
} | ||
|
||
closeDatabase(); | ||
exitJabRef(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for extracting this