Search in sources :

Example 11 with JTableFixture

use of org.fest.swing.fixture.JTableFixture in project android by JetBrains.

the class TranslationsEditorTest method enteringTextInTranslationTextFieldUpdatesTableCell.

@Test
public void enteringTextInTranslationTextFieldUpdatesTableCell() {
    JTableFixture table = myTranslationsEditor.getTable();
    TableCell cell = TableCell.row(2).column(3);
    table.selectCell(cell);
    myTranslationsEditor.getTranslationTextField().enterText("cancel_en");
    // Make the Translation text field lose focus
    myTranslationsEditor.getKeyTextField().focus();
    assertEquals("cancel_en", table.valueAt(cell));
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) Test(org.junit.Test)

Example 12 with JTableFixture

use of org.fest.swing.fixture.JTableFixture 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);
    }
}
Also used : JTreeFixture(org.fest.swing.fixture.JTreeFixture) JRadioButton(javax.swing.JRadioButton) SwingDriverInternal(com.axway.ats.uiengine.internal.driver.SwingDriverInternal) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JTextComponent(javax.swing.text.JTextComponent) JSpinnerFixture(org.fest.swing.fixture.JSpinnerFixture) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) JLabelFixture(org.fest.swing.fixture.JLabelFixture) JTabbedPaneFixture(org.fest.swing.fixture.JTabbedPaneFixture) JButtonFixture(org.fest.swing.fixture.JButtonFixture) JToggleButtonFixture(org.fest.swing.fixture.JToggleButtonFixture) JComboBoxFixture(org.fest.swing.fixture.JComboBoxFixture) JTableFixture(org.fest.swing.fixture.JTableFixture) JToggleButton(javax.swing.JToggleButton) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) ComponentFixture(org.fest.swing.fixture.ComponentFixture) JMenuItemFixture(org.fest.swing.fixture.JMenuItemFixture) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) JMenuItem(javax.swing.JMenuItem) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) JRadioButtonFixture(org.fest.swing.fixture.JRadioButtonFixture) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JPopupMenuFixture(org.fest.swing.fixture.JPopupMenuFixture) JListFixture(org.fest.swing.fixture.JListFixture) ContainerFixture(org.fest.swing.fixture.ContainerFixture) JTable(javax.swing.JTable) JSpinner(javax.swing.JSpinner) JCheckBoxFixture(org.fest.swing.fixture.JCheckBoxFixture) JList(javax.swing.JList)

Example 13 with JTableFixture

use of org.fest.swing.fixture.JTableFixture in project ats-framework by Axway.

the class SwingTable method rightClickCell.

/**
     * Right click on table cell
     *
     * @param row the row number
     * @param column the column number
     * @throws VerificationException if the table element doesn't exist
     */
@PublicAtsApi
public void rightClickCell(int row, int column) {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    try {
        tableFixture.cell(new TableCell(row, column) {
        }).rightClick();
    } catch (Exception e) {
        throw new UiElementException(e.getMessage(), this);
    }
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) VerifyNotEqualityException(com.axway.ats.uiengine.exceptions.VerifyNotEqualityException) VerifyEqualityException(com.axway.ats.uiengine.exceptions.VerifyEqualityException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 14 with JTableFixture

use of org.fest.swing.fixture.JTableFixture in project ats-framework by Axway.

the class SwingTable method getCellForegroundColor.

/**
     * Returns the table cell foreground {@link Color}
     *
     * @param row the row number
     * @param column the column number
     */
@PublicAtsApi
public Color getCellForegroundColor(int row, int column) {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    return tableFixture.foregroundAt(new TableCell(row, column) {
    }).target();
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 15 with JTableFixture

use of org.fest.swing.fixture.JTableFixture in project ats-framework by Axway.

the class SwingTable method getCellIndexesByValue.

/**
     * Get table cell coordinates by cell value
     *
     * @param value cell value to search for
     * @param isRegEx if the value is a regular expression
     * @return an {@link ArrayList} with cell coordinates(indexes) represented by arrays [ row, column ] which contains
     *  the searched value
     * @throws VerificationException if the table element doesn't exist
     */
@PublicAtsApi
public List<Integer[]> getCellIndexesByValue(String value, boolean isRegEx) {
    new SwingElementState(this).waitToBecomeExisting();
    List<Integer[]> results = new ArrayList<Integer[]>();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    try {
        if (value == null) {
            isRegEx = false;
        }
        Pattern regexPattern = null;
        if (isRegEx) {
            regexPattern = Pattern.compile(value);
        }
        for (int row = 0; row < tableFixture.target.getRowCount(); row++) {
            for (int column = 0; column < tableFixture.target.getColumnCount(); column++) {
                String cellValue = null;
                try {
                    cellValue = tableFixture.valueAt(new TableCell(row, column) {
                    });
                } catch (NullPointerException npe) {
                // valueAt() throws NPE if the cell is null
                }
                if (cellValue == null && value != null) {
                    continue;
                }
                if ((cellValue == null && value == null) || (isRegEx && regexPattern.matcher(cellValue).matches()) || (!isRegEx && cellValue.equals(value))) {
                    results.add(new Integer[] { row, column });
                }
            }
        }
    } catch (Exception e) {
        throw new UiElementException(e.getMessage(), this);
    }
    return results;
}
Also used : Pattern(java.util.regex.Pattern) JTableFixture(org.fest.swing.fixture.JTableFixture) TableCell(org.fest.swing.data.TableCell) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) ArrayList(java.util.ArrayList) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) VerifyNotEqualityException(com.axway.ats.uiengine.exceptions.VerifyNotEqualityException) VerifyEqualityException(com.axway.ats.uiengine.exceptions.VerifyEqualityException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) NotSupportedOperationException(com.axway.ats.uiengine.exceptions.NotSupportedOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

JTableFixture (org.fest.swing.fixture.JTableFixture)29 PublicAtsApi (com.axway.ats.common.PublicAtsApi)16 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)16 TableCell (org.fest.swing.data.TableCell)15 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)11 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)11 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)10 VerifyEqualityException (com.axway.ats.uiengine.exceptions.VerifyEqualityException)10 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)10 NotNull (org.jetbrains.annotations.NotNull)7 JTableCellFixture (org.fest.swing.fixture.JTableCellFixture)6 TableView (com.intellij.ui.table.TableView)4 JPopupMenuFixture (org.fest.swing.fixture.JPopupMenuFixture)3 ImmutableList (com.google.common.collect.ImmutableList)2 JTableHeaderFixture (org.fest.swing.fixture.JTableHeaderFixture)2 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)1 SwingDriverInternal (com.axway.ats.uiengine.internal.driver.SwingDriverInternal)1 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)1 Content (com.intellij.ui.content.Content)1 Color (java.awt.Color)1