Skip to content

Commit 8f9b8a8

Browse files
committed
For Java 21
1 parent 9e9a59d commit 8f9b8a8

File tree

2 files changed

+114
-115
lines changed
  • taf-base/src/main/java/com/baloise/testautomation/taf/base/_base
  • taf-swing-server/src/main/java/com/baloise/testautomation/taf/swing/server/elements

2 files changed

+114
-115
lines changed

taf-base/src/main/java/com/baloise/testautomation/taf/base/_base/AElement.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,6 @@ public String value() {
8383
return byXpath;
8484
}
8585

86-
public IFinder<?> getFinder() {
87-
assertComponentNotNull();
88-
IFinder<?> brFinder = null;
89-
IFinder<?> swFinder = null;
90-
try {
91-
brFinder = component.getBrowserFinder();
92-
}
93-
catch (Throwable t) {}
94-
try {
95-
swFinder = component.getSwingFinder();
96-
}
97-
catch (Throwable t) {}
98-
if (brFinder != null && swFinder != null) {
99-
fail("more than one finder declared on component --> cannot decide which one to use --> fail");
100-
}
101-
if (brFinder != null) {
102-
return brFinder;
103-
}
104-
if (swFinder != null) {
105-
return swFinder;
106-
}
107-
fail("no finder declared on component --> fail");
108-
return null;
109-
}
110-
11186
public String getName() {
11287
return name;
11388
}
@@ -122,16 +97,16 @@ public void setCheck(Annotation check) {
12297
this.check = check;
12398
}
12499

125-
// public Region roFind() {
126-
// // TODO
127-
// return null;
128-
// }
129-
130100
@Override
131101
public void setComponent(IComponent component) {
132102
this.component = component;
133103
}
134104

