< prev index next >

functional/ControlsTests/test/javafx/commons/ControlsTest.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) 2014, 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


  28 import javafx.scene.Node;
  29 import org.jemmy.fx.ByID;
  30 import org.jemmy.image.Image;
  31 import org.jemmy.interfaces.Selectable;
  32 import org.junit.Test;
  33 import static javafx.commons.ControlChooserApp.*;
  34 import org.junit.runner.RunWith;
  35 import test.javaclient.shared.FilteredTestRunner;
  36 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType;
  37 import org.jemmy.env.Environment;
  38 import org.jemmy.env.Timeout;
  39 import org.jemmy.image.AWTImage;
  40 import org.jemmy.image.GlassImage;
  41 import org.jemmy.image.ImageComparator;
  42 import org.jemmy.image.pixel.MaxDistanceComparator;
  43 import org.jemmy.image.pixel.Raster;
  44 import org.jemmy.image.pixel.RasterComparator;
  45 import org.jemmy.timing.State;
  46 import org.jemmy.timing.Waiter;
  47 import org.junit.Assert;
  48 import test.javaclient.shared.screenshots.ImagesManager;

  49 

  50 /**
  51  *
  52  * @author Dmitry Zinkevich <dmitry.zinkevich@oracle.com>
  53  */
  54 @RunWith(FilteredTestRunner.class)
  55 public class ControlsTest extends ControlsBase {
  56 
  57     /**
  58      * Checks opacity of controls by comparing two screenshots:
  59      * first - control having 40% opacity,
  60      * second - initial control screenshot with applied 40% opacity
  61      */
  62     @ScreenshotCheck
  63     //Test//Switched off.
  64     public void opacityTest() throws InterruptedException, Throwable {
  65 
  66         final MaxDistanceComparator maxDistanceComparator = new MaxDistanceComparator(0.0);
  67         final double THRESHOLD = 0.03 * Math.sqrt(3);
  68         
  69         /*


 104                 /*
 105                  * Decrease control opacity by x percent
 106                  * and check that the image distance between opaque and translucent states is less or equal x
 107                  */
 108                 final double OPACITY = 0.4;
 109                 setPropertyBySlider(settingType, TestedProperties.opacity, OPACITY);
 110 
 111                 maxDistanceComparator.setThreshold(THRESHOLD);
 112                 try {
 113                     new Waiter(new Timeout("", 2000)).ensureState(new State<Boolean>() {
 114                         public Boolean reached() {
 115                             Image imgTranslucent = testedControl.getScreenImage();
 116                             Boolean isDifference = !maxDistanceComparator.compare((Raster) imgOpacity40, (Raster) imgTranslucent);
 117                             return isDifference ? null : Boolean.valueOf(true);
 118                         }
 119                     });
 120                 } catch (Exception ex) {
 121                     System.out.println(ex.getMessage());
 122                     Image imgTranslucent = testedControl.getScreenImage();
 123                     
 124                     String screenshotPath = ImagesManager.getInstance().getScreenshotPath(String.format("%s_img_opacity40", nodeName));

 125                     imgOpacity40.save(screenshotPath);
 126                     
 127                     screenshotPath = ImagesManager.getInstance().getScreenshotPath(String.format("%s_control_opacity40", nodeName));

 128                     imgTranslucent.save(screenshotPath);
 129 
 130                     Image diff = Environment.getEnvironment().getProperty(ImageComparator.class).compare(imgOpacity40, imgTranslucent);
 131                     
 132                     Assert.assertTrue(diff != null);
 133                     
 134                     screenshotPath = ImagesManager.getInstance().getScreenshotPath(String.format("%s_diff", nodeName));

 135                     diff.save(screenshotPath);
 136                 }
 137                 setPropertyBySlider(settingType, TestedProperties.opacity, 1);
 138             }
 139             clearCache();
 140         }
 141         
 142         /*
 143          * Restore comparator
 144          */
 145         if (rasterComparator != null) {
 146             Environment.getEnvironment().setProperty(RasterComparator.class, rasterComparator);
 147         }
 148     }
 149 }
   1 /*
   2  * Copyright (c) 2014, 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


  28 import javafx.scene.Node;
  29 import org.jemmy.fx.ByID;
  30 import org.jemmy.image.Image;
  31 import org.jemmy.interfaces.Selectable;
  32 import org.junit.Test;
  33 import static javafx.commons.ControlChooserApp.*;
  34 import org.junit.runner.RunWith;
  35 import test.javaclient.shared.FilteredTestRunner;
  36 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType;
  37 import org.jemmy.env.Environment;
  38 import org.jemmy.env.Timeout;
  39 import org.jemmy.image.AWTImage;
  40 import org.jemmy.image.GlassImage;
  41 import org.jemmy.image.ImageComparator;
  42 import org.jemmy.image.pixel.MaxDistanceComparator;
  43 import org.jemmy.image.pixel.Raster;
  44 import org.jemmy.image.pixel.RasterComparator;
  45 import org.jemmy.timing.State;
  46 import org.jemmy.timing.Waiter;
  47 import org.junit.Assert;
  48 import test.javaclient.shared.screenshots.GoldenImageManager;


  49 /**
  50  *
  51  * @author Dmitry Zinkevich <dmitry.zinkevich@oracle.com>
  52  */
  53 @RunWith(FilteredTestRunner.class)
  54 public class ControlsTest extends ControlsBase {
  55 
  56     /**
  57      * Checks opacity of controls by comparing two screenshots:
  58      * first - control having 40% opacity,
  59      * second - initial control screenshot with applied 40% opacity
  60      */
  61     @ScreenshotCheck
  62     //Test//Switched off.
  63     public void opacityTest() throws InterruptedException, Throwable {
  64 
  65         final MaxDistanceComparator maxDistanceComparator = new MaxDistanceComparator(0.0);
  66         final double THRESHOLD = 0.03 * Math.sqrt(3);
  67         
  68         /*


 103                 /*
 104                  * Decrease control opacity by x percent
 105                  * and check that the image distance between opaque and translucent states is less or equal x
 106                  */
 107                 final double OPACITY = 0.4;
 108                 setPropertyBySlider(settingType, TestedProperties.opacity, OPACITY);
 109 
 110                 maxDistanceComparator.setThreshold(THRESHOLD);
 111                 try {
 112                     new Waiter(new Timeout("", 2000)).ensureState(new State<Boolean>() {
 113                         public Boolean reached() {
 114                             Image imgTranslucent = testedControl.getScreenImage();
 115                             Boolean isDifference = !maxDistanceComparator.compare((Raster) imgOpacity40, (Raster) imgTranslucent);
 116                             return isDifference ? null : Boolean.valueOf(true);
 117                         }
 118                     });
 119                 } catch (Exception ex) {
 120                     System.out.println(ex.getMessage());
 121                     Image imgTranslucent = testedControl.getScreenImage();
 122                     
 123                     String screenshotPath = GoldenImageManager.getScreenshotPath(String.format("%s_img_opacity40", nodeName));

 124                     imgOpacity40.save(screenshotPath);
 125                     
 126                     screenshotPath = GoldenImageManager.getScreenshotPath(String.format("%s_control_opacity40", nodeName));

 127                     imgTranslucent.save(screenshotPath);
 128 
 129                     Image diff = Environment.getEnvironment().getProperty(ImageComparator.class).compare(imgOpacity40, imgTranslucent);
 130                     
 131                     Assert.assertTrue(diff != null);
 132                     
 133                     screenshotPath = GoldenImageManager.getScreenshotPath(String.format("%s_diff", nodeName));

 134                     diff.save(screenshotPath);
 135                 }
 136                 setPropertyBySlider(settingType, TestedProperties.opacity, 1);
 137             }
 138             clearCache();
 139         }
 140         
 141         /*
 142          * Restore comparator
 143          */
 144         if (rasterComparator != null) {
 145             Environment.getEnvironment().setProperty(RasterComparator.class, rasterComparator);
 146         }
 147     }
 148 }
< prev index next >