Package org.fest.swing.core

Examples of org.fest.swing.core.Robot


  }

  @Test
  public void should_create_Robot_on_setUp_and_inactivate_it_on_cleanUp() {
    testCase.setUpRobot();
    Robot robot = testCase.robot();
    assertThat(robot).isInstanceOf(BasicRobot.class);
    assertThat(robot.hierarchy()).isInstanceOf(ExistingHierarchy.class);
    assertThat(robot.isActive()).isTrue();
    testCase.cleanUp();
    assertThat(robot.isActive()).isFalse();
  }
View Full Code Here


public class AWT_insetsFromContainer_Test {
  private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);

  @Test
  public void should_return_insets_from_container() {
    Robot robot = robotWithNewAwtHierarchy();
    TestWindow window = TestWindow.createNewWindow(getClass());
    try {
      robot.showWindow(window, new Dimension(500, 300));
      Insets insets = insetsFrom(window);
      assertThat(insets).isEqualTo(insetsOf(window));
    } finally {
      robot.cleanUp();
    }
  }
View Full Code Here

   * Runs the screenshot process.
   */
  public void run() {
    long start = System.currentTimeMillis();

    Robot robot = BasicRobot.robotWithNewAwtHierarchy();

    // set skin
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
        JFrame.setDefaultLookAndFeelDecorated(true);
      }
    });
    robot.waitForIdle();

    // create the frame and set the icon image
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf = new JFrame("Sample frame");
        apply();
        sf.setSize(238, 261);

        sf.setLayout(new FlowLayout(FlowLayout.CENTER));
        JButton defButton = new JButton("default");
        JButton disButton = new JButton("disabled");
        JButton regButton = new JButton("regular");
        disButton.setEnabled(false);
        sf.add(defButton);
        sf.add(disButton);
        sf.add(regButton);
        sf.getRootPane().setDefaultButton(defButton);

        BufferedImage iconImage = new BufferedImage(1, 1,
            BufferedImage.TYPE_INT_ARGB);
        sf.setIconImage(iconImage);
        sf.setLocationRelativeTo(null);
        sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sf.setVisible(true);
      }
    });
    robot.waitForIdle();

    // make the screenshot
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        makeScreenshot();
      }
    });
    robot.waitForIdle();

    // dispose the frame
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf.dispose();
      }
    });
    robot.waitForIdle();

    long end = System.currentTimeMillis();
    System.out.println(this.getClass().getSimpleName() + " : "
        + (end - start) + "ms");
  }
View Full Code Here

   * Runs the screenshot process.
   */
  public void run() {
    long start = System.currentTimeMillis();

    Robot robot = BasicRobot.robotWithNewAwtHierarchy();

    // set skin
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        SubstanceLookAndFeel.setSkin(skin);
        JFrame.setDefaultLookAndFeelDecorated(true);
      }
    });
    robot.waitForIdle();

    // create the frame and set the icon image
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf = new SampleFrame(false);
        sf.setIconImage(SubstanceImageCreator.getColorSchemeImage(null,
            new ImageIcon(SkinRobot.class.getClassLoader()
                .getResource(
                    "test/resource/image-x-generic.png")),
            SubstanceLookAndFeel.getCurrentSkin(sf.getRootPane())
                .getMainActiveColorScheme(), 0.0f));
        sf.setSize(315, 245);
        sf.setLocationRelativeTo(null);
        sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sf.setVisible(true);
      }
    });
    robot.waitForIdle();

    // make the screenshot
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        makeScreenshot();
      }
    });
    robot.waitForIdle();

    // dispose the frame
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf.dispose();
      }
    });
    robot.waitForIdle();

    long end = System.currentTimeMillis();
    System.out.println(this.getClass().getSimpleName() + " : "
        + (end - start) + "ms");
  }
View Full Code Here

   * Runs the screenshot process.
   */
  public void run() {
    long start = System.currentTimeMillis();

    Robot robot = BasicRobot.robotWithNewAwtHierarchy();

    // set skin
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        SubstanceLookAndFeel.setSkin(skin);
        JFrame.setDefaultLookAndFeelDecorated(true);
      }
    });
    robot.waitForIdle();

    // create the frame and set the icon image
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf = new SampleFrame(false);
        sf.setIconImage(SubstanceImageCreator.getColorSchemeImage(null,
            new ImageIcon(SkinRobot.class.getClassLoader()
                .getResource(
                    "test/resource/image-x-generic.png")),
            SubstanceLookAndFeel.getCurrentSkin(sf.getRootPane())
                .getMainActiveColorScheme(), 0.0f));
        sf.setSize(315, 245);
        sf.setLocationRelativeTo(null);
        sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sf.setVisible(true);
      }
    });
    robot.waitForIdle();

    // get the default button
    JButton defaultButton = GuiActionRunner
        .execute(new GuiQuery<JButton>() {
          @Override
          protected JButton executeInEDT() throws Throwable {
            return sf.getRootPane().getDefaultButton();
          }
        });
    // and move the mouse to it
    robot.moveMouse(defaultButton);
    robot.waitForIdle();

    // wait for a second
    Pause.pause(1000);

    // make the first screenshot
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        makeScreenshot(1);
      }
    });
    robot.waitForIdle();

    // switch to the last tab
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf.switchToLastTab();
      }
    });
    robot.waitForIdle();

    // move the mouse away from the frame
    robot.moveMouse(new Point(0, 0));
    robot.waitForIdle();

    // wait for two seconds
    Pause.pause(1000);

    // make the second screenshot
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        makeScreenshot(2);
      }
    });
    robot.waitForIdle();

    // dispose the frame
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf.dispose();
      }
    });
    robot.waitForIdle();

    long end = System.currentTimeMillis();
    System.out.println(this.getClass().getSimpleName() + " : "
        + (end - start) + "ms");
  }
