org.netbeans.jemmy.operators.JFrameOperator Java Examples

The following examples show how to use org.netbeans.jemmy.operators.JFrameOperator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToggleButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void testToggleButtons(JFrameOperator jfo) {
    ComponentChooser directionPanelChooser = new ByClassChooser(DirectionPanel.class);

    String text_Position = LayoutControlPanel.TEXT_POSITION;
    ContainerOperator<?> textPositionContainer = getLabeledContainerOperator(jfo, text_Position);
    ContainerOperator<?> directionPanelOperator = new ContainerOperator<>(textPositionContainer, directionPanelChooser);
    testRadioButtons(directionPanelOperator, 9, (t, i) -> i == 5);

    // Unfortunately, both directionPanels are in the same parent container
    // so we have to use indexes here.
    // There is no guarantee that if the UI changes, the code would be still
    // valid in terms of which directionPanel is checked first. However, it
    // does guarantee that two different directionPanels are checked.
    String content_Alignment = LayoutControlPanel.CONTENT_ALIGNMENT;
    ContainerOperator<?> contentAlignmentContainer = getLabeledContainerOperator(jfo, content_Alignment);
    ContainerOperator<?> directionPanelOperator2 = new ContainerOperator<>(contentAlignmentContainer, directionPanelChooser,
            contentAlignmentContainer.getSource() == textPositionContainer.getSource() ? 1 : 0);
    testRadioButtons(directionPanelOperator2, 9, (t, i) -> i == 4);

}
 
Example #2
Source File: OptionPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void showConfirmationDialog(JFrameOperator jfo) throws Exception {
    // Case: Yes option selected
    {
        callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, YES);
        checkMessage(CONFIRM_YES);
    }

    // Case: No option selected
    {
        callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, NO);
        checkMessage(CONFIRM_NO);
    }

    // Case: Cancel option selected
    {
        callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, CANCEL);
        //TODO: wait for no dialog displayed
    }
}
 
Example #3
Source File: SliderDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void minorTicks(JFrameOperator jfo, String accessibleName) {
    JSliderOperator jso = new JSliderOperator(jfo,
            new AccessibleNameChooser(accessibleName));
    if (accessibleName.equals(HORIZONTAL_MINOR_TICKS_SLIDER)) {
        checkMaximum(jso, HORIZONTAL_MINOR_TICKS_SLIDER_MAXIMUM);
        checkMinimum(jso, HORIZONTAL_MINOR_TICKS_SLIDER_MINIMUM);
        checkMoveForward(jso, 2);
        checkSnapToTick(jso, 5, 6);
        assertEquals(5, jso.getMajorTickSpacing());
        assertEquals(1, jso.getMinorTickSpacing());
    } else {
        checkMaximum(jso, VERTICAL_MINOR_TICKS_SLIDER_MAXIMUM);
        checkMinimum(jso, VERTICAL_MINOR_TICKS_SLIDER_MINIMUM);
        checkMoveForward(jso, 10);
        assertEquals(20, jso.getMajorTickSpacing());
        assertEquals(5, jso.getMinorTickSpacing());
    }
    assertTrue(jso.getPaintTicks());
    assertTrue(jso.getPaintLabels());
}
 
Example #4
Source File: SpinnerDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void changeValues(JFrameOperator jfo, int spinnerIndex) throws Exception {
    JSpinnerOperator spinner = new JSpinnerOperator(jfo, spinnerIndex);
    JTextFieldOperator jtfo = new JTextFieldOperator(spinner);
    float originalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
    float finalFieldValue;

    // increment by one the value via spinner
    spinner.getIncreaseOperator().push();
    finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();

    // check that the value was increased
    assertTrue("Increment Spinner " + spinner
            + " (originalFieldValue, actual value: " + originalFieldValue + " "
            + "< finalFieldValue, actual value = " + finalFieldValue + ")",
            originalFieldValue < finalFieldValue);

    // decrease value via spinner
    spinner.getDecreaseOperator().push();
    finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();

    // check that the value was decrimented
    assertTrue("Decrement Spinner " + spinner
            + " (originalFieldValue, actual value: " + originalFieldValue + " "
            + ">= finalFieldValue, actual value = " + finalFieldValue + ")",
            originalFieldValue >= finalFieldValue);
}
 
Example #5
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void stepChooseComponet( String name, TestData data )
{
    JFrameOperator installerMain = new JFrameOperator(MAIN_FRAME_TITLE);

    new JButtonOperator(installerMain, "Customize...").push();
    JDialogOperator customizeInstallation = new JDialogOperator("Customize Installation");
    JListOperator featureList = new JListOperator(customizeInstallation);
    featureList.selectItem(name);

    featureList.pressKey(KeyEvent.VK_SPACE);

    // Check prelude
    data.m_bPreludePresents = ( -1 != featureList.findItemIndex( "Prelude" ) );

    new JButtonOperator(customizeInstallation, "OK").push();
}
 
