< prev index next >

tools/SharedTestUtilsOpen/src/test/javaclient/shared/TestUtil.java

Print this page
rev 320 : 8151500: [TEST] Implement multiple golden image support
Summary: Makes possible using any number of golden images.
   1 /*
   2  * Copyright (c) 2009, 2012, 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. Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  */
  24 
  25 package test.javaclient.shared;
  26 
  27 import java.io.*;
  28 import java.util.logging.Level;
  29 import java.util.logging.Logger;
  30 import javafx.scene.Scene;
  31 import javafx.stage.Stage;
  32 import javafx.stage.Window;
  33 import org.jemmy.TimeoutExpiredException;
  34 import org.jemmy.control.Wrap;
  35 import org.jemmy.env.Timeout;

  36 import org.jemmy.fx.ByWindowType;
  37 import org.jemmy.fx.Root;
  38 import org.jemmy.image.Image;

  39 import org.jemmy.timing.State;
  40 import org.jemmy.timing.Waiter;

  41 import test.javaclient.shared.description.TreeNode;
  42 import test.javaclient.shared.screenshots.ImagesManager;

  43 
  44 /**
  45  * Utility methods
  46  *
  47  * @author Sergey Grinev
  48  */
  49 public class TestUtil {
  50 
  51     public static final boolean IS_GOLDEN_MODE = Boolean.getBoolean("test.javaclient.creategolden");
  52     private static final boolean IS_SLOW_MODE = Boolean.getBoolean("test.javaclient.slowmode");
  53     public static final boolean IS_DESCRIBING_MODE = Boolean.getBoolean("test.javaclient.createdescription");
  54     public static final boolean IS_DESCRIPTION_MODE = Boolean.getBoolean("test.javaclient.description");
  55     /**
  56      * Suffixes for embedded mode.
  57      */
  58     public static final String[] SUFFIXES = new String[]{"First", "Second", "Third", "Forth"};
  59 
  60     /**
  61      * For embedded mode. Verify -Djavatest.vmOptions="-DembeddedMode=X",
  62      * whether X is true or false


 110             ObjectInputStream p = new ObjectInputStream(ostream);
 111             obj = p.readObject();
 112             ostream.close();
 113         } catch (IOException ex) {
 114             Logger.getLogger(TreeNode.class.getName()).log(Level.SEVERE, null, ex);
 115         } catch (ClassNotFoundException ex) {
 116             Logger.getLogger(TreeNode.class.getName()).log(Level.SEVERE, null, ex);
 117         }
 118         return obj;
 119     }
 120 
 121     /**
 122      * Verify screenshots of two wraps, by comparing screenshots of both of
 123      * them, until they are equal.
 124      *
 125      * @param testName test name for a test
 126      * @param existingWrap wrap for object already placed on UI
 127      * @param oneToWaitForWrap wrap for object can be not yet placed on UI
 128      */
 129     public static void compareScreenshots(String testName, final Wrap existingWrap, final Wrap oneToWaitForWrap) {
 130         String existingName = ImagesManager.getInstance().getScreenshotPath(testName + "-existing"); //= RESULT_PATH + testName + "-diff.png";

 131         String waitingForName = ImagesManager.getInstance().getScreenshotPath(testName + "-waitingFor");

 132         String diffName = ImagesManager.getInstance().getScreenshotPath(testName + "-diff"); //= RESULT_PATH + testName + IMAGE_POSTFIX;

 133         String OUTPUT = oneToWaitForWrap.getClass().getName() + ".OUTPUT";
 134         try {
 135             oneToWaitForWrap.waitState(new State<Object>() {
 136                 public Object reached() {
 137                     return (existingWrap.getScreenImage().compareTo(oneToWaitForWrap.getScreenImage()) == null) ? true : null;
 138                 }
 139 
 140                 @Override
 141                 public String toString() {
 142                     return "Control having expected image";
 143                 }
 144             });
 145         } catch (TimeoutExpiredException e) {
 146             if (diffName != null) {
 147                 oneToWaitForWrap.getEnvironment().getOutput(OUTPUT).println("Saving diff to " + diffName);
 148                 existingWrap.getScreenImage().compareTo(oneToWaitForWrap.getScreenImage()).save(diffName);
 149             }
 150             if (waitingForName != null) {
 151                 oneToWaitForWrap.getEnvironment().getOutput(OUTPUT).println("Saving waiting for to " + waitingForName);
 152                 oneToWaitForWrap.getScreenImage().save(waitingForName);


   1 /*
   2  * Copyright (c) 2009, 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. Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  */
  24 
  25 package test.javaclient.shared;
  26 
  27 import java.io.*;
  28 import java.util.logging.Level;
  29 import java.util.logging.Logger;
  30 import javafx.scene.Scene;
  31 import javafx.stage.Stage;
  32 import javafx.stage.Window;
  33 import org.jemmy.TimeoutExpiredException;
  34 import org.jemmy.control.Wrap;

  35 import org.jemmy.fx.ByWindowType;
  36 import org.jemmy.fx.Root;

  37 import org.jemmy.timing.State;

  38 import test.javaclient.shared.description.TreeNode;
  39 import test.javaclient.shared.screenshots.GoldenImageManager;

  40 
  41 /**
  42  * Utility methods
  43  *
  44  * @author Sergey Grinev
  45  */
  46 public class TestUtil {
  47 
  48     public static final boolean IS_GOLDEN_MODE = Boolean.getBoolean("test.javaclient.creategolden");
  49     private static final boolean IS_SLOW_MODE = Boolean.getBoolean("test.javaclient.slowmode");
  50     public static final boolean IS_DESCRIBING_MODE = Boolean.getBoolean("test.javaclient.createdescription");
  51     public static final boolean IS_DESCRIPTION_MODE = Boolean.getBoolean("test.javaclient.description");
  52     /**
  53      * Suffixes for embedded mode.
  54      */
  55     public static final String[] SUFFIXES = new String[]{"First", "Second", "Third", "Forth"};
  56 
  57     /**
  58      * For embedded mode. Verify -Djavatest.vmOptions="-DembeddedMode=X",
  59      * whether X is true or false


 107             ObjectInputStream p = new ObjectInputStream(ostream);
 108             obj = p.readObject();
 109             ostream.close();
 110         } catch (IOException ex) {
 111             Logger.getLogger(TreeNode.class.getName()).log(Level.SEVERE, null, ex);
 112         } catch (ClassNotFoundException ex) {
 113             Logger.getLogger(TreeNode.class.getName()).log(Level.SEVERE, null, ex);
 114         }
 115         return obj;
 116     }
 117 
 118     /**
 119      * Verify screenshots of two wraps, by comparing screenshots of both of
 120      * them, until they are equal.
 121      *
 122      * @param testName test name for a test
 123      * @param existingWrap wrap for object already placed on UI
 124      * @param oneToWaitForWrap wrap for object can be not yet placed on UI
 125      */
 126     public static void compareScreenshots(String testName, final Wrap existingWrap, final Wrap oneToWaitForWrap) {
 127         String existingName = GoldenImageManager.getScreenshotPath(testName + "-existing"); //= RESULT_PATH + testName + "-diff.png";

 128         String waitingForName = GoldenImageManager.getScreenshotPath(testName + "-waitingFor");

 129         String diffName = GoldenImageManager.getScreenshotPath(testName + "-diff"); //= RESULT_PATH + testName + IMAGE_POSTFIX;

 130         String OUTPUT = oneToWaitForWrap.getClass().getName() + ".OUTPUT";
 131         try {
 132             oneToWaitForWrap.waitState(new State<Object>() {
 133                 public Object reached() {
 134                     return (existingWrap.getScreenImage().compareTo(oneToWaitForWrap.getScreenImage()) == null) ? true : null;
 135                 }
 136 
 137                 @Override
 138                 public String toString() {
 139                     return "Control having expected image";
 140                 }
 141             });
 142         } catch (TimeoutExpiredException e) {
 143             if (diffName != null) {
 144                 oneToWaitForWrap.getEnvironment().getOutput(OUTPUT).println("Saving diff to " + diffName);
 145                 existingWrap.getScreenImage().compareTo(oneToWaitForWrap.getScreenImage()).save(diffName);
 146             }
 147             if (waitingForName != null) {
 148                 oneToWaitForWrap.getEnvironment().getOutput(OUTPUT).println("Saving waiting for to " + waitingForName);
 149                 oneToWaitForWrap.getScreenImage().save(waitingForName);


< prev index next >