2626
2727@ SuppressWarnings ("serial" )
2828public abstract class MobileBy extends By {
29+
30+ private final String locatorString ;
31+
32+ protected MobileBy (String locatorString ) {
33+ if (StringUtils .isBlank (locatorString )) {
34+ throw new IllegalArgumentException ("Must supply a not empty locator value." );
35+ }
36+ this .locatorString = locatorString ;
37+ }
38+
39+ protected String getLocatorString () {
40+ return locatorString ;
41+ }
42+
2943 /**
3044 * Read https://developer.apple.com/library/tvos/documentation/DeveloperTools/
3145 * Conceptual/InstrumentsUserGuide/UIAutomation.html
3246 *
33- * @param uiautomationText is iOS UIAutomation string
47+ * @param iOSAutomationText is iOS UIAutomation string
3448 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosUIAutomation}
3549 */
36- public static By IosUIAutomation (final String uiautomationText ) {
37- if (StringUtils .isBlank (uiautomationText )) {
38- throw new IllegalArgumentException ("Must supply an iOS UIAutomation string" );
39- }
40-
41- return new ByIosUIAutomation (uiautomationText );
50+ public static By IosUIAutomation (final String iOSAutomationText ) {
51+ return new ByIosUIAutomation (iOSAutomationText );
4252 }
4353
4454 /**
@@ -48,10 +58,6 @@ public static By IosUIAutomation(final String uiautomationText) {
4858 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}
4959 */
5060 public static By AndroidUIAutomator (final String uiautomatorText ) {
51- if (StringUtils .isBlank (uiautomatorText )) {
52- throw new IllegalArgumentException ("Must supply an Android UIAutomator string" );
53- }
54-
5561 return new ByAndroidUIAutomator (uiautomatorText );
5662 }
5763
@@ -61,15 +67,11 @@ public static By AndroidUIAutomator(final String uiautomatorText) {
6167 * About iOS accessibility
6268 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/
6369 * UIAccessibilityIdentification_Protocol/index.html
64- * @param id id is a convenient UI automation accessibility Id.
70+ * @param accessibilityId id is a convenient UI automation accessibility Id.
6571 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}
6672 */
67- public static By AccessibilityId (final String id ) {
68- if (StringUtils .isBlank (id )) {
69- throw new IllegalArgumentException ("Must supply a uiautomationText" );
70- }
71-
72- return new ByAccessibilityId (id );
73+ public static By AccessibilityId (final String accessibilityId ) {
74+ return new ByAccessibilityId (accessibilityId );
7375 }
7476
7577 /**
@@ -78,110 +80,100 @@ public static By AccessibilityId(final String id) {
7880 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosNsPredicate}
7981 */
8082 public static By IosNsPredicateString (final String iOSNsPredicateString ) {
81- if (iOSNsPredicateString == null ) {
82- throw new IllegalArgumentException ("Must supply an iOS NsPredicate String" );
83- }
84-
8583 return new ByIosNsPredicate (iOSNsPredicateString );
8684 }
8785
88- public static class ByIosUIAutomation extends By implements Serializable {
86+ public static class ByIosUIAutomation extends MobileBy implements Serializable {
8987
90- private final String automationText ;
91-
92- public ByIosUIAutomation (String uiautomationText ) {
93- automationText = uiautomationText ;
88+ public ByIosUIAutomation (String iOSAutomationText ) {
89+ super (iOSAutomationText );
9490 }
9591
9692 @ SuppressWarnings ("unchecked" )
9793 @ Override
9894 public List <WebElement > findElements (SearchContext context ) {
9995 return (List <WebElement >) ((FindsByIosUIAutomation <?>) context )
100- .findElementsByIosUIAutomation (automationText );
96+ .findElementsByIosUIAutomation (getLocatorString () );
10197 }
10298
10399 @ Override public WebElement findElement (SearchContext context ) {
104100 return ((FindsByIosUIAutomation <?>) context )
105- .findElementByIosUIAutomation (automationText );
101+ .findElementByIosUIAutomation (getLocatorString () );
106102 }
107103
108104 @ Override public String toString () {
109- return "By.IosUIAutomation: " + automationText ;
105+ return "By.IosUIAutomation: " + getLocatorString () ;
110106 }
111107 }
112108
113- public static class ByIosNsPredicate extends By implements Serializable {
114-
115- private final String automationText ;
116-
117- public ByIosNsPredicate (String uiautomationText ) {
118- automationText = uiautomationText ;
109+ public static class ByIosNsPredicate extends MobileBy implements Serializable {
110+
111+ public ByIosNsPredicate (String iOSNsPredicate ) {
112+ super (iOSNsPredicate );
119113 }
120114
121115 @ SuppressWarnings ("unchecked" )
122116 @ Override public List <WebElement > findElements (SearchContext context ) {
123117 return (List <WebElement >) ((FindsByIosNsPredicate <?>) context )
124- .findElementsByIosNsPredicate (automationText );
118+ .findElementsByIosNsPredicate (getLocatorString () );
125119 }
126120
127121 @ Override public WebElement findElement (SearchContext context ) {
128122 return ((FindsByIosNsPredicate <?>) context )
129- .findElementByIosNsPredicate (automationText );
123+ .findElementByIosNsPredicate (getLocatorString () );
130124 }
131125
132126 @ Override public String toString () {
133- return "By.IosNsPredicate: " + automationText ;
127+ return "By.IosNsPredicate: " + getLocatorString () ;
134128 }
135129 }
136130
137131
138- public static class ByAndroidUIAutomator extends By implements Serializable {
132+ public static class ByAndroidUIAutomator extends MobileBy implements Serializable {
139133
140- private final String automatorText ;
141134
142135 public ByAndroidUIAutomator (String uiautomatorText ) {
143- automatorText = uiautomatorText ;
136+ super ( uiautomatorText ) ;
144137 }
145138
146139 @ SuppressWarnings ("unchecked" )
147140 @ Override
148141 public List <WebElement > findElements (SearchContext context ) {
149142 return (List <WebElement >) ((FindsByAndroidUIAutomator <?>) context )
150- .findElementsByAndroidUIAutomator (automatorText );
143+ .findElementsByAndroidUIAutomator (getLocatorString () );
151144 }
152145
153146 @ Override public WebElement findElement (SearchContext context ) {
154147 return ((FindsByAndroidUIAutomator <?>) context )
155- .findElementByAndroidUIAutomator (automatorText );
148+ .findElementByAndroidUIAutomator (getLocatorString () );
156149 }
157150
158151 @ Override public String toString () {
159- return "By.AndroidUIAutomator: " + automatorText ;
152+ return "By.AndroidUIAutomator: " + getLocatorString () ;
160153 }
161154 }
162155
163156
164- public static class ByAccessibilityId extends By implements Serializable {
165-
166- private final String id ;
157+ public static class ByAccessibilityId extends MobileBy implements Serializable {
167158
168- public ByAccessibilityId (String id ) {
169- this . id = id ;
159+ public ByAccessibilityId (String accessibilityId ) {
160+ super ( accessibilityId ) ;
170161 }
171162
172163 @ SuppressWarnings ("unchecked" )
173164 @ Override
174165 public List <WebElement > findElements (SearchContext context ) {
175166 return (List <WebElement >) ((FindsByAccessibilityId <?>) context )
176- .findElementsByAccessibilityId (id );
167+ .findElementsByAccessibilityId (getLocatorString () );
177168 }
178169
179170 @ Override public WebElement findElement (SearchContext context ) {
180- return ((FindsByAccessibilityId <?>) context ).findElementByAccessibilityId (id );
171+ return ((FindsByAccessibilityId <?>) context )
172+ .findElementByAccessibilityId (getLocatorString ());
181173 }
182174
183175 @ Override public String toString () {
184- return "By.AccessibilityId: " + id ;
176+ return "By.AccessibilityId: " + getLocatorString () ;
185177 }
186178 }
187179}
0 commit comments