ButtonDemoScreenshotTest.java revision 14305:566a5f5a9a5a
144746Smarkm/*
250476Speter * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
344746Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
444746Smarkm *
544746Smarkm * This code is free software; you can redistribute it and/or modify it
657171Sshin * under the terms of the GNU General Public License version 2 only, as
796462Sru * published by the Free Software Foundation.
874870Sru *
974870Sru * This code is distributed in the hope that it will be useful, but WITHOUT
10114962Shmp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11114962Shmp * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1244746Smarkm * version 2 for more details (a copy is included in the LICENSE file that
1344746Smarkm * accompanied this code).
1444746Smarkm *
1544746Smarkm * You should have received a copy of the GNU General Public License version
1644746Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
1744746Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1844746Smarkm *
19117980Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2059266Ssteve * or visit www.oracle.com if you need additional information or have any
2159266Ssteve * questions.
2259266Ssteve */
2344746Smarkm
2444746Smarkmimport com.sun.swingset3.demos.button.ButtonDemo;
2544746Smarkmimport org.jtregext.GuiTestListener;
2644746Smarkmimport java.awt.Point;
2745255Sacheimport java.awt.Robot;
2844746Smarkmimport java.awt.event.InputEvent;
2944746Smarkmimport java.awt.image.BufferedImage;
30import org.netbeans.jemmy.ClassReference;
31import org.netbeans.jemmy.image.StrictImageComparator;
32import org.netbeans.jemmy.operators.JButtonOperator;
33import org.netbeans.jemmy.operators.JFrameOperator;
34import static org.jemmy2ext.JemmyExt.*;
35import org.testng.annotations.Test;
36import static com.sun.swingset3.demos.button.ButtonDemo.*;
37import org.testng.annotations.Listeners;
38
39/*
40 * @test
41 * @key headful screenshots
42 * @summary Verifies buttons on SwingSet3 ButtonDemo page by clicking each
43 *          button, taking its screenshots and checking that pressed button
44 *          image is different from initial button image.
45 *
46 * @library /sanity/client/lib/jemmy/src
47 * @library /sanity/client/lib/Extensions/src
48 * @library /sanity/client/lib/SwingSet3/src
49 * @build org.jemmy2ext.JemmyExt
50 * @build com.sun.swingset3.demos.button.ButtonDemo
51 * @run testng ButtonDemoScreenshotTest
52 */
53@Listeners(GuiTestListener.class)
54public class ButtonDemoScreenshotTest {
55
56    private static final int BUTTON_COUNT = 6; // TODO: Decide about "open browser" buttons (value was 8 originally)
57
58    @Test
59    public void test() throws Exception {
60        Robot rob = new Robot();
61
62        new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication();
63
64        JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE);
65        waitImageIsStill(rob, mainFrame);
66
67        // Check all the buttons
68        for (int i = 0; i < BUTTON_COUNT; i++) {
69            checkButton(mainFrame, i, rob);
70        }
71    }
72
73    public void checkButton(JFrameOperator jfo, int i, Robot rob) {
74        JButtonOperator button = new JButtonOperator(jfo, i);
75
76        Point loc = button.getLocationOnScreen();
77        rob.mouseMove(loc.x, loc.y);
78
79        BufferedImage initialButtonImage = capture(rob, button);
80        assertNotBlack(initialButtonImage);
81        save(initialButtonImage, "button" + i + "_0initial.png");
82        rob.mousePress(InputEvent.BUTTON1_MASK);
83        try {
84            waitPressed(button);
85            BufferedImage pressedButtonImage = capture(rob, button);
86            assertNotBlack(pressedButtonImage);
87            save(pressedButtonImage, "button" + i + "_1pressed.png");
88
89            StrictImageComparator sComparator = new StrictImageComparator();
90            assertNotEquals("Button " + i + " Test", sComparator, initialButtonImage, pressedButtonImage);
91        } finally {
92            rob.mouseRelease(InputEvent.BUTTON1_MASK);
93        }
94    }
95
96}
97