use of com.axway.ats.uiengine.internal.driver.SwingDriverInternal in project ats-framework by Axway.
the class SwingElementLocator method findElement.
@SuppressWarnings("unchecked")
private static <T extends Component> T findElement(UiElement uiElement) {
SwingDriverInternal driver = (SwingDriverInternal) uiElement.getUiDriver();
ContainerFixture<? extends Container> containerFixture = driver.getActiveContainerFixture();
Class<? extends Component> componentClass = null;
String exactClassName = uiElement.getElementProperties().getProperty("class");
if (exactClassName != null) {
try {
componentClass = (Class<? extends Component>) SwingElementLocator.class.getClassLoader().loadClass(exactClassName);
} catch (ClassNotFoundException ex) {
throw new ElementNotFoundException("Could not load UI Component class named " + exactClassName + ". Probably it is not in the classpath or the name is invalid. Cause message: " + ex.getMessage(), ex);
}
} else {
componentClass = componentsMap.get(uiElement.getClass());
}
try {
boolean requireVisible = true;
if (uiElement.getElementProperty("visible") != null) {
requireVisible = Boolean.parseBoolean(uiElement.getElementProperty("visible").trim());
}
// Finding components by their associated labels ( someJLabel.setLabelFor( someComponent ) )
if (uiElement.getElementProperty("label") != null) {
return (T) containerFixture.robot.finder().findByLabel(containerFixture.component(), uiElement.getElementProperty("label"), componentClass, requireVisible);
}
return (T) SwingElementFinder.find(containerFixture.robot, containerFixture.component(), buildLocator(componentClass, uiElement.getElementProperties(), requireVisible, uiElement.getPropertyNamesToUseForMatch()));
} catch (ComponentLookupException cle) {
if (cle.getMessage().startsWith("Found more than one ")) {
throw new MoreThanOneSuchElementException(cle.getMessage() + "\n" + uiElement.toString(), cle);
}
Window win = driver.getWindowFixture().component();
Container currentContainer = containerFixture.component();
String winTitle;
if (win instanceof Dialog) {
winTitle = "'" + ((Dialog) win).getTitle() + "'";
} else if (win instanceof Frame) {
winTitle = "'" + ((Frame) win).getTitle() + "'";
} else {
winTitle = "N/A";
}
String containerMsg = null;
if (win.equals(currentContainer)) {
containerMsg = "[same as window]";
}
if (log.isDebugEnabled()) {
// more verbose trace
throw new ElementNotFoundException(uiElement.toString() + " not found.\n" + "Current container: " + (containerMsg != null ? containerMsg : currentContainer.toString()) + "\n" + "Current window: window title " + winTitle + "( details: " + win.toString() + ")", cle);
} else {
// /light message
throw new ElementNotFoundException(uiElement.toString() + " not found.\n" + "Current container name: " + (containerMsg != null ? containerMsg : currentContainer.getName()) + "\n" + "Current window: window title " + winTitle, cle);
}
}
}
use of com.axway.ats.uiengine.internal.driver.SwingDriverInternal in project ats-framework by Axway.
the class SwingElementLocator method findFixture.
public static ComponentFixture<? extends Component> findFixture(UiElement uiElement) {
SwingDriverInternal driver = (SwingDriverInternal) uiElement.getUiDriver();
ContainerFixture<?> containerFixture = (ContainerFixture<?>) driver.getActiveContainerFixture();
Class<? extends Component> componentClass = componentsMap.get(uiElement.getClass());
try {
if (componentClass.equals(JButton.class)) {
return (ComponentFixture<? extends Component>) new JButtonFixture(containerFixture.robot, (JButton) findElement(uiElement));
} else if (componentClass.equals(JTextComponent.class)) {
return (ComponentFixture<? extends Component>) new JTextComponentFixture(containerFixture.robot, (JTextComponent) findElement(uiElement));
} else if (componentClass.equals(JMenuItem.class)) {
if (uiElement.getElementProperty("path") != null) {
return containerFixture.menuItemWithPath(uiElement.getElementProperty("path").split("[\\,\\/]+"));
} else {
return (ComponentFixture<? extends Component>) new JMenuItemFixture(containerFixture.robot, (JMenuItem) findElement(uiElement));
}
} else if (componentClass.equals(JPopupMenu.class)) {
return (ComponentFixture<? extends Component>) new JPopupMenuFixture(containerFixture.robot, (JPopupMenu) findElement(uiElement));
} else if (componentClass.equals(JTree.class)) {
return (ComponentFixture<? extends Component>) new JTreeFixture(containerFixture.robot, (JTree) findElement(uiElement));
} else if (componentClass.equals(JList.class)) {
return (ComponentFixture<? extends Component>) new JListFixture(containerFixture.robot, (JList) findElement(uiElement));
} else if (componentClass.equals(JCheckBox.class)) {
return (ComponentFixture<? extends Component>) new JCheckBoxFixture(containerFixture.robot, (JCheckBox) findElement(uiElement));
} else if (componentClass.equals(JToggleButton.class)) {
return (ComponentFixture<? extends Component>) new JToggleButtonFixture(containerFixture.robot, (JToggleButton) findElement(uiElement));
} else if (componentClass.equals(JComboBox.class)) {
return (ComponentFixture<? extends Component>) new JComboBoxFixture(containerFixture.robot, (JComboBox) findElement(uiElement));
} else if (componentClass.equals(JRadioButton.class)) {
return (ComponentFixture<? extends Component>) new JRadioButtonFixture(containerFixture.robot, (JRadioButton) findElement(uiElement));
} else if (componentClass.equals(JTable.class)) {
return (ComponentFixture<? extends Component>) new JTableFixture(containerFixture.robot, (JTable) findElement(uiElement));
} else if (componentClass.equals(JSpinner.class)) {
return (ComponentFixture<? extends Component>) new JSpinnerFixture(containerFixture.robot, (JSpinner) findElement(uiElement));
} else if (componentClass.equals(JTabbedPane.class)) {
return (ComponentFixture<? extends Component>) new JTabbedPaneFixture(containerFixture.robot, (JTabbedPane) findElement(uiElement));
} else if (componentClass.equals(JOptionPane.class)) {
return (ComponentFixture<? extends Component>) containerFixture.optionPane();
} else if (componentClass.equals(JLabel.class)) {
return (ComponentFixture<? extends Component>) new JLabelFixture(containerFixture.robot, (JLabel) findElement(uiElement));
} else if (componentClass.equals(Component.class)) {
return new ComponentFixture<Component>(containerFixture.robot, findElement(uiElement)) {
};
} else if (componentClass.equals(JFileChooser.class)) {
// TODO - might be searched by name too
return containerFixture.fileChooser(Timeout.timeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()));
} else {
throw new ElementNotFoundException(uiElement.toString() + " not found. No such Fixture");
}
} catch (ComponentLookupException cle) {
throw new ElementNotFoundException(uiElement.toString() + " not found.", cle);
} catch (WaitTimedOutError exc) {
// thrown for OptionPane search, wait for Window (BasicRobot.waitForWindow), AbstractJTableCellWriter, JTreeDriver.waitForChildrenToShowUp, each Pause wait
throw new ElementNotFoundException(uiElement.toString() + " not found.", exc);
}
}
Aggregations