View Full Code Here

public class SwingConsoleTest
{
    @Test(groups = "display-required") // Will fail if run in a headless environment.
    public void testUserSelection() throws InterruptedException
    {
        Robot robot = BasicRobot.robotWithNewAwtHierarchy();
        final SwingConsole swingConsole = new SwingConsole();
        JFrame frame = new JFrame();
        frame.add(swingConsole, BorderLayout.CENTER);
        FrameFixture frameFixture = new FrameFixture(robot, frame);
        frame.setSize(300, 100);
        frame.validate();
        frame.setVisible(true);

        final List<JLabel> labels = Arrays.asList(new JLabel("Zero"),
                                                  new JLabel("One"),
                                                  new JLabel("Two"));

        final int[] selection = new int[1];
        new Thread(new Runnable()
        {
            public void run()
            {
                // This method blocks so we can't run it on the test thread.
                selection[0] = swingConsole.select(labels);
            }
        }).start();
        Thread.sleep(250)// TO DO: Come up with a proper solution to this race condition.
        frameFixture.button("Selection-1").click();

        assert selection[0] == 1
                : "Second item (index 1) should have been selected, selection index was " + selection[0];

        robot.cleanUp();
    }
View Full Code Here

    f.getContentPane().add(p);
    f.pack();
   
    Assert.assertNull(dt.v); // Make sure we're starting clean
   
    Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();
   
    ComponentDragAndDrop d = new ComponentDragAndDrop(robot);
       
    d.drag(view, new Point(5,5));
    d.drop(view, new Point(5,5));
View Full Code Here

 
 
  // Test disabled pending alternative approach (open is final, can't be mocked)
  @Test (enabled = false)
  public void testDoubleClick() {
    Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();
   
    Mockito.verify(comp, Mockito.never()).open();
    robot.doubleClick(view);
    Mockito.verify(comp, Mockito.times(1)).open();   
  }
View Full Code Here

   * Runs the screenshot process.
   */
  public void run() {
    long start = System.currentTimeMillis();

    Robot robot = BasicRobot.robotWithNewAwtHierarchy();

    // set skin
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
        JFrame.setDefaultLookAndFeelDecorated(true);
      }
    });
    robot.waitForIdle();

    // create the frame and set the icon image
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf = new JFrame("Sample frame");
        apply();
        sf.setSize(238, 261);

        sf.setLayout(new FlowLayout(FlowLayout.CENTER));
        JButton defButton = new JButton("default");
        JButton disButton = new JButton("disabled");
        JButton regButton = new JButton("regular");
        disButton.setEnabled(false);
        sf.add(defButton);
        sf.add(disButton);
        sf.add(regButton);
        sf.getRootPane().setDefaultButton(defButton);

        BufferedImage iconImage = new BufferedImage(1, 1,
            BufferedImage.TYPE_INT_ARGB);
        sf.setIconImage(iconImage);
        sf.setLocationRelativeTo(null);
        sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sf.setVisible(true);
      }
    });
    robot.waitForIdle();

    // make the screenshot
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        makeScreenshot();
      }
    });
    robot.waitForIdle();

    // dispose the frame
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf.dispose();
      }
    });
    robot.waitForIdle();

    long end = System.currentTimeMillis();
    System.out.println(this.getClass().getSimpleName() + " : "
        + (end - start) + "ms");
  }
View Full Code Here

   * Runs the screenshot process.
   */
  public void run() {
    long start = System.currentTimeMillis();

    Robot robot = BasicRobot.robotWithNewAwtHierarchy();

    // set skin
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        SubstanceLookAndFeel.setSkin(skin);
        JFrame.setDefaultLookAndFeelDecorated(true);
      }
    });
    robot.waitForIdle();

    // create the frame and set the icon image
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf = new SampleFrame();
        sf.setIconImage(SubstanceImageCreator.getColorSchemeImage(null,
            new ImageIcon(SkinRobot.class.getClassLoader()
                .getResource(
                    "test/resource/image-x-generic.png")),
            SubstanceLookAndFeel.getCurrentSkin(sf.getRootPane())
                .getActiveColorScheme(
                    DecorationAreaType.PRIMARY_TITLE_PANE),
            0.0f));
        sf.setSize(338, 245);
        sf.setLocationRelativeTo(null);
        sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sf.setVisible(true);
      }
    });
    robot.waitForIdle();

    // wait for one second
    Pause.pause(1000);

    // make the screenshot
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        makeScreenshot();
      }
    });
    robot.waitForIdle();

    // dispose the frame
    GuiActionRunner.execute(new GuiTask() {
      @Override
      protected void executeInEDT() throws Throwable {
        sf.dispose();
      }
    });
    robot.waitForIdle();

    long end = System.currentTimeMillis();
    System.out.println(this.getClass().getSimpleName() + " : "
        + (end - start) + "ms");
  }
View Full Code Here

TOP

Related Classes of org.fest.swing.core.Robot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.