-
-
Notifications
You must be signed in to change notification settings - Fork 748
/
AndroidDriverTest.java
188 lines (150 loc) · 6.49 KB
/
AndroidDriverTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.appium.java_client.android;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.html5.Location;
import java.io.File;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class AndroidDriverTest extends BaseAndroidTest {
@Test public void getDeviceTimeTest() {
String time = driver.getDeviceTime();
assertTrue(time.length() == 28);
}
@Test public void isAppInstalledTest() {
assertTrue(driver.isAppInstalled("com.example.android.apis"));
}
@Test public void isAppNotInstalledTest() {
assertFalse(driver.isAppInstalled("foo"));
}
@Test public void closeAppTest() throws InterruptedException {
driver.closeApp();
driver.launchApp();
assertEquals(".ApiDemos", driver.currentActivity());
}
@Test public void pushFileTest() {
byte[] data = Base64.encodeBase64(
"The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra"
.getBytes());
driver.pushFile("/data/local/tmp/remote.txt", data);
byte[] returnData = driver.pullFile("/data/local/tmp/remote.txt");
String returnDataDecoded = new String(Base64.decodeBase64(returnData));
assertEquals(
"The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra",
returnDataDecoded);
}
@Test public void pushTempFileTest() throws Exception {
File temp = File.createTempFile("Temp_", "_test");
try {
FileUtils.writeStringToFile(temp, "The eventual code is no "
+ "more than the deposit of your understanding. ~E. W. Dijkstra", "UTF-8", true);
driver.pushFile("/data/local/tmp/remote2.txt", temp);
byte[] returnData = driver.pullFile("/data/local/tmp/remote2.txt");
String returnDataDecoded = new String(Base64.decodeBase64(returnData));
assertEquals(
"The eventual code is no more than the deposit of "
+ "your understanding. ~E. W. Dijkstra",
returnDataDecoded);
} finally {
FileUtils.forceDelete(temp);
}
}
@Test public void toggleLocationServicesTest() {
driver.toggleLocationServices();
}
@Test public void geolocationTest() {
Location location = new Location(45, 45, 100);
driver.setLocation(location);
}
@Test public void orientationTest() {
assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation());
driver.rotate(ScreenOrientation.LANDSCAPE);
assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation());
driver.rotate(ScreenOrientation.PORTRAIT);
}
@Test public void lockTest() {
driver.lockDevice();
assertEquals(true, driver.isLocked());
driver.unlockDevice();
assertEquals(false, driver.isLocked());
}
@Test public void runAppInBackgroundTest() {
long time = System.currentTimeMillis();
driver.runAppInBackground(Duration.ofSeconds(4));
long timeAfter = System.currentTimeMillis();
assert (timeAfter - time > 3000);
}
@Test public void pullFileTest() {
byte[] data =
driver.pullFile("data/system/registered_services/android.content.SyncAdapter.xml");
assert (data.length > 0);
}
@Test public void resetTest() {
driver.resetApp();
}
@Test public void endTestCoverage() {
driver.endTestCoverage("android.intent.action.MAIN", "");
}
@Test public void getDeviceUDIDTest() {
String deviceSerial = driver.getSessionDetail("deviceUDID").toString();
assertNotNull(deviceSerial);
}
@Test public void getSessionMapData() {
Map<?,?> map = (Map<?, ?>) driver.getSessionDetail("desired");
assertNotEquals(map.size(), 0);
}
@Test public void deviceDetailsAndKeyboardTest() {
assertFalse(driver.isKeyboardShown());
assertNotNull(driver.getDisplayDensity());
assertNotEquals(0, driver.getSystemBars().size());
}
@Test public void getSupportedPerformanceDataTypesTest() {
driver.startActivity(new Activity("io.appium.android.apis", ".ApiDemos"));
List<String> dataTypes = new ArrayList<String>();
dataTypes.add("cpuinfo");
dataTypes.add("memoryinfo");
dataTypes.add("batteryinfo");
dataTypes.add("networkinfo");
List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();
assertEquals(4, supportedPerformanceDataTypes.size());
for ( int i = 0 ; i < supportedPerformanceDataTypes.size() ; ++i) {
assertEquals(dataTypes.get(i), supportedPerformanceDataTypes.get(i));
}
}
@Test public void getPerformanceDataTest() throws Exception {
driver.startActivity(new Activity("io.appium.android.apis", ".ApiDemos"));
List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();
for (String dataType : supportedPerformanceDataTypes) {
List<List<Object>> valueTable = driver.getPerformanceData("com.example.android.apis", dataType, 60000);
for (int j = 1; j < valueTable.size(); ++j) {
assertEquals(valueTable.subList(0, 0).size(), valueTable.subList(j, j).size());
}
}
}
@Test public void getCurrentPackageTest() {
assertEquals("io.appium.android.apis",driver.getCurrentPackage());
}
}