Skip to content

Commit 4656309

Browse files
shridharkalagiSrinivasanTarget
authored andcommitted
Fix Android tests and add them to CI (#1002)
* Fix Android tests and add them to CI * Get the appium version from ENV variable in travis
1 parent a873737 commit 4656309

11 files changed

+121
-116
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ settings.xml
1010
build/
1111
.gradle
1212
.gradle/*
13-
13+
classes/
1414
# Eclipse
1515
/bin
1616
/target

.travis.yml

+36-27
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,42 @@ matrix:
1616
- npm install -g $appiumVersion
1717
script:
1818
- ./gradlew clean build xcuiTest -x test -x signArchives
19-
# - language: android
20-
# install: true
21-
# os: linux
22-
# jdk: oraclejdk8
23-
# android:
24-
# components:
25-
# - build-tools-26.0.2
26-
# - platform-tools
27-
# - tools
28-
# - android-22
29-
# - extra-android-m2repository
30-
# - extra-google-google_play_services
31-
# - extra-google-m2repository
32-
# - sys-img-armeabi-v7a-android-22
33-
# before_install:
34-
# # node stuff
35-
# - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
36-
# - nvm install 6
37-
# - node --version
38-
# - npm --version
39-
# - npm install -g [email protected]
40-
# - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
41-
# - emulator -avd test -no-audio -no-window &
42-
# - android-wait-for-emulator
43-
# - adb devices
44-
# script:
45-
# - ./gradlew clean test --tests "io.appium.java_client.android.*" --exclude-task signArchives
19+
20+
- language: android
21+
install: true
22+
install:
23+
- echo y | android update sdk -u -a -t tools
24+
- echo y | android update sdk -u -a -t platform-tools
25+
- echo y | android update sdk -u -a -t build-tools-25.0.2
26+
- echo y | android update sdk -u -a -t android-25
27+
- echo y | android update sdk -u -a -t extra-google-m2repository
28+
- echo y | android update sdk -u -a -t extra-android-m2repository
29+
os: linux
30+
jdk: oraclejdk8
31+
android:
32+
components:
33+
- extra-android-support
34+
- sys-img-armeabi-v7a-android-24
35+
before_install:
36+
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
37+
- nvm install 8
38+
- node --version
39+
- npm --version
40+
- npm install -g $appiumVersion
41+
- echo y | android update sdk -a --no-ui --filter android-24
42+
- echo y | android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-24
43+
- android list targets | grep -E '^id:' | awk -F '"' '{$1=""; print $2}' # list all targets
44+
- echo no | android create avd --force -n test -t android-24 --abi armeabi-v7a
45+
- emulator -avd test -no-skin -no-window &
46+
- android-wait-for-emulator
47+
- adb shell input keyevent 82 &
48+
- adb wait-for-device get-serialno
49+
- sleep 100
50+
- chmod +x gradlew
51+
- ./gradlew --version
52+
- echo y |adb devices
53+
script:
54+
- ./gradlew clean build uiAutomationTest -x test -x signArchives
4655

4756
before_cache:
4857
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,9 @@ task uiAutomationTest( type: Test ) {
229229
useJUnit()
230230
testLogging.showStandardStreams = true
231231
testLogging.exceptionFormat = 'full'
232-
include '**/UIAutomationTest.class'
232+
filter {
233+
includeTestsMatching '*.SettingTest'
234+
includeTestsMatching 'io.appium.java_client.android.ClipboardTest'
235+
includeTestsMatching '*.AndroidAppStringsTest'
236+
}
233237
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public enum Setting {
2323

2424
IGNORE_UNIMPORTANT_VIEWS("ignoreUnimportantViews"),
2525
WAIT_FOR_IDLE_TIMEOUT("waitForIdleTimeout"),
26-
WAIT_FOR_SELECTOR_TIMEOUT("setWaitForSelectorTimeout"),
27-
WAIT_SCROLL_ACKNOWLEDGMENT_TIMEOUT("setScrollAcknowledgmentTimeout"),
28-
WAIT_ACTION_ACKNOWLEDGMENT_TIMEOUT("setActionAcknowledgmentTimeout"),
29-
KEY_INJECTION_DELAY("setKeyInjectionDelay"),
26+
WAIT_FOR_SELECTOR_TIMEOUT("waitForSelectorTimeout"),
27+
WAIT_SCROLL_ACKNOWLEDGMENT_TIMEOUT("scrollAcknowledgmentTimeout"),
28+
WAIT_ACTION_ACKNOWLEDGMENT_TIMEOUT("actionAcknowledgmentTimeout"),
29+
KEY_INJECTION_DELAY("keyInjectionDelay"),
3030
NATIVE_WEB_TAP("nativeWebTap"),
3131
IMAGE_MATCH_THRESHOLD("imageMatchThreshold"),
3232
FIX_IMAGE_FIND_SCREENSHOT_DIMENSIONS("fixImageFindScreenshotDims"),

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public class AndroidActivityTest extends BaseAndroidTest {
4949
}
5050

5151
@Test public void startActivityInNewAppTestCase() {
52-
Activity activity = new Activity("com.android.contacts", ".ContactsListActivity");
52+
Activity activity = new Activity("com.android.settings", ".Settings");
5353
driver.startActivity(activity);
54-
assertEquals(driver.currentActivity(), ".ContactsListActivity");
54+
assertEquals(driver.currentActivity(), ".Settings");
5555
driver.pressKey(new KeyEvent(AndroidKey.BACK));
56-
assertEquals(driver.currentActivity(), ".ContactsListActivity");
56+
assertEquals(driver.currentActivity(), ".ApiDemos");
5757
}
5858

5959
@Test public void startActivityInNewAppTestCaseWithoutClosingApp() {
@@ -62,12 +62,12 @@ public class AndroidActivityTest extends BaseAndroidTest {
6262
driver.startActivity(activity);
6363
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");
6464

65-
Activity newActivity = new Activity("com.android.contacts", ".ContactsListActivity")
66-
.setAppWaitPackage("com.android.contacts")
67-
.setAppWaitActivity(".ContactsListActivity")
65+
Activity newActivity = new Activity("com.android.settings", ".Settings")
66+
.setAppWaitPackage("com.android.settings")
67+
.setAppWaitActivity(".Settings")
6868
.setStopApp(false);
6969
driver.startActivity(newActivity);
70-
assertEquals(driver.currentActivity(), ".ContactsListActivity");
70+
assertEquals(driver.currentActivity(), ".Settings");
7171
driver.pressKey(new KeyEvent(AndroidKey.BACK));
7272
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");
7373
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class AndroidContextTest extends BaseAndroidTest {
4444
driver.context("WEBVIEW_io.appium.android.apis");
4545
assertEquals(driver.getContext(), "WEBVIEW_io.appium.android.apis");
4646
driver.context("NATIVE_APP");
47+
assertEquals(driver.getContext(), "NATIVE_APP");
4748
}
4849

4950
@Test(expected = NoSuchContextException.class) public void testContextError() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
210210

211211
@Test public void pullFileTest() {
212212
byte[] data =
213-
driver.pullFile("data/system/registered_services/android.content.SyncAdapter.xml");
213+
driver.pullFile("/data/system/users/userlist.xml");
214214
assert (data.length > 0);
215215
}
216216

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,22 @@ public class AndroidFunctionTest extends BaseAndroidTest {
6565
return null;
6666
};
6767

68-
@BeforeClass public static void startWebViewActivity() {
68+
@BeforeClass
69+
public static void startWebViewActivity() {
6970
if (driver != null) {
7071
Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
7172
driver.startActivity(activity);
7273
}
7374
}
7475

75-
@Before public void setUp() {
76+
@Before
77+
public void setUp() {
78+
7679
driver.context("NATIVE_APP");
7780
}
7881

79-
@Test public void complexWaitingTestWithPreCondition() {
82+
@Test
83+
public void complexWaitingTestWithPreCondition() {
8084
AppiumFunction<Pattern, List<WebElement>> compositeFunction =
8185
searchingFunction.compose(contextFunction);
8286

@@ -123,13 +127,15 @@ public class AndroidFunctionTest extends BaseAndroidTest {
123127
assertThat("There should be 3 calls", calls.size(), is(3));
124128
}
125129

126-
@Test(expected = TimeoutException.class) public void nullPointerExceptionSafetyTestWithPrecondition() {
130+
@Test(expected = TimeoutException.class)
131+
public void nullPointerExceptionSafetyTestWithPrecondition() {
127132
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
128133
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
129134
assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0);
130135
}
131136

132-
@Test(expected = TimeoutException.class) public void nullPointerExceptionSafetyTestWithPostConditions() {
137+
@Test(expected = TimeoutException.class)
138+
public void nullPointerExceptionSafetyTestWithPostConditions() {
133139
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
134140
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
135141
assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0);

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ private AndroidElement findElementByText(String text) {
7272
new NoSuchElementException(String.format("There is no element with the text '%s'", text)));
7373
}
7474

75-
private void clickNext() {
75+
private void clickNext() {
7676
driver.findElementById("com.android.settings:id/next_button").click();
7777
}
7878

79+
private void clickFingerPrintNext() {
80+
driver.findElementById("com.android.settings:id/fingerprint_next_button").click();
81+
}
82+
7983
private void clickOKInPopup() {
8084
driver.findElementById("android:id/button1").click();
8185
}
@@ -88,13 +92,14 @@ private void enterPasswordAndContinue() {
8892
private void clickOnSecurity() {
8993
driver.findElement(AndroidUIAutomator("new UiScrollable(new UiSelector()"
9094
+ ".scrollable(true)).scrollIntoView("
91-
+ "new UiSelector().text(\"Security\"));")).click();
95+
+ "new UiSelector().text(\"Security & location\"));")).click();
9296
}
9397

9498
/**
9599
* enable system security which is required for finger print activation.
96100
*/
97-
@Before public void before() {
101+
@Before
102+
public void before() {
98103
initDriver();
99104
clickOnSecurity();
100105
findElementByText("Screen lock").click();
@@ -107,13 +112,14 @@ private void clickOnSecurity() {
107112
/**
108113
* add a new finger print to security.
109114
*/
110-
@Test public void fingerPrintTest() {
115+
@Test
116+
public void fingerPrintTest() {
111117
findElementByText("Fingerprint").click();
112-
clickNext();
118+
clickFingerPrintNext();
113119
enterPasswordAndContinue();
114-
clickNext();
115-
116-
driver.fingerPrint(2);
120+
driver.fingerPrint(1234);
121+
driver.fingerPrint(1234);
122+
driver.fingerPrint(1234);
117123
try {
118124
clickNext();
119125
} catch (Exception e) {
@@ -124,7 +130,8 @@ private void clickOnSecurity() {
124130
/**
125131
* disabling pin lock mode.
126132
*/
127-
@After public void after() {
133+
@After
134+
public void after() {
128135
driver.quit();
129136

130137
initDriver();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void openNotification() {
1717
WebDriverWait wait = new WebDriverWait(driver, 20);
1818
assertNotEquals(0, wait.until(input -> {
1919
List<AndroidElement> result = input
20-
.findElements(id("com.android.systemui:id/carrier_label"));
20+
.findElements(id("com.android.systemui:id/settings_button"));
2121

2222
return result.isEmpty() ? null : result;
2323
}).size());

0 commit comments

Comments
 (0)