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
159
160 /**
161 * Debugging Code. Will slow test execution if
162 * <code>IS_SLOW_MODE</code> is set.
163 */
164 public static void slow(long delay) {
165 if (IS_SLOW_MODE) {
166 try {
167 Thread.sleep(delay);
168 } catch (InterruptedException ex) {
169 }
170 }
171 }
172
173 public static Wrap<? extends Scene> getScene() {
174 final Wrap<? extends Scene> scene;
175
176 scene = Root.ROOT.lookup(new ByWindowType(Stage.class)).lookup(Scene.class).wrap(0);
177 Utils.deferAction(new Runnable() {
178 public void run() {
179 scene.getControl().getWindow().setFocused(true);
180 }
181 });
182
183 return scene;
184 }
185
186 public static String getTitle(Scene scene) {
187 Window window = scene.getWindow();
188 if (Stage.class.isInstance(window)) {
189 return ((Stage) window).getTitle();
190 }
191 return "";
192 }
193
194 public static void setTitle(Scene scene, String title) {
195 Window window = scene.getWindow();
196 if (Stage.class.isInstance(window)) {
197 ((Stage) window).setTitle(title);
198 }
199 }
|
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 import com.sun.javafx.stage.WindowHelper;
41
42 /**
43 * Utility methods
44 *
45 * @author Sergey Grinev
46 */
47 public class TestUtil {
48
49 public static final boolean IS_GOLDEN_MODE = Boolean.getBoolean("test.javaclient.creategolden");
50 private static final boolean IS_SLOW_MODE = Boolean.getBoolean("test.javaclient.slowmode");
51 public static final boolean IS_DESCRIBING_MODE = Boolean.getBoolean("test.javaclient.createdescription");
52 public static final boolean IS_DESCRIPTION_MODE = Boolean.getBoolean("test.javaclient.description");
53 /**
54 * Suffixes for embedded mode.
55 */
56 public static final String[] SUFFIXES = new String[]{"First", "Second", "Third", "Forth"};
57
58 /**
59 * For embedded mode. Verify -Djavatest.vmOptions="-DembeddedMode=X",
60 * whether X is true or false
160
161 /**
162 * Debugging Code. Will slow test execution if
163 * <code>IS_SLOW_MODE</code> is set.
164 */
165 public static void slow(long delay) {
166 if (IS_SLOW_MODE) {
167 try {
168 Thread.sleep(delay);
169 } catch (InterruptedException ex) {
170 }
171 }
172 }
173
174 public static Wrap<? extends Scene> getScene() {
175 final Wrap<? extends Scene> scene;
176
177 scene = Root.ROOT.lookup(new ByWindowType(Stage.class)).lookup(Scene.class).wrap(0);
178 Utils.deferAction(new Runnable() {
179 public void run() {
180 //scene.getControl().getWindow().setFocused(true);
181 WindowHelper.setFocused(scene.getControl().getWindow(), true);
182 }
183 });
184
185 return scene;
186 }
187
188 public static String getTitle(Scene scene) {
189 Window window = scene.getWindow();
190 if (Stage.class.isInstance(window)) {
191 return ((Stage) window).getTitle();
192 }
193 return "";
194 }
195
196 public static void setTitle(Scene scene, String title) {
197 Window window = scene.getWindow();
198 if (Stage.class.isInstance(window)) {
199 ((Stage) window).setTitle(title);
200 }
201 }
|