26
26
import java .io .Serializable ;
27
27
import java .util .List ;
28
28
29
- @ SuppressWarnings ("serial" )
30
29
public abstract class AppiumBy extends By implements Remotable {
31
30
32
31
@ Getter private final Parameters remoteParameters ;
@@ -38,7 +37,6 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
38
37
this .locatorName = locatorName ;
39
38
}
40
39
41
- @ SuppressWarnings ("unchecked" )
42
40
@ Override public List <WebElement > findElements (SearchContext context ) {
43
41
return context .findElements (this );
44
42
}
@@ -48,7 +46,7 @@ protected AppiumBy(String selector, String locatorString, String locatorName) {
48
46
}
49
47
50
48
@ Override public String toString () {
51
- return String .format ("AppiumBy .%s: %s" , locatorName , remoteParameters .value ());
49
+ return String .format ("%s .%s: %s" , AppiumBy . class . getSimpleName () , locatorName , remoteParameters .value ());
52
50
}
53
51
54
52
/**
@@ -115,6 +113,26 @@ public static By className(final String selector) {
115
113
return new ByClassName (selector );
116
114
}
117
115
116
+ /**
117
+ * For IOS the element name.
118
+ * For Android it is the resource identifier.
119
+ * @param selector element id
120
+ * @return an instance of {@link ById}
121
+ */
122
+ public static By id (final String selector ) {
123
+ return new ById (selector );
124
+ }
125
+
126
+ /**
127
+ * For IOS the element name.
128
+ * For Android it is the resource identifier.
129
+ * @param selector element id
130
+ * @return an instance of {@link ByName}
131
+ */
132
+ public static By name (final String selector ) {
133
+ return new ByName (selector );
134
+ }
135
+
118
136
/**
119
137
* This type of locator requires the use of the 'customFindModules' capability and a
120
138
* separately-installed element finding plugin.
@@ -165,70 +183,72 @@ public static By iOSNsPredicateString(final String iOSNsPredicateString) {
165
183
}
166
184
167
185
public static class ByAccessibilityId extends AppiumBy implements Serializable {
168
-
169
186
public ByAccessibilityId (String accessibilityId ) {
170
187
super ("accessibility id" , accessibilityId , "accessibilityId" );
171
188
}
172
189
}
173
190
174
191
public static class ByAndroidDataMatcher extends AppiumBy implements Serializable {
175
-
176
192
protected ByAndroidDataMatcher (String locatorString ) {
177
193
super ("-android datamatcher" , locatorString , "androidDataMatcher" );
178
194
}
179
195
}
180
196
181
197
public static class ByAndroidUIAutomator extends AppiumBy implements Serializable {
182
-
183
198
public ByAndroidUIAutomator (String uiautomatorText ) {
184
199
super ("-android uiautomator" , uiautomatorText , "androidUIAutomator" );
185
200
}
186
201
}
187
202
188
203
public static class ByAndroidViewMatcher extends AppiumBy implements Serializable {
189
-
190
204
protected ByAndroidViewMatcher (String locatorString ) {
191
205
super ("-android viewmatcher" , locatorString , "androidViewMatcher" );
192
206
}
193
207
}
194
208
195
209
public static class ByAndroidViewTag extends AppiumBy implements Serializable {
196
-
197
210
public ByAndroidViewTag (String tag ) {
198
211
super ("-android viewtag" , tag , "androidViewTag" );
199
212
}
200
213
}
201
214
202
- public static class ByClassName extends AppiumBy implements Serializable {
215
+ public static class ById extends AppiumBy implements Serializable {
216
+ protected ById (String selector ) {
217
+ super ("id" , selector , "id" );
218
+ }
219
+ }
220
+
221
+ public static class ByName extends AppiumBy implements Serializable {
222
+ protected ByName (String selector ) {
223
+ super ("name" , selector , "name" );
224
+ }
225
+ }
203
226
227
+ public static class ByClassName extends AppiumBy implements Serializable {
204
228
protected ByClassName (String selector ) {
205
229
super ("class name" , selector , "className" );
206
230
}
207
231
}
208
232
209
233
public static class ByCustom extends AppiumBy implements Serializable {
210
-
211
234
protected ByCustom (String selector ) {
212
235
super ("-custom" , selector , "custom" );
213
236
}
214
237
}
215
238
216
239
public static class ByImage extends AppiumBy implements Serializable {
217
-
218
240
protected ByImage (String b64Template ) {
219
241
super ("-image" , b64Template , "image" );
220
242
}
221
243
}
222
244
223
245
public static class ByIosClassChain extends AppiumBy implements Serializable {
224
-
225
246
protected ByIosClassChain (String locatorString ) {
226
247
super ("-ios class chain" , locatorString , "iOSClassChain" );
227
248
}
228
249
}
229
250
230
251
public static class ByIosNsPredicate extends AppiumBy implements Serializable {
231
-
232
252
protected ByIosNsPredicate (String locatorString ) {
233
253
super ("-ios predicate string" , locatorString , "iOSNsPredicate" );
234
254
}
0 commit comments