Skip to content

Commit eaaed61

Browse files
committed
[-] Fix bugs in @SelendroidFindBys and @SelendroidFindAll annotations
[*] Remove unnecessary validators [+] Add selendroid tests
1 parent d71fcf4 commit eaaed61

File tree

3 files changed

+155
-8
lines changed

3 files changed

+155
-8
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,11 @@ private void assertValidAnnotations() {
177177
iOSFindAll iOSFindAll = mobileField.getAnnotation(iOSFindAll.class);
178178

179179
checkDisallowedAnnotationPairs(androidBy, androidBys);
180-
checkDisallowedAnnotationPairs(androidBy, selendroidBys);
181180
checkDisallowedAnnotationPairs(androidBy, androidFindAll);
182-
checkDisallowedAnnotationPairs(androidBy, selendroidFindAll);
183181
checkDisallowedAnnotationPairs(androidBys, androidFindAll);
184-
checkDisallowedAnnotationPairs(androidBys, selendroidFindAll);
185182

186-
checkDisallowedAnnotationPairs(selendroidBy, androidBys);
187183
checkDisallowedAnnotationPairs(selendroidBy, selendroidBys);
188-
checkDisallowedAnnotationPairs(selendroidBy, androidFindAll);
189184
checkDisallowedAnnotationPairs(selendroidBy, selendroidFindAll);
190-
checkDisallowedAnnotationPairs(selendroidBys, androidFindAll);
191185
checkDisallowedAnnotationPairs(selendroidBys, selendroidFindAll);
192186

193187
checkDisallowedAnnotationPairs(iOSBy, iOSBys);
@@ -279,14 +273,14 @@ public By buildBy() {
279273
.getAnnotation(SelendroidFindBys.class);
280274
if (selendroidBys != null && ANDROID.toUpperCase().equals(platform) &&
281275
"Selendroid".toUpperCase().equals(automation)) {
282-
return getMobileBy(selendroidBys, getFilledValue(selendroidBys));
276+
return getComplexMobileBy(selendroidBys.value(), ByChained.class);
283277
}
284278

285279
SelendroidFindAll selendroidAll = mobileField
286280
.getAnnotation(SelendroidFindAll.class);
287281
if (selendroidAll != null && ANDROID.toUpperCase().equals(platform) &&
288282
"Selendroid".toUpperCase().equals(automation)) {
289-
return getMobileBy(selendroidAll, getFilledValue(selendroidAll));
283+
return getComplexMobileBy(selendroidAll.value(), ByAll.class);
290284
}
291285

292286

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.appium.java_client.pagefactory.AndroidFindBy;
88
import io.appium.java_client.pagefactory.AndroidFindBys;
99
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
10+
import io.appium.java_client.pagefactory.SelendroidFindBy;
1011
import io.appium.java_client.pagefactory.iOSFindBy;
1112
import io.appium.java_client.pagefactory.iOSFindBys;
1213
import io.appium.java_client.remote.MobileCapabilityType;
@@ -148,6 +149,10 @@ public class AndroidPageObjectTest {
148149
@AndroidFindBy(id = "android:id/FakeId")
149150
})
150151
private WebElement findAllElementView;
152+
153+
@AndroidFindBy(id = "android:id/text1")
154+
@SelendroidFindBy(id = "Invalid Identifier")
155+
private WebElement textAndroidId;
151156

152157
@Before
153158
public void setUp() throws Exception {
@@ -311,4 +316,9 @@ public void findAllElementTest(){
311316
public void findAllElementsTest(){
312317
Assert.assertNotEquals(0, findAllElementViews.size());
313318
}
319+
320+
@Test
321+
public void findByAndroidAnnotationOnlyTest(){
322+
Assert.assertNotEquals(null, textAndroidId.getAttribute("text"));
323+
}
314324
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package io.appium.java_client.pagefactory_tests;
2+
3+
import io.appium.java_client.android.AndroidDriver;
4+
import io.appium.java_client.pagefactory.AndroidFindBy;
5+
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
6+
import io.appium.java_client.pagefactory.SelendroidFindAll;
7+
import io.appium.java_client.pagefactory.SelendroidFindBy;
8+
import io.appium.java_client.pagefactory.SelendroidFindBys;
9+
import io.appium.java_client.remote.MobileCapabilityType;
10+
import org.openqa.selenium.WebElement;
11+
import java.io.File;
12+
import java.net.URL;
13+
import java.util.List;
14+
import java.util.concurrent.TimeUnit;
15+
import org.junit.After;
16+
import org.junit.Assert;
17+
import org.junit.Before;
18+
import org.junit.Test;
19+
import org.openqa.selenium.WebDriver;
20+
import org.openqa.selenium.remote.DesiredCapabilities;
21+
import org.openqa.selenium.support.FindBy;
22+
import org.openqa.selenium.support.PageFactory;
23+
24+
public class SelendroidModeTest {
25+
26+
private WebDriver driver;
27+
28+
@SelendroidFindBy(id = "text1")
29+
private WebElement textId;
30+
31+
@AndroidFindBy(id = "Invalid Identifier")
32+
@SelendroidFindBy(id = "text1")
33+
private WebElement textSelendroidId;
34+
35+
@SelendroidFindBy(name = "Accessibility")
36+
private WebElement textName;
37+
38+
@AndroidFindBy(name = "Accessibility")
39+
private WebElement textNameAndroid;
40+
41+
@FindBy(name = "Accessibility")
42+
private WebElement textNameDefault;
43+
44+
@SelendroidFindBy(xpath = "//TextView[@value='Accessibility']")
45+
private WebElement textXpath;
46+
47+
@SelendroidFindBys({
48+
@SelendroidFindBy(id = "text1")})
49+
private WebElement textIds;
50+
51+
@SelendroidFindAll({
52+
@SelendroidFindBy(id = "text1")})
53+
private WebElement textAll;
54+
55+
@SelendroidFindAll({
56+
@SelendroidFindBy(id = "text1")})
57+
private List<WebElement> textsAll;
58+
59+
@SelendroidFindBy(className = "android.widget.TextView")
60+
private WebElement textClass;
61+
62+
@SelendroidFindBy(tagName = "TextView")
63+
private WebElement textTag;
64+
65+
@Before
66+
public void setUp() throws Exception {
67+
File appDir = new File("src/test/java/io/appium/java_client");
68+
File app = new File(appDir, "ApiDemos-debug.apk");
69+
DesiredCapabilities capabilities = new DesiredCapabilities();
70+
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
71+
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
72+
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Selendroid");
73+
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
74+
75+
//This time out is set because test can be run on slow Android SDK emulator
76+
PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this);
77+
}
78+
79+
@After
80+
public void tearDown() throws Exception {
81+
driver.quit();
82+
}
83+
84+
@Test
85+
public void findByIdElementTest() {
86+
Assert.assertNotEquals(null, textId.getAttribute("text"));
87+
}
88+
89+
@Test
90+
public void findBySelendroidSelectorTest() {
91+
Assert.assertNotEquals(null, textSelendroidId.getAttribute("text"));
92+
}
93+
94+
@Test
95+
public void findByElementByNameTest() {
96+
Assert.assertEquals("Accessibility", textName.getText());
97+
}
98+
99+
@Test
100+
public void findByElementByNameAndroidTest() {
101+
Assert.assertEquals("Accessibility", textNameAndroid.getText());
102+
}
103+
104+
@Test
105+
public void findByElementByNameDefaultTest() {
106+
Assert.assertEquals("Accessibility", textNameDefault.getText());
107+
}
108+
109+
@Test
110+
public void findByElementByXpathTest() {
111+
Assert.assertEquals("Accessibility", textXpath.getText());
112+
}
113+
114+
@Test
115+
public void findByElementByIdsTest() {
116+
Assert.assertNotNull(textIds.getText());
117+
}
118+
119+
@Test
120+
public void findByElementByTestAllTest() {
121+
Assert.assertNotNull(textAll.getText());
122+
}
123+
124+
@Test
125+
public void findByElementByTextsAllTest() {
126+
Assert.assertTrue(textsAll.size() > 1);
127+
}
128+
129+
@Test
130+
public void findByElementByCalssTest() {
131+
Assert.assertNotEquals(null, textClass.getAttribute("text"));
132+
}
133+
134+
@Test
135+
public void findByElementByTagTest() {
136+
Assert.assertNotEquals(null, textTag.getAttribute("text"));
137+
}
138+
@Test
139+
public void findBySelendroidAnnotationOnlyTest() {
140+
Assert.assertNotEquals(null, textSelendroidId.getAttribute("text"));
141+
}
142+
143+
}

0 commit comments

Comments
 (0)