Example #6
Source File: ProgressBarDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(ProgressBarDemo.class.getCanonicalName()).startApplication();

    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);

    JButtonOperator startButton = new JButtonOperator(frame, START_BUTTON);
    JButtonOperator stopButton = new JButtonOperator(frame, STOP_BUTTON);
    JProgressBarOperator jpbo = new JProgressBarOperator(frame);

    // Check that progress completes and corect enable/disable of start/stop buttons
    checkCompleteProgress(frame, startButton, stopButton, jpbo);

    // Check progess bar progression and start/stop button disabled/enabled states
    checkStartStop(frame, startButton, stopButton, jpbo);
}
 
Example #7
Source File: ListDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) {

        // We map first half of indexes to the Prefixes panel and the second half
        // to the Suffixes panel
        String labelText;
        int subindex;
        if (index < CHECKBOX_COUNT / 2) {
            labelText = "Prefixes";
            subindex = index;
        } else {
            labelText = "Suffixes";
            subindex = index - CHECKBOX_COUNT / 2;
        }

        JCheckBoxOperator result = new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex);
        result.setVerification(true);
        return result;
    }
 
Example #8
Source File: OptionPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void showInputDialog(JFrameOperator jfo) throws Exception {
    // Cancel with text case
    useInputDialog(jfo, SOME_TEXT_TO_TYPE, CANCEL);
    //TODO: wait for no dialog displayed

    // Cancel with *NO* text case
    useInputDialog(jfo, null, CANCEL);
    //TODO: wait for no dialog displayed

    // Text field has *NO* input
    useInputDialog(jfo, null, OK);
    //TODO: wait for no dialog displayed

    // Text field has input
    {
        final String enteredText = "Rambo";

        useInputDialog(jfo, enteredText, OK);
        checkMessage(enteredText + INPUT_RESPONSE);
    }
}
 
Example #9
Source File: SplitPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication();

    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);

    JSplitPaneOperator splitPane = new JSplitPaneOperator(frame);

    // Toggle OneTouch Expandable
    checkOneTouch(frame, splitPane, true);
    checkOneTouch(frame, splitPane, false);

    // Check changing divider size to minimum and maximum values
    changeDividerSize(frame, splitPane, 50);
    changeDividerSize(frame, splitPane, 6);

    // Check moving the divider
    checkDividerMoves(frame, splitPane, false);
    checkDividerMoves(frame, splitPane, true);

    // Check different minumum Day/Night sizes
    changeMinimumSizes(frame, splitPane, 100);
    changeMinimumSizes(frame, splitPane, 0);
}
 
Example #10
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void watchProgressBar(TestData data, JFrameOperator frame, String label) {
    new JLabelOperator(frame, label); //dirty hack
    JProgressBarOperator progressBar = new JProgressBarOperator(frame);

    long waitingTime;
    for (waitingTime = 0; waitingTime < Utils.MAX_INSTALATION_WAIT; waitingTime += Utils.DELAY) {
        int val = ((JProgressBar) progressBar.getSource()).getValue();
        if (val >= 100) {
            break;
        }
        Utils.waitSecond(data, 5);
    }

    if (waitingTime >= Utils.MAX_INSTALATION_WAIT) {
        TestCase.fail("Installation timeout");
    }
}
 
Example #11
Source File: SplitPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void checkDividerMoves(JFrameOperator frame, JSplitPaneOperator splitPane, boolean isVertical) throws Exception {
    if (isVertical) {
        new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick();
    } else {
        new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick();
    }

    splitPane.moveDivider(0.0);
    assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation",
            splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation());

    // use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work
    splitPane.moveDivider(1.0);

    assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation",
            splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation());

    splitPane.moveDivider(0.5);
    assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations",
            (splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation());
}
 
Example #12
Source File: ButtonDemoScreenshotTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void checkButton(JFrameOperator jfo, int i, Robot rob) {
    JButtonOperator button = new JButtonOperator(jfo, i);

    Point loc = button.getLocationOnScreen();
    rob.mouseMove(loc.x, loc.y);

    BufferedImage initialButtonImage = capture(rob, button);
    assertNotBlack(initialButtonImage);
    save(initialButtonImage, "button" + i + "_0initial.png");
    rob.mousePress(InputEvent.BUTTON1_MASK);
    try {
        waitPressed(button);
        BufferedImage pressedButtonImage = capture(rob, button);
        assertNotBlack(pressedButtonImage);
        save(pressedButtonImage, "button" + i + "_1pressed.png");

        StrictImageComparator sComparator = new StrictImageComparator();
        assertNotEquals("Button " + i + " Test", sComparator, initialButtonImage, pressedButtonImage);
    } finally {
        rob.mouseRelease(InputEvent.BUTTON1_MASK);
    }
}
 
