Skip to content

Commit dbd958a

Browse files
stonemanTikhomirovSergey
authored andcommitted
#455 fix. The searching by Windows automation
1 parent 94063b7 commit dbd958a

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
package io.appium.java_client;
19+
20+
import org.openqa.selenium.WebElement;
21+
22+
import java.util.List;
23+
24+
public interface FindsByWindowsAutomation<T extends WebElement> {
25+
26+
/**
27+
* Finds the first of elements that match the Windows UIAutomation selector supplied.
28+
*
29+
* @param selector a Windows UIAutomation selector
30+
* @return The first element that matches the given selector
31+
*/
32+
T findElementByWindowsUIAutomation(String selector);
33+
34+
/**
35+
* Finds a list of elements that match the Windows UIAutomation selector supplied.
36+
*
37+
* @param selector a Windows UIAutomation selector
38+
* @return a list of elements that match the given selector
39+
*/
40+
List<T> findElementsByWindowsUIAutomation(String selector);
41+
}

src/main/java/io/appium/java_client/MobileBy.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,58 @@ protected ByIosNsPredicate(String locatorString) {
341341
return "By.IosNsPredicate: " + getLocatorString();
342342
}
343343
}
344+
345+
public static class ByWindowsAutomation extends MobileBy implements Serializable {
346+
347+
protected ByWindowsAutomation(String locatorString) {
348+
super(MobileSelector.WINDOWS_UI_AUTOMATION, locatorString);
349+
}
350+
351+
/**
352+
* @throws WebDriverException when current session doesn't support the given selector or when
353+
* value of the selector is not consistent.
354+
* @throws IllegalArgumentException when it is impossible to find something on the given
355+
* {@link SearchContext} instance
356+
*/
357+
@SuppressWarnings("unchecked")
358+
@Override public List<WebElement> findElements(SearchContext context) {
359+
Class<?> contextClass = context.getClass();
360+
361+
if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {
362+
return FindsByWindowsAutomation.class.cast(context)
363+
.findElementsByWindowsUIAutomation(getLocatorString());
364+
}
365+
366+
if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {
367+
return super.findElements(context);
368+
}
369+
370+
throw formIllegalArgumentException(contextClass, FindsByWindowsAutomation.class,
371+
FindsByFluentSelector.class);
372+
}
373+
374+
/**
375+
* @throws WebDriverException when current session doesn't support the given selector or when
376+
* value of the selector is not consistent.
377+
* @throws IllegalArgumentException when it is impossible to find something on the given
378+
* {@link SearchContext} instance
379+
*/
380+
@Override public WebElement findElement(SearchContext context) {
381+
Class<?> contextClass = context.getClass();
382+
383+
if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {
384+
return FindsByWindowsAutomation.class.cast(context)
385+
.findElementByWindowsUIAutomation(getLocatorString());
386+
}
387+
388+
if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {
389+
return super.findElement(context);
390+
}
391+
392+
throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,
393+
FindsByWindowsAutomation.class);
394+
}
395+
}
344396
}
345397

346398

src/main/java/io/appium/java_client/MobileSelector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum MobileSelector {
2020
ACCESSIBILITY("accessibility id"),
2121
ANDROID_UI_AUTOMATOR("-android uiautomator"),
2222
IOS_UI_AUTOMATION("-ios uiautomation"),
23-
IOS_PREDICATE_STRING("-ios predicate string");
23+
IOS_PREDICATE_STRING("-ios predicate string"),
24+
WINDOWS_UI_AUTOMATION("-windows uiautomation");
2425

2526
private final String selector;
2627

0 commit comments

Comments
 (0)