1 /* 2 * Copyright (c) 2007, 2018, 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 package org.jemmy.swt; 24 25 import org.eclipse.swt.widgets.Control; 26 import org.eclipse.swt.widgets.Shell; 27 import org.eclipse.swt.widgets.TabFolder; 28 import org.eclipse.swt.widgets.TabItem; 29 import org.eclipse.swt.widgets.Table; 30 import org.eclipse.swt.widgets.TableColumn; 31 import org.eclipse.swt.widgets.TableItem; 32 import org.eclipse.swt.widgets.ToolBar; 33 import org.eclipse.swt.widgets.ToolItem; 34 import org.eclipse.swt.widgets.Tree; 35 import org.eclipse.swt.widgets.TreeItem; 36 import org.jemmy.control.Wrap; 37 import org.jemmy.interfaces.Keyboard.KeyboardButtons; 38 import org.jemmy.interfaces.Parent; 39 import org.testng.annotations.AfterClass; 40 import org.testng.annotations.AfterMethod; 41 import org.testng.annotations.BeforeClass; 42 import org.testng.annotations.BeforeMethod; 43 import org.testng.annotations.Test; 44 45 /** 46 * 47 * @author shura 48 */ 49 public class ItemsTest { 50 51 public ItemsTest() { 52 } 53 54 @BeforeClass 55 public static void setUpClass() throws Exception { 56 new Thread(new Runnable() { 57 58 public void run() { 59 Items.main(null); 60 } 61 }).start(); 62 Thread.sleep(2000); 63 } 64 65 @AfterClass 66 public static void tearDownClass() throws Exception { 67 } 68 Wrap<? extends Shell> shell; 69 70 @BeforeMethod 71 public void setUp() { 72 shell = Shells.SHELLS.lookup().wrap(); 73 } 74 75 @AfterMethod 76 public void tearDown() { 77 } 78 79 @Test 80 public void tabs() throws InterruptedException { 81 Wrap<? extends TabFolder> tabbedPane = Shells.SHELLS.lookup(). 82 as(Parent.class, Control.class).lookup(TabFolder.class).wrap(); 83 Parent<TabItem> prnt = tabbedPane.as(Parent.class, TabItem.class); 84 prnt.lookup(new ByTextItem<TabItem>("Table")).wrap().mouse().click(); 85 prnt.lookup().wrap().mouse().click(); 86 } 87 88 private <T extends Control> Wrap<? extends T> select(String tab, Class<T> cls) { 89 Parent<Control> parent = shell.as(Parent.class, Control.class); 90 Wrap<? extends TabFolder> tabbedPane = parent.lookup(TabFolder.class).wrap(); 91 Parent<TabItem> prnt = tabbedPane.as(Parent.class, TabItem.class); 92 prnt.lookup(new ByTextItem<TabItem>(tab)).wrap().mouse().click(); 93 return parent.lookup(cls).wrap(); 94 } 95 96 @Test 97 public void tool() throws InterruptedException { 98 Parent<ToolItem> tb = select("Toolbar", ToolBar.class).as(Parent.class, 99 ToolItem.class); 100 tb.lookup(new ByTextItem<ToolItem>("1")).wrap().mouse().click(); 101 shell.waitProperty(Wrap.TEXT_PROP_NAME, "ToolItem 1"); 102 tb.lookup(new ByTextItem<ToolItem>("2")).wrap().mouse().click(); 103 shell.waitProperty(Wrap.TEXT_PROP_NAME, "ToolItem 2"); 104 tb.lookup().wrap().mouse().click(); 105 shell.waitProperty(Wrap.TEXT_PROP_NAME, "ToolItem 0"); 106 } 107 108 @Test 109 public void table() throws InterruptedException { 110 Parent<TableItem> tb = select("Table", Table.class).as(Parent.class, 111 TableItem.class); 112 tb.lookup().wrap().mouse().click(); 113 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TableItem {A:0}"); 114 tb.lookup(new ByTextItem<TableItem>("3")).wrap().mouse().click(); 115 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TableItem {A:3}"); 116 tb.lookup(new ByTextItem<TableItem>("6")).wrap().mouse().click(); 117 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TableItem {A:6}"); 118 } 119 120 @Test 121 public void tableByItem() throws InterruptedException { 122 select("Table", Table.class).as(Parent.class, 123 TableItem.class); 124 Parent<Control> parent = shell.as(Parent.class, Control.class); 125 Wrap<? extends Table> tableB = parent.lookup(Table.class, new ByItemLookup<Table>("B:0")).wrap(); 126 Parent<TableItem> tb = tableB.as(Parent.class, TableItem.class); 127 128 tb.lookup(new ByTextItem<TableItem>("0")).wrap().mouse().click(); 129 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TableItem {B:0}"); 130 tb.lookup(new ByTextItem<TableItem>("3")).wrap().mouse().click(); 131 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TableItem {B:3}"); 132 tb.lookup(new ByTextItem<TableItem>("6")).wrap().mouse().click(); 133 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TableItem {B:6}"); 134 } 135 136 @Test 137 public void tree() throws InterruptedException { 138 Wrap<? extends Tree> tree = select("Tree", Tree.class); 139 Parent<TreeItem> tb = tree.as(Parent.class, 140 TreeItem.class); 141 tb.lookup().wrap().mouse().click(); 142 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TreeItem {0}"); 143 tb.lookup(new ByTextItem<TreeItem>("1")).wrap().mouse().click(1); 144 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TreeItem {1}"); 145 if (System.getProperty("os.name").contains("Windows")) { 146 tree.keyboard().pushKey(KeyboardButtons.RIGHT); 147 } else { 148 tree.keyboard().typeChar('+'); 149 } 150 tb.lookup(new ByTextItem<TreeItem>("11")).wrap().mouse().click(); 151 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TreeItem {11}"); 152 tb.lookup(new ByTextItem<TreeItem>("0")).wrap().mouse().click(1); 153 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TreeItem {0}"); 154 if (System.getProperty("os.name").contains("Windows")) { 155 tree.keyboard().pushKey(KeyboardButtons.RIGHT); 156 } else { 157 tree.keyboard().typeChar('+'); 158 } 159 tb.lookup(new ByTextItem<TreeItem>("01")).wrap().mouse().click(1); 160 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TreeItem {01}"); 161 if (System.getProperty("os.name").contains("Windows")) { 162 tree.keyboard().pushKey(KeyboardButtons.RIGHT); 163 } else { 164 tree.keyboard().typeChar('+'); 165 } 166 tb.lookup(new ByTextItem<TreeItem>("010")).wrap().mouse().click(); 167 shell.waitProperty(Wrap.TEXT_PROP_NAME, "TreeItem {010}"); 168 } 169 170 @Test 171 public void columns() throws InterruptedException { 172 Parent<TableColumn> tb = select("Table", Table.class).as(Parent.class, 173 TableColumn.class); 174 tb.lookup().wrap().waitProperty(Wrap.TEXT_PROP_NAME, "0"); 175 tb.lookup(new ByTextItem<TableColumn>("1")).wait(1); 176 } 177 178 @Test 179 public void dump() throws InterruptedException { 180 shell.as(Parent.class, Control.class).lookup().wait(5).dump(System.out); 181 } 182 }