Search in sources :

Example 1 with BasicJComboBoxCellReader

use of org.fest.swing.driver.BasicJComboBoxCellReader in project android by JetBrains.

the class ConfigureFormFactorStepFixture method selectMinimumSdkApi.

@NotNull
public ConfigureFormFactorStepFixture selectMinimumSdkApi(@NotNull final FormFactor formFactor, @NotNull final String api) {
    JCheckBox checkBox = robot().finder().find(target(), new GenericTypeMatcher<JCheckBox>(JCheckBox.class) {

        @Override
        protected boolean isMatching(@NotNull JCheckBox checkBox) {
            String text = checkBox.getText();
            // "startsWith" instead of "equals" because the UI may add "(Not installed)" at the end.
            return text != null && text.startsWith(formFactor.toString());
        }
    });
    AbstractButtonDriver buttonDriver = new AbstractButtonDriver(robot());
    buttonDriver.requireEnabled(checkBox);
    buttonDriver.select(checkBox);
    final JComboBox comboBox = robot().finder().findByName(target(), formFactor.id + ".minSdk", JComboBox.class);
    int itemIndex = GuiQuery.getNonNull(() -> {
        BasicJComboBoxCellReader cellReader = new BasicJComboBoxCellReader();
        int itemCount = comboBox.getItemCount();
        for (int i = 0; i < itemCount; i++) {
            String value = cellReader.valueAt(comboBox, i);
            if (value != null && value.startsWith("API " + api + ":")) {
                return i;
            }
        }
        return -1;
    });
    if (itemIndex < 0) {
        throw new LocationUnavailableException("Unable to find SDK " + api + " in " + formFactor + " drop-down");
    }
    JComboBoxDriver comboBoxDriver = new JComboBoxDriver(robot());
    comboBoxDriver.selectItem(comboBox, itemIndex);
    return this;
}
Also used : LocationUnavailableException(org.fest.swing.exception.LocationUnavailableException) AbstractButtonDriver(org.fest.swing.driver.AbstractButtonDriver) BasicJComboBoxCellReader(org.fest.swing.driver.BasicJComboBoxCellReader) JComboBoxDriver(org.fest.swing.driver.JComboBoxDriver) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractButtonDriver (org.fest.swing.driver.AbstractButtonDriver)1 BasicJComboBoxCellReader (org.fest.swing.driver.BasicJComboBoxCellReader)1 JComboBoxDriver (org.fest.swing.driver.JComboBoxDriver)1 LocationUnavailableException (org.fest.swing.exception.LocationUnavailableException)1 NotNull (org.jetbrains.annotations.NotNull)1