Example #13
Source File: TextFieldDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication();

    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);

    historyTextField(frame);
    dateTextField(frame);
    passwordField(frame);
}
 
Example #14
Source File: ButtonDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication();

    JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
    mainFrame.setComparator(EXACT_STRING_COMPARATOR);

    // Check all the buttons
    for (int i = 0; i < BUTTON_TOOLTIP.length; i++) {
        String tooltip = BUTTON_TOOLTIP[i];

        JButtonOperator button = new JButtonOperator(mainFrame, new ByToolTipChooser(tooltip));

        assertEquals(BUTTON_TEXT_BEFORE[i], button.getText());

        // Two buttons are hyperlinks, we don't want to click them
        if (!button.getSource().getClass().equals(JHyperlink.class)) {
            checkButton(button);
        }

        if (BUTTON_TEXT_AFTER.length > i) {
            assertEquals(BUTTON_TEXT_AFTER[i], button.getText());
        } else {
            assertEquals(BUTTON_TEXT_BEFORE[i], button.getText());
        }
    }
}
 
Example #15
Source File: DialogDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void initialCheckWithLabel(JFrameOperator frame, JDialogOperator jdo) {
    JLabelOperator label = new JLabelOperator(jdo);
    assertFalse("JFrame is not iconified", isIconified(frame));
    assertEquals("Only one JDialog is present", 1,
            countWindows(jDialogClassChooser));
    assertEquals(LABEL_CONTENT, label.getText());
}
 
Example #16
Source File: DialogDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    new ClassReference(DialogDemo.class.getCanonicalName()).startApplication();
    JFrameOperator mainFrame = new JFrameOperator(DIALOG_DEMO_TITLE);
    JDialogOperator dialog = new JDialogOperator(DIALOG_TITLE);
    JButtonOperator showJDialogButton = new JButtonOperator(mainFrame, SHOW_BUTTON_TITLE);
    initialCheckWithLabel(mainFrame, dialog);
    checkShowDialogButton(dialog, showJDialogButton);
    TestHelpers.checkChangeSize(dialog, new Dimension(dialog.getSize().width * 2,
            dialog.getSize().height * 2));
    TestHelpers.checkChangeLocation(dialog, new Point(dialog.getLocation().x + 100,
            dialog.getLocation().y + 100));
}
 
Example #17
Source File: SpinnerDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication();

    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);

    // Check changing different spinners
    for (int i = 0; i < SPINNERS_COUNT; i++) {
        changeValues(frame, i);
    }
}
 
Example #18
Source File: SliderDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    new ClassReference(SliderDemo.class.getCanonicalName()).startApplication();
    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
    plain(frame, HORIZONTAL_PLAIN_SLIDER);
    majorTicks(frame, HORIZONTAL_MAJOR_TICKS_SLIDER);
    minorTicks(frame, HORIZONTAL_MINOR_TICKS_SLIDER);
    disabled(frame, HORIZONTAL_DISABLED_SLIDER);
    plain(frame, VERTICAL_PLAIN_SLIDER);
    majorTicks(frame, VERTICAL_MAJOR_TICKS_SLIDER);
    minorTicks(frame, VERTICAL_MINOR_TICKS_SLIDER);
    disabled(frame, VERTICAL_DISABLED_SLIDER);
}
 
Example #19
Source File: TextFieldDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void historyTextField(JFrameOperator jfo) throws Exception {
    JTextFieldOperator jtfo = new JTextFieldOperator(jfo, new ByClassChooser(JHistoryTextField.class));
    jtfo.typeText("cat");

    jtfo.pressKey(KeyEvent.VK_DOWN);
    jtfo.pressKey(KeyEvent.VK_DOWN);
    jtfo.pressKey(KeyEvent.VK_ENTER);

    final String expectedValue = "category";
    jtfo.waitText(expectedValue);
    assertEquals("Select History Item", expectedValue, jtfo.getText());
}
 
