Skip to content

Commit bcac648

Browse files
committed
refactor!: unify MobileBy methods naming and toString implementations
BREAKING CHANGE: 1) rename methods: - `MobileBy#AndroidUIAutomator` -> `MobileBy#androidUIAutomator` - `MobileBy#AccessibilityId` -> `MobileBy#accessibilityId` - `MobileBy#AndroidViewTag` -> `MobileBy#androidViewTag` 2) Update `toString` implementation: - `"By.AndroidUIAutomator: "` -> "By.androidUIAutomator: " - `"By.AccessibilityId: "` -> "By.accessibilityId: " - `"By.IosClassChain: "` -> "By.iOSClassChain: " - `"By.AndroidViewMatcher: "` -> "By.androidViewMatcher: " - `"By.IosNsPredicate: "` -> "By.iOSNsPredicate: " - `"By.Image: "` -> "By.image: " - `"By.Custom: "` -> "By.custom: " - `"By.AndroidViewTag: "` -> "By.androidViewTag: "
1 parent 92396dc commit bcac648

19 files changed

+87
-90
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public Parameters getRemoteParameters() {
6060
* @param uiautomatorText is Android UIAutomator string
6161
* @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}
6262
*/
63-
public static By AndroidUIAutomator(final String uiautomatorText) {
63+
public static By androidUIAutomator(final String uiautomatorText) {
6464
return new ByAndroidUIAutomator(uiautomatorText);
6565
}
6666

@@ -73,7 +73,7 @@ public static By AndroidUIAutomator(final String uiautomatorText) {
7373
* @param accessibilityId id is a convenient UI automation accessibility Id.
7474
* @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}
7575
*/
76-
public static By AccessibilityId(final String accessibilityId) {
76+
public static By accessibilityId(final String accessibilityId) {
7777
return new ByAccessibilityId(accessibilityId);
7878
}
7979

@@ -129,7 +129,7 @@ public static By windowsAutomation(final String windowsAutomation) {
129129
* @param tag is an view tag string
130130
* @return an instance of {@link ByAndroidViewTag}
131131
*/
132-
public static By AndroidViewTag(final String tag) {
132+
public static By androidViewTag(final String tag) {
133133
return new ByAndroidViewTag(tag);
134134
}
135135

@@ -179,7 +179,7 @@ public ByAndroidUIAutomator(String uiautomatorText) {
179179
}
180180

181181
@Override public String toString() {
182-
return "By.AndroidUIAutomator: " + getLocatorString();
182+
return "By.androidUIAutomator: " + getLocatorString();
183183
}
184184
}
185185

@@ -191,7 +191,7 @@ public ByAccessibilityId(String accessibilityId) {
191191
}
192192

193193
@Override public String toString() {
194-
return "By.AccessibilityId: " + getLocatorString();
194+
return "By.accessibilityId: " + getLocatorString();
195195
}
196196
}
197197

@@ -202,7 +202,7 @@ protected ByIosClassChain(String locatorString) {
202202
}
203203

204204
@Override public String toString() {
205-
return "By.IosClassChain: " + getLocatorString();
205+
return "By.iOSClassChain: " + getLocatorString();
206206
}
207207
}
208208

@@ -213,7 +213,7 @@ protected ByAndroidDataMatcher(String locatorString) {
213213
}
214214

215215
@Override public String toString() {
216-
return "By.AndroidDataMatcher: " + getLocatorString();
216+
return "By.androidDataMatcher: " + getLocatorString();
217217
}
218218
}
219219

@@ -224,7 +224,7 @@ protected ByAndroidViewMatcher(String locatorString) {
224224
}
225225

226226
@Override public String toString() {
227-
return "By.AndroidViewMatcher: " + getLocatorString();
227+
return "By.androidViewMatcher: " + getLocatorString();
228228
}
229229
}
230230

@@ -235,7 +235,7 @@ protected ByIosNsPredicate(String locatorString) {
235235
}
236236

237237
@Override public String toString() {
238-
return "By.IosNsPredicate: " + getLocatorString();
238+
return "By.iOSNsPredicate: " + getLocatorString();
239239
}
240240
}
241241

@@ -254,7 +254,7 @@ protected ByImage(String b64Template) {
254254
}
255255

256256
@Override public String toString() {
257-
return "By.Image: " + getLocatorString();
257+
return "By.image: " + getLocatorString();
258258
}
259259
}
260260

@@ -265,7 +265,7 @@ protected ByCustom(String selector) {
265265
}
266266

267267
@Override public String toString() {
268-
return "By.Custom: " + getLocatorString();
268+
return "By.custom: " + getLocatorString();
269269
}
270270
}
271271

@@ -276,7 +276,7 @@ public ByAndroidViewTag(String tag) {
276276
}
277277