105+
// public Region roFind() {
106+
// // TODO
107+
// return null;
108+
// }
109+
135110
@Override
136111
public void setName(String name) {
137112
this.name = name;
@@ -179,6 +154,31 @@ public void withXPath(IComponent parent, String name, final String xpath) {
179154
setComponent(parent);
180155
}
181156

157+
protected IFinder<?> getFinder() {
158+
assertComponentNotNull();
159+
IFinder<?> brFinder = null;
160+
IFinder<?> swFinder = null;
161+
try {
162+
brFinder = component.getBrowserFinder();
163+
}
164+
catch (Throwable t) {}
165+
try {
166+
swFinder = component.getSwingFinder();
167+
}
168+
catch (Throwable t) {}
169+
if (brFinder != null && swFinder != null) {
170+
fail("more than one finder declared on component --> cannot decide which one to use --> fail");
171+
}
172+
if (brFinder != null) {
173+
return brFinder;
174+
}
175+
if (swFinder != null) {
176+
return swFinder;
177+
}
178+
fail("no finder declared on component --> fail");
179+
return null;
180+
}
181+
182182
private void assertComponentNotNull() {
183183
assertNotNull(
184184
"component may not be null --> check, if the used annotion is supported (ABase --> getSupportedBys() --> "

taf-swing-server/src/main/java/com/baloise/testautomation/taf/swing/server/elements/ASwElement.java

Lines changed: 84 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ public abstract class ASwElement implements ISwElement<Component> {
1717

1818
public static String paramCommand = "command";
1919

20-
public Component component;
20+
public static long TIMEOUT_FOR_EXECUTION_IN_SECONDS = 10;
2121

22+
public Component component;
2223
public TafProperties properties;
24+
2325
// public String tagName;
2426
public long tid;
2527

@@ -39,67 +41,8 @@ public ASwElement(long tid, Component component) {
3941
fillProperties();
4042
}
4143

42-
protected void addProperty(String key, int value) {
43-
addProperty(key, new Integer(value).toString());
44-
}
45-
46-
protected void addProperty(String key, long value) {
47-
addProperty(key, new Long(value).toString());
48-
}
49-
50-
protected void addProperty(String key, String value) {
51-
if ((key != null) && (value != null)) {
52-
properties.putObject(key, value);
53-
}
54-
}
55-
56-
protected String asEscaped(String s) {
57-
if (s == null) {
58-
return s;
59-
}
60-
return asEscapedString(s);
61-
}
62-
63-
protected String asEscapedXml(String s) {
64-
if (s == null) {
65-
return s;
66-
}
67-
return asEscapedXmlString(s);
68-
}
69-
7044
public abstract TafProperties basicExecCommand(TafProperties props);
7145

72-
// protected void click(Component c, int mask) {
73-
// if (c != null) {
74-
// if (c.getBounds().isEmpty()) {
75-
// System.out.println("Can't click --> has no bounds!");
76-
// return;
77-
// }
78-
// waitUntilReady();
79-
// Point upperLeft = c.getLocationOnScreen();
80-
// Rectangle bounds = new Rectangle(upperLeft.x, upperLeft.y, c.getWidth(), c.getHeight());
81-
// Point p = new Point(new Double(bounds.getCenterX()).intValue(), new Double(bounds.getCenterY()).intValue());
82-
// click(p, mask);
83-
// }
84-
// }
85-
//
86-
// protected void click(Point p, int mask) {
87-
// while (Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() != null) {};
88-
// try {
89-
// System.out.println("Click auf " + p);
90-
// Robot robot = new Robot();
91-
// robot.mouseMove(p.x, p.y);
92-
// robot.mousePress(mask);
93-
// robot.delay(100);
94-
// robot.mouseRelease(mask);
95-
// }
96-
// catch (Exception e) {
97-
// e.printStackTrace();
98-
// }
99-
// }
100-
101-
public static long TIMEOUT_FOR_EXECUTION_IN_SECONDS = 10;
102-
10346
public TafProperties execCommand(TafProperties props) {
10447
boolean timedOut = false;
10548
long time = System.currentTimeMillis();
@@ -109,8 +52,8 @@ public TafProperties execCommand(TafProperties props) {
10952
System.out.println("ASwElement --> execCommand");
11053
try {
11154
if (!getType().equalsIgnoreCase(incomingProps.getString("type"))) {
112-
return getErrorProperties("wrong type (expected = " + getType() + ", actual = "
113-
+ incomingProps.getString("type"));
55+
return getErrorProperties(
56+
"wrong type (expected = " + getType() + ", actual = " + incomingProps.getString("type"));
11457
}
11558
incomingProps = basicExecCommand(incomingProps);
11659
System.out.println("ASwElement --> execCommand successfully completed");
@@ -123,8 +66,7 @@ public TafProperties execCommand(TafProperties props) {
12366
try {
12467
Thread.sleep(200);
12568
}
126-
catch (Exception e2) {
127-
}
69+
catch (Exception e2) {}
12870
}
12971
if (System.currentTimeMillis() > time + (TIMEOUT_FOR_EXECUTION_IN_SECONDS * 1000)) {
13072
System.out.println("ASwElement --> execCommand --> TIMED OUT");
@@ -136,16 +78,6 @@ public TafProperties execCommand(TafProperties props) {
13678

13779
public abstract void fillProperties();
13880

139-
// public String getTagName() {
140-
// if (tagName == null) {
141-
// return "null-tag";
142-
// }
143-
// if (tagName.isEmpty()) {
144-
// return "empty-tag-" + component.getClass().getSimpleName();
145-
// }
146-
// return tagName;
147-
// }
148-
14981
public <T extends Enum<T>> T getCommand(Class<T> c, String command) {
15082
if (c != null && command != null) {
15183
try {
@@ -158,17 +90,34 @@ public <T extends Enum<T>> T getCommand(Class<T> c, String command) {
15890

15991
public abstract Component getComponent();
16092

161-
private TafProperties getDoneProperties(TafProperties props) {
162-
props.putObject("status", "done");
163-
return props;
164-
}
165-
166-
private TafProperties getErrorProperties(String message) {
167-
TafProperties result = new TafProperties();
168-
result.putObject("status", "error");
169-
result.putObject("message", message);
170-
return result;
171-
}
93+
// protected void click(Component c, int mask) {
94+
// if (c != null) {
95+
// if (c.getBounds().isEmpty()) {
96+
// System.out.println("Can't click --> has no bounds!");
97+
// return;
98+
// }
99+
// waitUntilReady();
100+
// Point upperLeft = c.getLocationOnScreen();
101+
// Rectangle bounds = new Rectangle(upperLeft.x, upperLeft.y, c.getWidth(), c.getHeight());
102+
// Point p = new Point(new Double(bounds.getCenterX()).intValue(), new Double(bounds.getCenterY()).intValue());
103+
// click(p, mask);
104+
// }
105+
// }
106+
//
107+
// protected void click(Point p, int mask) {
108+
// while (Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() != null) {};
109+
// try {
110+
// System.out.println("Click auf " + p);
111+
// Robot robot = new Robot();
112+
// robot.mouseMove(p.x, p.y);
113+
// robot.mousePress(mask);
114+
// robot.delay(100);
115+
// robot.mouseRelease(mask);
116+
// }
117+
// catch (Exception e) {
118+
// e.printStackTrace();
119+
// }
120+
// }
172121

173122
public abstract AbstractComponentFixture getFixture();
174123

@@ -186,6 +135,16 @@ public String getPropertiesAsString() {
186135
return attributes;
187136
}
188137

138+
// public String getTagName() {
139+
// if (tagName == null) {
140+
// return "null-tag";
141+
// }
142+
// if (tagName.isEmpty()) {
143+
// return "empty-tag-" + component.getClass().getSimpleName();
144+
// }
145+
// return tagName;
146+
// }
147+
189148
@Override
190149
public Component getReference() {
191150
return component;
@@ -221,6 +180,46 @@ public String toString() {
221180
return "tagName=" + getType() + " " + component.toString();
222181
}
223182

183+
protected void addProperty(String key, int value) {
184+
addProperty(key, Integer.valueOf(value).toString());
185+
}
186+
187+
protected void addProperty(String key, long value) {
188+
addProperty(key, Long.valueOf(value).toString());
189+
}
190+
191+
protected void addProperty(String key, String value) {
192+
if ((key != null) && (value != null)) {
193+
properties.putObject(key, value);
194+
}
195+
}
196+
197+
protected String asEscaped(String s) {
198+
if (s == null) {
199+
return s;
200+
}
201+
return asEscapedString(s);
202+
}
203+
204+
protected String asEscapedXml(String s) {
205+
if (s == null) {
206+
return s;
207+
}
208+
return asEscapedXmlString(s);
209+
}
210+
211+
private TafProperties getDoneProperties(TafProperties props) {
212+
props.putObject("status", "done");
213+
return props;
214+
}
215+
216+
private TafProperties getErrorProperties(String message) {
217+
TafProperties result = new TafProperties();
218+
result.putObject("status", "error");
219+
result.putObject("message", message);
220+
return result;
221+
}
222+
224223
// public void waitUntilReady() {
225224
// while (Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() != null) {}
226225
// ;

0 commit comments

Comments
 (0)