Example #20
Source File: TextFieldDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void dateTextField(JFrameOperator jfo) throws Exception {
    JTextFieldOperator jtfo = new JTextFieldOperator(jfo,
            new ByClassChooser(JFormattedTextField.class));
    ContainerOperator<?> containerOperator = new ContainerOperator<>(jtfo.getParent());
    JButtonOperator jbo = new JButtonOperator(containerOperator, GO);
    JLabelOperator dowLabel = new JLabelOperator(containerOperator);
    Calendar calendar = Calendar.getInstance(Locale.ENGLISH);

    // Check default date Day of the Week
    jbo.push();
    dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH));

    // Check Custom Day of the Week
    calendar.set(2012, 9, 11); // Represents "Oct 11, 2012"
    Date date = calendar.getTime();
    String dateString = jtfo.getQueueTool().invokeAndWait(
            new QueueTool.QueueAction<String>("Formatting the value using JFormattedTextField formatter") {

        @Override
        public String launch() throws Exception {
            return ((JFormattedTextField) jtfo.getSource()).getFormatter().valueToString(date);
        }
    });
    System.out.println("dateString = " + dateString);
    jtfo.enterText(dateString);

    jbo.push();
    dowLabel.waitText("Thursday");
}
 
Example #21
Source File: JemmyExt.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void waitIsFocused(JFrameOperator jfo) {
    jfo.waitState(new ComponentChooser() {

        @Override
        public boolean checkComponent(Component comp) {
            return jfo.isFocused();
        }

        @Override
        public String getDescription() {
            return "JFrame is focused";
        }
    });
}
 
Example #22
Source File: ButtonDemoScreenshotTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    Robot rob = new Robot();

    new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication();

    JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
    waitImageIsStill(rob, mainFrame);

    // Check all the buttons
    for (int i = 0; i < BUTTON_COUNT; i++) {
        checkButton(mainFrame, i, rob);
    }
}
 
Example #23
Source File: OptionPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication();

    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);

    showInputDialog(frame);
    showWarningDialog(frame);
    showMessageDialog(frame);
    showComponentDialog(frame);
    showConfirmationDialog(frame);
}
 
Example #24
Source File: OptionPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void useInputDialog(JFrameOperator jfo, String textToType, String buttonToPush) {
    new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock();
    JDialogOperator jdo = new JDialogOperator(INPUT);
    if(textToType != null) {
        JTextFieldOperator jto = new JTextFieldOperator(jdo);
        jto.typeText(textToType);
        jto.waitText(textToType);
    }
    new JButtonOperator(jdo, buttonToPush).push();
    jdo.waitClosed();
}
 
Example #25
Source File: SwingViewTest.java    From SimpleMVC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void when_item_in_list_is_select_then_remove_button_is_enabled() {
    init_ListWithOneItem();
    JFrameOperator root = getRootFrame();

    new JListOperator(root, 0).selectItem(0);

    JButtonOperator removeButton = findButton(root, REMOVE_BUTTON);
    assertTrue("Remove button must be enabled", removeButton.isEnabled());
}
 
Example #26
Source File: SwingViewTest.java    From SimpleMVC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void when_remove_button_clicked_then_calls_removeAction() {
    init_ListWithOneItem();
    JFrameOperator root = getRootFrame();
    new JListOperator(root, 0).selectItem(0);

    pushButton(root, REMOVE_BUTTON);

    verify(controller).removeAction(ANY_STRING);
}
 
Example #27
Source File: OptionPaneDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void callADialogAndClose(JFrameOperator jfo, String buttonToOpenDialog,
                                 String dialogTitle, String buttonToPush) {
    new JButtonOperator(jfo, buttonToOpenDialog).pushNoBlock();
    JDialogOperator jdo = new JDialogOperator(dialogTitle);
    new JButtonOperator(jdo, buttonToPush).push();
    jdo.waitClosed();
}
 
Example #28
Source File: SwingViewTest.java    From SimpleMVC with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void when_add_button_clicked_then_calls_addAction() {
    JFrameOperator root = getRootFrame();
    setTextInField(root, ANY_STRING);

    pushButton(root, ADD_BUTTON);

    verify(controller).addAction(ANY_STRING);
}
 
Example #29
Source File: ComboBoxDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

    new ClassReference(ComboBoxDemo.class.getCanonicalName()).startApplication();

    JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
    for (ComboBoxInfo comboBoxInfo : ComboBoxInfo.values()) {
        comboBoxChecker(frame, comboBoxInfo);
    }
}
 
Example #30
Source File: ComboBoxDemoTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void comboBoxChecker(JFrameOperator jfo, ComboBoxInfo comboBoxInfo) {
    JComboBoxOperator jcbo = new JComboBoxOperator(jfo, comboBoxInfo.ordinal());
    for (int i = 0; i < jcbo.getItemCount(); i++) {
        jcbo.selectItem(i);
        jcbo.waitItemSelected(i);
    }
}