Skip to content

Commit 5505387

Browse files
Merge pull request #646 from TikhomirovSergey/master
#565 FIX
2 parents 3768529 + a736259 commit 5505387

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1206
-232
lines changed

docs/Page-objects.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ RemoteWebElement someElement;
145145
List<RemoteWebElement> someElements;
146146
```
147147

148-
## Also possible combined variants:
148+
## Also possible combined variants for target platforms:
149149

150150
```java
151151
import org.openqa.selenium.remote.RemoteWebElement;
@@ -194,6 +194,67 @@ RemoteWebElement someElement;
194194
List<RemoteWebElement> someElements;
195195
```
196196

197+
## Mixed chain/any locator strategy
198+
199+
Some locator-element could not be defined certainly sometimes. It may be defined as one of possible variants/chained locator.
200+
If the using of _xpath_ is not convenient for some reasons so there are possible use cases
201+
202+
### the chained searching
203+
204+
```java
205+
import org.openqa.selenium.remote.RemoteWebElement;
206+
import io.appium.java_client.pagefactory.*;
207+
import org.openqa.selenium.support.FindBys;
208+
import org.openqa.selenium.support.FindBy;
209+
210+
//it is necessary to define priorities at this case. The lower number means the higher priority.
211+
//The default value is 0 (the highest priority)
212+
@iOSFindBy(someStrategy1)
213+
@iOSFindAll(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //it means that the chained searching contains
214+
//the searching by all possible locators as the element of the chain
215+
@iOSFindBy(someStrategy2, priority = 2)
216+
@iOSFindBy(someStrategy3, priority = 3)
217+
RemoteWebElement someElement;
218+
219+
220+
@iOSFindBy(someStrategy1)
221+
@iOSFindAll(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //it means that the chained searching contains
222+
//the searching by all possible locators as the element of the chain
223+
@iOSFindBy(someStrategy2, priority = 2)
224+
@iOSFindBy(someStrategy3, priority = 3)
225+
List<RemoteWebElement> someElements;
226+
```
227+
228+
### all possible
229+
230+
```java
231+
import org.openqa.selenium.remote.RemoteWebElement;
232+
import io.appium.java_client.pagefactory.*;
233+
import org.openqa.selenium.support.FindBys;
234+
import org.openqa.selenium.support.FindBy;
235+
236+
//it is not necessary to define priorities at this case. But it can manage the searching.
237+
//The lower number means the higher priority.
238+
//The default value is 0 (the highest priority)
239+
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
240+
@iOSFindBy(someStrategy1)
241+
@iOSFindBys(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //it means that the searching by all possible locators
242+
// contains the searching by chained locator as one of all possible variants
243+
@iOSFindBy(someStrategy2, priority = 2)
244+
@iOSFindBy(someStrategy3, priority = 3)
245+
RemoteWebElement someElement;
246+
247+
248+
249+
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
250+
@iOSFindBy(someStrategy1)
251+
@iOSFindBys(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //it means that the searching by all possible locators
252+
// contains the searching by chained locator as one of all possible variants
253+
@iOSFindBy(someStrategy2, priority = 2)
254+
@iOSFindBy(someStrategy3, priority = 3)
255+
List<RemoteWebElement> someElements;
256+
```
257+
197258
# Appium Java client is integrated with Selenium PageFactory by AppiumFieldDecorator.
198259

199260
Object fields are populated as below:

google-style.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
value="Package name ''{0}'' must match pattern ''{1}''."/>
9898
</module>
9999
<module name="TypeName">
100-
<property name="format" value="^([iOSFindBys]||[iOSFindBy]||[iOSFindAll])||([A-Z][a-zA-Z0-9])*$"/>
100+
<property name="format" value="^([*iOSFindBy*]||[*iOSXCUITFind*])||([A-Z][a-zA-Z0-9])*$"/>
101101
<message key="name.invalidPattern"
102102
value="Type name ''{0}'' must match pattern ''{1}''."/>
103103
</module>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client;
1818

19+
import static nu.pattern.OpenCV.loadShared;
20+
1921
import org.opencv.core.Core;
2022
import org.opencv.core.CvType;
2123
import org.opencv.core.Mat;
@@ -32,8 +34,6 @@
3234
import java.util.function.Function;
3335
import java.util.function.Supplier;
3436

35-
import static nu.pattern.OpenCV.loadShared;
36-
3737
public class ScreenshotState {
3838
private static final Duration DEFAULT_INTERVAL_MS = Duration.ofMillis(500);
3939

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
package io.appium.java_client.pagefactory;
18+
19+
/**
20+
* Used to build a complex android automator locator.
21+
*/
22+
public @interface AndroidBy {
23+
/**
24+
* It is an is Android UIAutomator string.
25+
* Read http://developer.android.com/intl/ru/tools/testing-support-library/
26+
* index.html#uia-apis
27+
*/
28+
String uiAutomator() default "";
29+
30+
/**
31+
* It an UI automation accessibility Id which is a convenient to Android.
32+
* About Android accessibility
33+
* https://developer.android.com/intl/ru/training/accessibility/accessible-app.html
34+
*/
35+
String accessibility() default "";
36+
37+
/**
38+
* It is an id of the target element.
39+
*/
40+
String id() default "";
41+
42+
/**
43+
* It is a className of the target element.
44+
*/
45+
String className() default "";
46+
47+
/**
48+
* It is a desired element tag.
49+
*/
50+
String tagName() default "";
51+
52+
/**
53+
* It is a xpath to the target element.
54+
*/
55+
String xpath() default "";
56+
57+
/**
58+
* @return priority of the searching. Higher number means lower priority.
59+
*/
60+
int priority() default 0;
61+
}

src/main/java/io/appium/java_client/pagefactory/AndroidFindAll.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,31 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19-
import java.lang.annotation.ElementType;
19+
import static java.lang.annotation.ElementType.FIELD;
20+
import static java.lang.annotation.ElementType.TYPE;
21+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
22+
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
21-
import java.lang.annotation.RetentionPolicy;
2225
import java.lang.annotation.Target;
2326

2427
/**
2528
* Used to mark a field on a Page/Screen Object to indicate that lookup should use a
26-
* series of {@link io.appium.java_client.pagefactory.AndroidFindBy} tags
29+
* series of {@link io.appium.java_client.pagefactory.AndroidBy} tags
2730
* It will then search for all elements that match any criteria. Note that elements
2831
* are not guaranteed to be in document order.
29-
* It is deprecated. Set of {@link io.appium.java_client.pagefactory.AndroidFindBy}
30-
* can be defined without this annotation. To define the correct way how to use
31-
* the defined set please take a look at {@link HowToUseLocators}. The article.
32-
* https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html.
3332
*/
34-
@Deprecated
35-
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE})
33+
@Retention(RUNTIME) @Target({FIELD, TYPE})
34+
@Repeatable(AndroidFindByAllSet.class)
3635
public @interface AndroidFindAll {
3736
/**
38-
* It is a set of {@link io.appium.java_client.pagefactory.AndroidFindBy} strategies which may
37+
* It is a set of {@link io.appium.java_client.pagefactory.AndroidBy} strategies which may
3938
* be used to find the target element.
4039
*/
41-
AndroidFindBy[] value();
40+
AndroidBy[] value();
41+
42+
/**
43+
* @return priority of the searching. Higher number means lower priority.
44+
*/
45+
int priority() default 0;
4246
}

src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19-
import java.lang.annotation.ElementType;
19+
import static java.lang.annotation.ElementType.FIELD;
20+
import static java.lang.annotation.ElementType.TYPE;
21+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
22+
2023
import java.lang.annotation.Repeatable;
2124
import java.lang.annotation.Retention;
22-
import java.lang.annotation.RetentionPolicy;
2325
import java.lang.annotation.Target;
2426

2527

@@ -30,7 +32,7 @@
3032
* this allows users to quickly and easily create PageObjects.
3133
* using Android UI selectors, accessibility, id, name, class name, tag and xpath
3234
*/
33-
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE})
35+
@Retention(RUNTIME) @Target({FIELD, TYPE})
3436
@Repeatable(AndroidFindBySet.class)
3537
public @interface AndroidFindBy {
3638
/**
@@ -66,4 +68,9 @@
6668
* It is a xpath to the target element.
6769
*/
6870
String xpath() default "";
71+
72+
/**
73+
* @return priority of the searching. Higher number means lower priority.
74+
*/
75+
int priority() default 0;
6976
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.appium.java_client.pagefactory;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.TYPE;
5+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
6+
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.Target;
9+
10+
/**
11+
* Defines set of chained/possible locators. Each one locator
12+
* should be defined with {@link AndroidFindAll}
13+
*/
14+
@Target(value = {TYPE, FIELD})
15+
@Retention(value = RUNTIME)
16+
public @interface AndroidFindByAllSet {
17+
/**
18+
* @return an array of {@link AndroidFindAll} which builds a sequence of
19+
* the chained searching for elements or a set of possible locators
20+
*/
21+
AndroidFindAll[] value();
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.appium.java_client.pagefactory;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.TYPE;
5+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
6+
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.Target;
9+
10+
/**
11+
* Defines set of chained/possible locators. Each one locator
12+
* should be defined with {@link io.appium.java_client.pagefactory.AndroidFindBys}
13+
*/
14+
@Target(value = {TYPE, FIELD})
15+
@Retention(value = RUNTIME)
16+
public @interface AndroidFindByChainSet {
17+
/**
18+
* @return an array of {@link io.appium.java_client.pagefactory.AndroidFindBys} which builds a sequence of
19+
* the chained searching for elements or a set of possible locators
20+
*/
21+
AndroidFindBys[] value();
22+
}

src/main/java/io/appium/java_client/pagefactory/AndroidFindBySet.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19-
import java.lang.annotation.ElementType;
19+
import static java.lang.annotation.ElementType.FIELD;
20+
import static java.lang.annotation.ElementType.TYPE;
21+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
22+
2023
import java.lang.annotation.Retention;
21-
import java.lang.annotation.RetentionPolicy;
2224
import java.lang.annotation.Target;
2325

2426
/**
2527
* Defines set of chained/possible locators. Each one locator
2628
* should be defined with {@link io.appium.java_client.pagefactory.AndroidFindBy}
2729
*/
28-
@Target(value = {ElementType.TYPE, ElementType.FIELD})
29-
@Retention(value = RetentionPolicy.RUNTIME)
30+
@Target(value = {TYPE, FIELD})
31+
@Retention(value = RUNTIME)
3032
public @interface AndroidFindBySet {
3133
/**
3234
* @return an array of {@link io.appium.java_client.pagefactory.AndroidFindBy} which builds a sequence of

src/main/java/io/appium/java_client/pagefactory/AndroidFindBys.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19-
import java.lang.annotation.ElementType;
19+
import static java.lang.annotation.ElementType.FIELD;
20+
import static java.lang.annotation.ElementType.TYPE;
21+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
22+
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
21-
import java.lang.annotation.RetentionPolicy;
2225
import java.lang.annotation.Target;
2326

2427
/**
2528
* Used to mark a field on a Page Object to indicate that lookup should use
26-
* a series of {@link io.appium.java_client.pagefactory.AndroidFindBy} tags.
27-
* It is deprecated. Set of {@link io.appium.java_client.pagefactory.AndroidFindBy}
28-
* can be defined without this annotation. To define the correct way how to use
29-
* the defined set please take a look at {@link HowToUseLocators}. The article.
30-
* https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html.
29+
* a series of {@link io.appium.java_client.pagefactory.AndroidBy} tags.
3130
*/
32-
@Deprecated
33-
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE})
31+
@Retention(RUNTIME) @Target({FIELD, TYPE})
32+
@Repeatable(AndroidFindByChainSet.class)
3433
public @interface AndroidFindBys {
3534
/**
36-
* It is a set of {@link io.appium.java_client.pagefactory.AndroidFindBy} strategies which build
35+
* It is a set of {@link io.appium.java_client.pagefactory.AndroidBy} strategies which build
3736
* the chain of the searching for the target element.
3837
*/
39-
AndroidFindBy[] value();
38+
AndroidBy[] value();
39+
40+
/**
41+
* @return priority of the searching. Higher number means lower priority.
42+
*/
43+
int priority() default 0;
4044
}

0 commit comments

Comments
 (0)