Search in sources :

Example 1 with LocationUnavailableException

use of org.fest.swing.exception.LocationUnavailableException 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)

Example 2 with LocationUnavailableException

use of org.fest.swing.exception.LocationUnavailableException in project android by JetBrains.

the class IdeSettingsDialogFixture method selectSdkPage.

@NotNull
public IdeSettingsDialogFixture selectSdkPage() {
    JPanel optionsEditor = field("myEditor").ofType(JPanel.class).in(getDialogWrapper()).get();
    List<JComponent> trees = findComponentsOfType(optionsEditor, "com.intellij.openapi.options.newEditor.SettingsTreeView");
    JComponent tree = Iterables.getOnlyElement(trees);
    JTree jTree = field("myTree").ofType(JTree.class).in(tree).get();
    JTreeFixture jTreeFixture = new JTreeFixture(robot(), jTree);
    jTreeFixture.replaceCellReader(TREE_NODE_CELL_READER);
    // It takes a few seconds to load the whole tree.
    Wait.seconds(5).expecting("The desired path is loaded").until(() -> {
        try {
            jTreeFixture.selectPath("Appearance & Behavior/System Settings/Android SDK");
            return true;
        } catch (LocationUnavailableException e) {
            return false;
        }
    });
    return this;
}
Also used : JTreeFixture(org.fest.swing.fixture.JTreeFixture) LocationUnavailableException(org.fest.swing.exception.LocationUnavailableException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LocationUnavailableException

use of org.fest.swing.exception.LocationUnavailableException in project ats-framework by Axway.

the class SwingComboBox method setValue.

/**
 * Set ComboBox value
 * @param value the ComboBox value to set
 * @throws VerificationException if the element doesn't exist
 */
@SuppressWarnings("unchecked")
@Override
@PublicAtsApi
public void setValue(String value) {
    new SwingElementState(this).waitToBecomeExisting();
    JComboBoxFixture comboBoxFixture = null;
    try {
        comboBoxFixture = ((JComboBoxFixture) SwingElementLocator.findFixture(this));
        comboBoxFixture.selectItem(value);
    } catch (LocationUnavailableException lue) {
        // if the element is editable we'll enter the new value
        if (comboBoxFixture != null && comboBoxFixture.component().isEditable()) {
            try {
                comboBoxFixture.component().addItem(value);
                comboBoxFixture.selectItem(value);
            } catch (LocationUnavailableException e) {
                throw new UiElementException(e.getMessage(), this);
            }
        } else {
            throw new UiElementException(lue.getMessage(), this);
        }
    }
}
Also used : JComboBoxFixture(org.fest.swing.fixture.JComboBoxFixture) LocationUnavailableException(org.fest.swing.exception.LocationUnavailableException) SwingElementState(com.axway.ats.uiengine.utilities.swing.SwingElementState) UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with LocationUnavailableException

use of org.fest.swing.exception.LocationUnavailableException in project android by JetBrains.

the class CapturesToolWindowFixture method openFile.

public void openFile(@NotNull final String fileName) throws IOException {
    String pathName = null;
    CaptureType[] captureTypes = CaptureTypeService.getInstance().getCaptureTypes();
    for (CaptureType captureType : captureTypes) {
        if (captureType instanceof FileCaptureType) {
            FileCaptureType fileCaptureType = (FileCaptureType) captureType;
            if (fileCaptureType.isValidCapture(fileName)) {
                pathName = fileCaptureType.getName();
                break;
            }
        }
    }
    if (pathName != null) {
        final String finalPathName = pathName;
        Wait.seconds(1).expecting("the file to be recognized").until(() -> {
            try {
                String fileToSelect = finalPathName + "/" + fileName;
                myTreeFixture.selectPath(fileToSelect);
                // TODO: Use mouse clicks instead of the keyboard when the fixture responds correctly to double clicks,
                //       as this will better model how users interact with the feature in practice.
                myTreeFixture.pressAndReleaseKey(KeyPressInfo.keyCode(KeyEvent.VK_ENTER));
                return true;
            } catch (LocationUnavailableException e) {
                return false;
            }
        });
    }
}
Also used : FileCaptureType(com.android.tools.idea.profiling.capture.FileCaptureType) CaptureType(com.android.tools.idea.profiling.capture.CaptureType) FileCaptureType(com.android.tools.idea.profiling.capture.FileCaptureType) LocationUnavailableException(org.fest.swing.exception.LocationUnavailableException)

Aggregations

LocationUnavailableException (org.fest.swing.exception.LocationUnavailableException)4 NotNull (org.jetbrains.annotations.NotNull)2 CaptureType (com.android.tools.idea.profiling.capture.CaptureType)1 FileCaptureType (com.android.tools.idea.profiling.capture.FileCaptureType)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)1 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)1 AbstractButtonDriver (org.fest.swing.driver.AbstractButtonDriver)1 BasicJComboBoxCellReader (org.fest.swing.driver.BasicJComboBoxCellReader)1 JComboBoxDriver (org.fest.swing.driver.JComboBoxDriver)1 JComboBoxFixture (org.fest.swing.fixture.JComboBoxFixture)1 JTreeFixture (org.fest.swing.fixture.JTreeFixture)1