Search in sources :

Example 46 with SwingElementState

use of com.axway.ats.uiengine.utilities.swing.SwingElementState in project ats-framework by Axway.

the class SwingPopupMenu method getVisibleMenuLabels.

/**
     * Getting only visible menu labels/texts
     *
     * @return an array with the visible menu labels/texts only
     */
@PublicAtsApi
public String[] getVisibleMenuLabels() {
    new SwingElementState(this).waitToBecomeExisting();
    JPopupMenuFixture popupMenuFixture = (JPopupMenuFixture) SwingElementLocator.findFixture(this);
    String[] labels = popupMenuFixture.menuLabels();
    List<String> visibleLabels = new ArrayList<String>(labels.length);
    for (final String label : labels) {
        JMenuItemFixture menuItemFixture = popupMenuFixture.menuItem(new GenericTypeMatcher<JMenuItem>(JMenuItem.class, false) {

            @Override
            protected boolean isMatching(JMenuItem menuItem) {
                String text = menuItem.getText();
                if (text != null && text.equals(label)) {
                    return true;
                }
                return false;
            }
        });
        if (menuItemFixture != null && menuItemFixture.component().isVisible()) {
            visibleLabels.add(label);
        }
    }
    return visibleLabels.toArray(new String[0]);
}
Also used : JPopupMenuFixture(org.fest.swing.fixture.JPopupMenuFixture) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) ArrayList(java.util.ArrayList) JMenuItemFixture(org.fest.swing.fixture.JMenuItemFixture) JMenuItem(javax.swing.JMenuItem) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 47 with SwingElementState

use of com.axway.ats.uiengine.utilities.swing.SwingElementState in project ats-framework by Axway.

the class SwingSpinner method setValue.

/**
     * Set spinner text value (entering and committing the given text in the JSpinner)
     * @throws VerificationException if the element doesn't exist
     */
@PublicAtsApi
public void setValue(String value) {
    new SwingElementState(this).waitToBecomeExisting();
    JSpinnerFixture spinnerFixture = (JSpinnerFixture) SwingElementLocator.findFixture(this);
    int delayBetweenEvents = spinnerFixture.robot.settings().delayBetweenEvents();
    try {
        // enterTextAndCommit() method sets the text value using the Robot, so we will speed it up
        String delay = AtsSystemProperties.getPropertyAsString(AtsSystemProperties.UI_ENGINE__SWING_ROBOT_DELAY_BETWEEN_EVENTS);
        if (delay != null) {
            int ms = -1;
            try {
                ms = Integer.parseInt(delay);
            } catch (NumberFormatException ex) {
                log.error("Illegal robot dealy between events specified! Will be used default one", ex);
            }
            if (ms >= 0) {
                spinnerFixture.robot.settings().delayBetweenEvents(ms);
            }
        } else {
            // hardcode to 100ms
            spinnerFixture.robot.settings().delayBetweenEvents(100);
        }
        spinnerFixture.enterTextAndCommit(value);
    } finally {
        spinnerFixture.robot.settings().delayBetweenEvents(delayBetweenEvents);
    }
}
Also used : SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) JSpinnerFixture(org.fest.swing.fixture.JSpinnerFixture) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 48 with SwingElementState

use of com.axway.ats.uiengine.utilities.swing.SwingElementState 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 49 with SwingElementState

use of com.axway.ats.uiengine.utilities.swing.SwingElementState 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)

Example 50 with SwingElementState

use of com.axway.ats.uiengine.utilities.swing.SwingElementState in project ats-framework by Axway.

the class SwingTable method getSelectedRows.

/**
     * Get selected rows in the table
     *
     * @return an array with the selected rows
     * @throws VerificationException if the table element doesn't exist
     */
@PublicAtsApi
public int[] getSelectedRows() {
    new SwingElementState(this).waitToBecomeExisting();
    JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this);
    try {
        return tableFixture.component().getSelectedRows();
    } catch (Exception e) {
        throw new UiElementException(e.getMessage(), this);
    }
}
Also used : JTableFixture(org.fest.swing.fixture.JTableFixture) 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)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)60 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)60 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)16 JTableFixture (org.fest.swing.fixture.JTableFixture)16 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)12 TableCell (org.fest.swing.data.TableCell)12 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)11 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)11 VerifyEqualityException (com.axway.ats.uiengine.exceptions.VerifyEqualityException)10 JTreeFixture (org.fest.swing.fixture.JTreeFixture)8 JListFixture (org.fest.swing.fixture.JListFixture)7 JPopupMenuFixture (org.fest.swing.fixture.JPopupMenuFixture)5 JSpinnerFixture (org.fest.swing.fixture.JSpinnerFixture)4 ArrayList (java.util.ArrayList)2 ComponentDragAndDrop (org.fest.swing.core.ComponentDragAndDrop)2 JCheckBoxFixture (org.fest.swing.fixture.JCheckBoxFixture)2 JFileChooserFixture (org.fest.swing.fixture.JFileChooserFixture)2 JMenuItemFixture (org.fest.swing.fixture.JMenuItemFixture)2 JTabbedPaneFixture (org.fest.swing.fixture.JTabbedPaneFixture)2 JTableHeaderFixture (org.fest.swing.fixture.JTableHeaderFixture)2