Skip to content

Commit 1499e0c

Browse files
reverted as per comments
1 parent 7543356 commit 1499e0c

File tree

7 files changed

+50
-25
lines changed

7 files changed

+50
-25
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,11 @@ public List findElementsByTagName(String using) {
100100
return super.findElementsByTagName(using);
101101
}
102102

103-
/**
104-
* @throws WebDriverException This method doesn't work against native app UI.
105-
*/
106-
public T findElementByName(String using) throws WebDriverException{
103+
public T findElementByName(String using) {
107104
return (T) super.findElementByName(using);
108105
}
109106

110-
/**
111-
* @throws WebDriverException This method doesn't work against native app UI.
112-
*/
113-
public List findElementsByName(String using) throws WebDriverException{
107+
public List findElementsByName(String using) {
114108
return super.findElementsByName(using);
115109
}
116110

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
String uiAutomator() default "";
3636
String accessibility() default "";
3737
String id() default "";
38+
@Deprecated
39+
/**
40+
* By.name selector is not supported by Appium server node since 1.5.x.
41+
* So this option is going to be removed further. Be careful.
42+
*/
43+
String name() default "";
3844
String className() default "";
3945
String tagName() default "";
4046
String xpath() default "";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
* element or a list of elements. Used in conjunction with
2828
* {@link org.openqa.selenium.support.PageFactory}
2929
* this allows users to quickly and easily create PageObjects.
30-
* using Selendroid UI selectors like, id, class name, tag and xpath
30+
* using Selendroid UI selectors like, id, name, class name, tag and xpath
3131
*/
3232
@Retention(RetentionPolicy.RUNTIME)
3333
@Target({ElementType.FIELD, ElementType.TYPE})
3434
public @interface SelendroidFindBy {
3535
String id() default "";
36+
String name() default "";
3637
String className() default "";
3738
String tagName() default "";
3839
String xpath() default "";

src/test/java/io/appium/java_client/ios/IOSDriverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void hideKeyboardWithParametersTest() {
124124

125125
@Test
126126
public void scrollToTest() {
127-
MobileElement searchBar = driver.findElementByXpath("//*[@name='Search Bars']");
127+
MobileElement searchBar = driver.findElementByName("Search Bars");
128128
Point before = searchBar.getLocation();
129129
driver.scrollTo("Search Ba");
130130
Point after = searchBar.getLocation();
@@ -133,7 +133,7 @@ public void scrollToTest() {
133133

134134
@Test
135135
public void scrollToExactTest() {
136-
MobileElement searchBar = driver.findElementByXpath("//*[@name='Search Bars']");
136+
MobileElement searchBar = driver.findElementByName("Search Bars");
137137
Point before = searchBar.getLocation();
138138
driver.scrollToExact("Search Bars");
139139
Point after = searchBar.getLocation();

src/test/java/io/appium/java_client/ios/iOSGestureTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void TapSingleFingerTest() {
134134

135135
@Test
136136
public void elementGestureTest(){
137-
MobileElement e = (MobileElement) driver.findElementByXpath("//*[@name='TextField1']");
137+
MobileElement e = (MobileElement) driver.findElementByName("TextField1");
138138
e.tap(1, 1500);
139139
e.zoom();
140140
e.pinch();

src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.junit.Assert.*;
3838

3939
public class SelendroidModeTest {
40-
private static int SELENDROID_PORT = 9999;
40+
private static int SELENDROID_PORT = 9999;
4141

4242
private static WebDriver driver;
4343
private static AppiumDriverLocalService service;
@@ -50,34 +50,43 @@ public class SelendroidModeTest {
5050
@SelendroidFindBy(id = "text1")
5151
private WebElement textSelendroidId;
5252

53+
@SelendroidFindBy(name = "Accessibility")
54+
private WebElement textName;
55+
56+
@AndroidFindBy(xpath = "//*[@name='Accessibility']")
57+
private WebElement textNameAndroid;
58+
59+
@FindBy(name = "Accessibility")
60+
private WebElement textNameDefault;
61+
5362
@SelendroidFindBy(xpath = "//TextView[@value='Accessibility']")
5463
private WebElement textXpath;
5564

5665
@SelendroidFindBys({
57-
@SelendroidFindBy(id = "text1")})
66+
@SelendroidFindBy(id = "text1")})
5867
private WebElement textIds;
5968

6069
@SelendroidFindAll({
61-
@SelendroidFindBy(id = "text1")})
70+
@SelendroidFindBy(id = "text1")})
6271
private WebElement textAll;
6372

6473
@SelendroidFindAll({
65-
@SelendroidFindBy(id = "text1")})
74+
@SelendroidFindBy(id = "text1")})
6675
private List<WebElement> textsAll;
6776

6877
@SelendroidFindBy(className = "android.widget.TextView")
6978
private WebElement textClass;
7079

7180
@SelendroidFindBy(tagName = "TextView")
7281
private WebElement textTag;
73-
82+
7483
@SelendroidFindBy(linkText = "Accessibility")
7584
private WebElement textLink;
76-
85+
7786
@SelendroidFindBy(partialLinkText = "ccessibilit")
7887
private WebElement textPartialLink;
7988

80-
@BeforeClass
89+
@BeforeClass
8190
public static void beforeClass() throws Exception {
8291
AppiumServiceBuilder builder = new AppiumServiceBuilder().withArgument(GeneralServerFlag.AUTOMATION_NAME, AutomationName.SELENDROID);
8392
service = builder.build();
@@ -114,12 +123,27 @@ public static void afterClass() throws Exception {
114123
public void findByIdElementTest() {
115124
assertNotEquals(null, textId.getAttribute("text"));
116125
}
117-
118-
@Test
126+
127+
@Test
119128
public void findBySelendroidSelectorTest() {
120129
assertNotEquals(null, textSelendroidId.getAttribute("text"));
121130
}
122131

132+
@Test
133+
public void findByElementByNameTest() {
134+
assertEquals("Accessibility", textName.getText());
135+
}
136+
137+
@Test
138+
public void findByElementByNameAndroidTest() {
139+
assertEquals("Accessibility", textNameAndroid.getText());
140+
}
141+
142+
@Test
143+
public void findByElementByNameDefaultTest() {
144+
assertEquals("Accessibility", textNameDefault.getText());
145+
}
146+
123147
@Test
124148
public void findByElementByXpathTest() {
125149
assertEquals("Accessibility", textXpath.getText());
@@ -149,12 +173,12 @@ public void findByElementByCalssTest() {
149173
public void findByElementByTagTest() {
150174
assertNotEquals(null, textTag.getAttribute("text"));
151175
}
152-
176+
153177
@Test
154178
public void findBySelendroidAnnotationOnlyTest() {
155179
assertNotEquals(null, textSelendroidId.getAttribute("text"));
156180
}
157-
181+
158182
@Test
159183
public void findBySelendroidLinkTextTest() {
160184
assertEquals("Accessibility", textLink.getText());

src/test/java/io/appium/java_client/pagefactory_tests/iOSPageObjectTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ public class iOSPageObjectTest {
118118

119119
@iOSFindAll({
120120
@iOSFindBy(xpath = "ComputeSumButton_Test"),
121-
@iOSFindBy(xpath = "ComputeSumButton") //it is real locator
121+
@iOSFindBy(xpath = "//*[@name='ComputeSumButton']") //it is real locator
122122
})
123123
private WebElement findAllElement;
124124

125125
@iOSFindAll({
126126
@iOSFindBy(xpath = "ComputeSumButton_Test"),
127-
@iOSFindBy(xpath = "ComputeSumButton") //it is real locator
127+
@iOSFindBy(xpath = "//*[@name='ComputeSumButton']") //it is real locator
128128
})
129129
private List<WebElement> findAllElements;
130130

0 commit comments

Comments
 (0)