278278
@Override public String toString() {
279-
return "By.AndroidViewTag: " + getLocatorString();
279+
return "By.androidViewTag: " + getLocatorString();
280280
}
281281
}
282282

src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import io.appium.java_client.MobileBy;
2020
import io.appium.java_client.pagefactory.AndroidBy;
2121
import io.appium.java_client.pagefactory.AndroidFindBy;
22-
import io.appium.java_client.pagefactory.iOSBy;
22+
2323
import org.openqa.selenium.By;
2424

2525
import java.lang.annotation.Annotation;
@@ -34,14 +34,14 @@ enum Strategies {
3434
String value = getValue(annotation, this);
3535
if (annotation.annotationType().equals(AndroidFindBy.class)
3636
|| annotation.annotationType().equals(AndroidBy.class)) {
37-
return MobileBy.AndroidUIAutomator(value);
37+
return MobileBy.androidUIAutomator(value);
3838
}
3939
return super.getBy(annotation);
4040
}
4141
},
4242
BYACCESSABILITY("accessibility") {
4343
@Override By getBy(Annotation annotation) {
44-
return MobileBy.AccessibilityId(getValue(annotation, this));
44+
return MobileBy.accessibilityId(getValue(annotation, this));
4545
}
4646
},
4747
BYCLASSNAME("className") {

src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
3737

3838
private final ActionSupplier<AndroidTouchAction> verticalSwiping = () ->
3939
new AndroidTouchAction(driver)
40-
.press(element(driver.findElement(MobileBy.AccessibilityId("Gallery"))))
40+
.press(element(driver.findElement(MobileBy.accessibilityId("Gallery"))))
4141

4242
.waitAction(waitOptions(ofSeconds(2)))
4343

44-
.moveTo(element(driver.findElement(MobileBy.AccessibilityId("Auto Complete"))))
44+
.moveTo(element(driver.findElement(MobileBy.accessibilityId("Auto Complete"))))
4545
.release();
4646

4747
@Test public void horizontalSwipingWithSupplier() {
@@ -59,11 +59,11 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
5959

6060
@Test public void verticalSwipingWithSupplier() throws Exception {
6161
driver.resetApp();
62-
driver.findElement(MobileBy.AccessibilityId("Views")).click();
62+
driver.findElement(MobileBy.accessibilityId("Views")).click();
6363

64-
Point originalLocation = driver.findElement(MobileBy.AccessibilityId("Gallery")).getLocation();
64+
Point originalLocation = driver.findElement(MobileBy.accessibilityId("Gallery")).getLocation();
6565
verticalSwiping.get().perform();
6666
Thread.sleep(5000);
67-
assertNotEquals(originalLocation, driver.findElement(MobileBy.AccessibilityId("Gallery")).getLocation());
67+
assertNotEquals(originalLocation, driver.findElement(MobileBy.accessibilityId("Gallery")).getLocation());
6868
}
6969
}

src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class AndroidDataMatcherTest extends BaseEspressoTest {
3232
public void testFindByDataMatcher() {
3333
final WebDriverWait wait = new WebDriverWait(driver, 10);
3434
wait.until(ExpectedConditions
35-
.elementToBeClickable(MobileBy.AccessibilityId("Graphics")));
36-
driver.findElement(MobileBy.AccessibilityId("Graphics")).click();
35+
.elementToBeClickable(MobileBy.accessibilityId("Graphics")));
36+
driver.findElement(MobileBy.accessibilityId("Graphics")).click();
3737

3838
String selector = new Json().toJson(ImmutableMap.of(
3939
"name", "hasEntry",

src/test/java/io/appium/java_client/android/AndroidElementTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ public class AndroidElementTest extends BaseAndroidTest {
3636

3737
@Test public void findByAccessibilityIdTest() {
3838
assertNotEquals(driver.findElement(By.id("android:id/content"))
39-
.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null);
39+
.findElement(MobileBy.accessibilityId("Graphics")).getText(), null);
4040
assertEquals(driver.findElement(By.id("android:id/content"))
41-
.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1);
41+
.findElements(MobileBy.accessibilityId("Graphics")).size(), 1);
4242
}
4343

4444
@Test public void findByAndroidUIAutomatorTest() {
4545
assertNotEquals(driver.findElement(By.id("android:id/content"))
4646
.findElement(MobileBy
47-
.AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
47+
.androidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
4848
assertNotEquals(driver.findElement(By.id("android:id/content"))
4949
.findElements(MobileBy
50-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
50+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
5151
assertNotEquals(driver.findElement(By.id("android:id/content"))
5252
.findElements(MobileBy
53-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
53+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
5454
}
5555

5656
@Test public void replaceValueTest() {
@@ -59,7 +59,7 @@ public class AndroidElementTest extends BaseAndroidTest {
5959
Activity activity = new Activity("io.appium.android.apis", ".view.Controls1");
6060
driver.startActivity(activity);
6161
AndroidElement editElement = driver
62-
.findElement(MobileBy.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
62+
.findElement(MobileBy.androidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
6363
editElement.sendKeys(originalValue);
6464
assertEquals(originalValue, editElement.getText());
6565
String replacedValue = "replaced value";
@@ -68,11 +68,11 @@ public class AndroidElementTest extends BaseAndroidTest {
6868
}
6969

7070
@Test public void scrollingToSubElement() {
71-
driver.findElement(MobileBy.AccessibilityId("Views")).click();
71+
driver.findElement(MobileBy.accessibilityId("Views")).click();
7272
AndroidElement list = driver.findElement(By.id("android:id/list"));
7373
MobileElement radioGroup = list
7474
.findElement(MobileBy
75-
.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
75+
.androidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
7676
+ "new UiSelector().text(\"Radio Group\"));"));
7777
assertNotNull(radioGroup.getLocation());
7878
}
@@ -83,7 +83,7 @@ public class AndroidElementTest extends BaseAndroidTest {
8383
Activity activity = new Activity("io.appium.android.apis", ".view.Controls1");
8484
driver.startActivity(activity);
8585
AndroidElement editElement = driver
86-
.findElement(MobileBy.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
86+
.findElement(MobileBy.androidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
8787
editElement.setValue(value);
8888
assertEquals(value, editElement.getText());
8989
}

src/test/java/io/appium/java_client/android/AndroidSearchingTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ public void setup() {
3535
}
3636

3737
@Test public void findByAccessibilityIdTest() {
38-
assertNotEquals(driver.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null);
39-
assertEquals(driver.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1);
38+
assertNotEquals(driver.findElement(MobileBy.accessibilityId("Graphics")).getText(), null);
39+
assertEquals(driver.findElements(MobileBy.accessibilityId("Graphics")).size(), 1);
4040
}
4141

4242
@Test public void findByAndroidUIAutomatorTest() {
4343
assertNotEquals(driver
4444
.findElement(MobileBy
45-
.AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
45+
.androidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
4646
assertNotEquals(driver
4747
.findElements(MobileBy
48-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
48+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
4949
assertNotEquals(driver
5050
.findElements(MobileBy
51-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
51+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
5252
}
5353

5454
@Test public void findByXPathTest() {
@@ -58,9 +58,9 @@ public void setup() {
5858
}
5959

6060
@Test public void findScrollable() {
61-
driver.findElement(MobileBy.AccessibilityId("Views")).click();
61+
driver.findElement(MobileBy.accessibilityId("Views")).click();
6262
MobileElement radioGroup = driver
63-
.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()"
63+
.findElement(MobileBy.androidUIAutomator("new UiScrollable(new UiSelector()"
6464
+ ".resourceId(\"android:id/list\")).scrollIntoView("
6565
+ "new UiSelector().text(\"Radio Group\"));"));
6666
assertNotNull(radioGroup.getLocation());

src/test/java/io/appium/java_client/android/FingerPrintTest.java

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

1717
package io.appium.java_client.android;
1818

19-
import static io.appium.java_client.MobileBy.AndroidUIAutomator;
19+
import static io.appium.java_client.MobileBy.androidUIAutomator;
2020
import static java.util.concurrent.TimeUnit.SECONDS;
2121

2222
import io.appium.java_client.remote.MobileCapabilityType;
@@ -89,7 +89,7 @@ private void enterPasswordAndContinue() {
8989
}
9090

9191
private void clickOnSecurity() {
92-
driver.findElement(AndroidUIAutomator("new UiScrollable(new UiSelector()"
92+
driver.findElement(androidUIAutomator("new UiScrollable(new UiSelector()"
9393
+ ".scrollable(true)).scrollIntoView("
9494
+ "new UiSelector().text(\"Security & location\"));")).click();
9595
}

src/test/java/io/appium/java_client/android/UIAutomator2Test.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void afterMethod() {
2525
public void testLandscapeRightRotation() {
2626
new WebDriverWait(driver, 20).until(ExpectedConditions
2727
.elementToBeClickable(driver.findElement(By.id("android:id/content"))
28-
.findElement(MobileBy.AccessibilityId("Graphics"))));
28+
.findElement(MobileBy.accessibilityId("Graphics"))));
2929
DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90);
3030
driver.rotate(landscapeRightRotation);
3131
assertEquals(driver.rotation(), landscapeRightRotation);
@@ -35,7 +35,7 @@ public void testLandscapeRightRotation() {
3535
public void testLandscapeLeftRotation() {
3636
new WebDriverWait(driver, 20).until(ExpectedConditions
3737
.elementToBeClickable(driver.findElement(By.id("android:id/content"))
38-
.findElement(MobileBy.AccessibilityId("Graphics"))));
38+
.findElement(MobileBy.accessibilityId("Graphics"))));
3939
DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270);
4040
driver.rotate(landscapeLeftRotation);
4141
assertEquals(driver.rotation(), landscapeLeftRotation);
@@ -45,7 +45,7 @@ public void testLandscapeLeftRotation() {
4545
public void testPortraitUpsideDown() {
4646
new WebDriverWait(driver, 20).until(ExpectedConditions
4747
.elementToBeClickable(driver.findElement(By.id("android:id/content"))
48-
.findElement(MobileBy.AccessibilityId("Graphics"))));
48+
.findElement(MobileBy.accessibilityId("Graphics"))));
4949
DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180);
5050
driver.rotate(landscapeRightRotation);
5151
assertEquals(driver.rotation(), landscapeRightRotation);
@@ -61,8 +61,8 @@ public void testToastMSGIsDisplayed() {
6161
driver.startActivity(activity);
6262

6363
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy
64-
.AccessibilityId("Make a Popup!")));
65-
MobileElement popUpElement = driver.findElement(MobileBy.AccessibilityId("Make a Popup!"));
64+
.accessibilityId("Make a Popup!")));
65+
MobileElement popUpElement = driver.findElement(MobileBy.accessibilityId("Make a Popup!"));
6666
wait.until(ExpectedConditions.elementToBeClickable(popUpElement)).click();
6767
wait.until(ExpectedConditions.visibilityOfElementLocated(
6868
By.xpath(".//*[@text='Search']"))).click();

src/test/java/io/appium/java_client/appium/AndroidTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,39 +83,39 @@ public Response execute(String driverCommand) {
8383

8484
@Test
8585
public void findByAccessibilityIdFromDriverTest() {
86-
assertNotEquals(driver.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null);
87-
assertEquals(driver.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1);
86+
assertNotEquals(driver.findElement(MobileBy.accessibilityId("Graphics")).getText(), null);
87+
assertEquals(driver.findElements(MobileBy.accessibilityId("Graphics")).size(), 1);
8888
}
8989

9090
@Test public void findByAndroidUIAutomatorFromDriverTest() {
9191
assertNotEquals(driver
9292
.findElement(MobileBy
93-
.AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
93+
.androidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
9494
assertNotEquals(driver
9595
.findElements(MobileBy
96-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
96+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
9797
assertNotEquals(driver
9898
.findElements(MobileBy
99-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
99+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
100100
}
101101

102102
@Test public void findByAccessibilityIdFromElementTest() {
103103
assertNotEquals(driver.findElement(By.id("android:id/content"))
104-
.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null);
104+
.findElement(MobileBy.accessibilityId("Graphics")).getText(), null);
105105
assertEquals(driver.findElement(By.id("android:id/content"))
106-
.findElements(MobileBy.AccessibilityId("Graphics")).size(), 1);
106+
.findElements(MobileBy.accessibilityId("Graphics")).size(), 1);
107107
}
108108

109109
@Test public void findByAndroidUIAutomatorFromElementTest() {
110110
assertNotEquals(driver.findElement(By.id("android:id/content"))
111111
.findElement(MobileBy
112-
.AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
112+
.androidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
113113
assertNotEquals(driver.findElement(By.id("android:id/content"))
114114
.findElements(MobileBy
115-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
115+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
116116
assertNotEquals(driver.findElement(By.id("android:id/content"))
117117
.findElements(MobileBy
118-
.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
118+
.androidUIAutomator("new UiSelector().clickable(true)")).size(), 1);
119119
}
120120

121121
@Test public void replaceValueTest() {
@@ -125,7 +125,7 @@ public void findByAccessibilityIdFromDriverTest() {
125125
startsActivity.startActivity(activity);
126126
AndroidElement editElement = driver
127127
.findElement(MobileBy
128-
.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
128+
.androidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
129129
editElement.sendKeys(originalValue);
130130
assertEquals(originalValue, editElement.getText());
131131
String replacedValue = "replaced value";
@@ -134,11 +134,11 @@ public void findByAccessibilityIdFromDriverTest() {
134134
}
135135

136136
@Test public void scrollingToSubElement() {
137-
driver.findElement(MobileBy.AccessibilityId("Views")).click();
137+
driver.findElement(MobileBy.accessibilityId("Views")).click();
138138
AndroidElement list = driver.findElement(By.id("android:id/list"));
139139
MobileElement radioGroup = list
140140
.findElement(MobileBy
141-
.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
141+
.androidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
142142
+ "new UiSelector().text(\"Radio Group\"));"));
143143
assertNotNull(radioGroup.getLocation());
144144
}

0 commit comments

Comments
 (0)