jdk/test/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java
changeset 36744 a00905527ec2
child 37677 9774eca96b01
equal deleted inserted replaced
36743:bdc3f1b79fb7 36744:a00905527ec2
       
     1 /*
       
     2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.awt.Point;
       
    25 import java.awt.Robot;
       
    26 import java.awt.event.InputEvent;
       
    27 import java.awt.image.BufferedImage;
       
    28 import org.netbeans.jemmy.ClassReference;
       
    29 import org.netbeans.jemmy.image.StrictImageComparator;
       
    30 import org.netbeans.jemmy.operators.JButtonOperator;
       
    31 import org.netbeans.jemmy.operators.JFrameOperator;
       
    32 import static org.jemmy2ext.JemmyExt.*;
       
    33 import org.testng.annotations.Test;
       
    34 import static com.sun.swingset3.demos.button.ButtonDemo.*;
       
    35 
       
    36 /*
       
    37  * @test
       
    38  * @key headful screenshots
       
    39  * @summary Verifies buttons on SwingSet3 ButtonDemo page by clicking each
       
    40  *          button, taking its screenshots and checking that pressed button
       
    41  *          image is different from initial button image.
       
    42  *
       
    43  * @library /sanity/client/lib/jemmy/src
       
    44  * @library /sanity/client/lib/Jemmy2Ext/src
       
    45  * @library /sanity/client/lib/SwingSet3/src
       
    46  * @build org.jemmy2ext.JemmyExt
       
    47  * @build com.sun.swingset3.demos.button.ButtonDemo
       
    48  * @run testng ButtonDemoScreenshotTest
       
    49  */
       
    50 public class ButtonDemoScreenshotTest {
       
    51 
       
    52     private static final int BUTTON_COUNT = 6; // TODO: Decide about "open browser" buttons (value was 8 originally)
       
    53 
       
    54     @Test
       
    55     public void test() throws Exception {
       
    56         captureDebugInfoOnFail(() -> {
       
    57             Robot rob = new Robot();
       
    58 
       
    59             new ClassReference(com.sun.swingset3.demos.button.ButtonDemo.class.getCanonicalName()).startApplication();
       
    60 
       
    61             JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
       
    62             waitImageIsStill(rob, mainFrame);
       
    63 
       
    64             // Check all the buttons
       
    65             for (int i = 0; i < BUTTON_COUNT; i++) {
       
    66                 checkButton(mainFrame, i, rob);
       
    67             }
       
    68         });
       
    69     }
       
    70 
       
    71     public void checkButton(JFrameOperator jfo, int i, Robot rob) {
       
    72         JButtonOperator button = new JButtonOperator(jfo, i);
       
    73 
       
    74         Point loc = button.getLocationOnScreen();
       
    75         rob.mouseMove(loc.x, loc.y);
       
    76 
       
    77         BufferedImage initialButtonImage = capture(rob, button);
       
    78         assertNotBlack(initialButtonImage);
       
    79         save(initialButtonImage, "button" + i + "_0initial.png");
       
    80         rob.mousePress(InputEvent.BUTTON1_MASK);
       
    81         try {
       
    82             waitPressed(button);
       
    83             BufferedImage pressedButtonImage = capture(rob, button);
       
    84             assertNotBlack(pressedButtonImage);
       
    85             save(pressedButtonImage, "button" + i + "_1pressed.png");
       
    86 
       
    87             StrictImageComparator sComparator = new StrictImageComparator();
       
    88             assertNotEquals("Button " + i + " Test", sComparator, initialButtonImage, pressedButtonImage);
       
    89         } finally {
       
    90             rob.mouseRelease(InputEvent.BUTTON1_MASK);
       
    91         }
       
    92     }
       
    93 
       
    94 }