use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method switchWindow.
/*
* TODO: Switching between test applications using CMD + TAB doesn't work on Mac
* cmd + tab moves between top level applications and multiple JavaFX applications launched by the testing framework
* are bundled under a single tab named Java.
*/
@RobotKeyword("Presses ALT/CMD + TAB for the given amount of times. \n\n" + "``switchAmount`` is an Integer value and specifies how many switches will be made in total")
@ArgumentNames({ "switchAmount" })
public void switchWindow(int switchAmount) {
robotLog("INFO", "Switching window for: \"" + Integer.toString(switchAmount) + "\" times.");
try {
if (isMac()) {
robot.press(KeyCode.META);
} else {
robot.press(KeyCode.ALT);
}
for (int i = 0; i < switchAmount; i++) {
robot.push(KeyCode.TAB);
}
robot.release(KeyCode.META);
robot.release(KeyCode.ALT);
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Unable to switch window.", e);
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method getTableColumnCells.
@RobotKeyword("Returns a list of *visible* cells(Nodes) of the given table column.\n\n" + "``locator`` is either a _query_ or _Object:Node_ for identifying the TableView element, see " + "`3. Locating or specifying UI elements`. \n\n" + "``column`` Integer value for the column")
@ArgumentNames({ "table", "column" })
public List<Object> getTableColumnCells(Object locator, int column) {
try {
TableView table = (TableView) objectToNode(locator);
List<Object> columnCells = new ArrayList<>();
VirtualFlow<?> vf = (VirtualFlow<?>) ((TableViewSkin<?>) table.getSkin()).getChildren().get(1);
for (int i = vf.getFirstVisibleCell().getIndex(); i < vf.getLastVisibleCell().getIndex() + 1; i++) {
robotLog("INFO", "index number: " + Integer.toString(i));
columnCells.add(mapObject(vf.getCell(i).getChildrenUnmodifiable().get(column)));
}
return mapObjects(columnCells);
} catch (ClassCastException cce) {
throw new JavaFXLibraryNonFatalException("Unable to handle argument as TableView!");
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method getPrimaryScreenBounds.
@RobotKeyword("Returns the bounds of primary screen. \n")
public Object getPrimaryScreenBounds() {
try {
robotLog("INFO", "Getting the primary screen bounds");
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
return mapObject(new BoundingBox(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()));
} catch (Exception e) {
throw new JavaFXLibraryNonFatalException("Unable to get primary screen bounds.", e);
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method getTableRowValues.
@RobotKeyword("Returns the given table row cells in a dictionary in form of name:node pairs. \n\n" + "``locator`` is either a _query_ or _Object:Node_ for identifying the TableView element, see " + "`3. Locating or specifying UI elements`. \n\n" + "``row`` Integer value for the column" + "\nExample:\n" + "| ${row cells}= | Get Table Row Cells | \\#table-id | ${2} | \n" + "| Dictionary Should Contain Key | ${row cells} | column name | \n" + "| ${cell text}= | Get Node Text | &{row cells}[column name] | # assuming that cell is a node that has a text value |\n")
@ArgumentNames({ "table", "row" })
public List<Object> getTableRowValues(Object locator, int rowNumber) {
robotLog("INFO", "Getting values from table row: " + rowNumber);
try {
TableView table = (TableView) objectToNode(locator);
Object row = table.getItems().get(rowNumber);
List<Object> values = new ArrayList<>();
for (Object tableColumn : table.getColumns()) {
values.add(((TableColumn) tableColumn).getCellObservableValue(row).getValue());
}
return values;
} catch (ClassCastException cce) {
throw new JavaFXLibraryNonFatalException("Unable to handle argument as TableView!");
}
}
use of javafxlibrary.exceptions.JavaFXLibraryNonFatalException in project JavaFXLibrary by eficode.
the class ConvenienceKeywords method getNodeText.
@RobotKeyword("Returns text value of the Node. \n\n" + "``locator`` is either a _query_ or _Object_ for a node whose getText method will be called, see " + "`3. Locating or specifying UI elements`. \n\n")
@ArgumentNames({ "locator" })
public String getNodeText(Object locator) {
Object node = objectToNode(locator);
// if(object instanceof String)
// object = robot.lookup((String)object).query();
robotLog("INFO", "Getting text value for node: \"" + node.toString() + "\"");
Class c = node.getClass();
try {
Method[] methods = c.getMethods();
for (Method m : methods) {
// There are two versions of getText: getText() and getText(int, int)
if (m.getName().equals("getText") && m.getParameterCount() == 0) {
robotLog("TRACE", "Calling method getText() for node: \"" + node.toString() + "\"");
try {
Object result = m.invoke(node);
return result.toString();
} catch (Exception e) {
// Return empty string in case cannot get text from node
return "";
// throw new JavaFXLibraryNonFatalException("Problem calling method getText() ", e);
}
}
}
throw new JavaFXLibraryNonFatalException("Get node text failed for node: \"" + node.toString() + "\". Node has no method getText().");
} catch (Exception e) {
if (e instanceof JavaFXLibraryNonFatalException)
throw e;
throw new JavaFXLibraryNonFatalException("Get node text failed for node: " + node.toString(), e);
}
}
Aggregations