@@ -12,18 +12,169 @@ chai.should();
12
12
chai . use ( chaiAsPromised ) ;
13
13
14
14
describe ( 'UiAutomator2' , function ( ) {
15
+ let uiautomator2 ;
15
16
const adb = new ADB ( ) ;
17
+ const serverApk = {
18
+ 'appPath' : 'path/to/appium-uiautomator2-server.apk' ,
19
+ 'appId' : 'io.appium.uiautomator2.server'
20
+ } ;
21
+ const serverTestApk = {
22
+ 'appPath' : 'path/to/appium-uiautomator2-server-test.apk' ,
23
+ 'appId' : 'io.appium.uiautomator2.server.test'
24
+ } ;
25
+ const defaultUIA2ServerOptions = {
26
+ tmpDir : 'tmp' ,
27
+ systemPort : 4724 ,
28
+ host : 'localhost' ,
29
+ devicePort : 6790 ,
30
+ disableWindowAnimation : false
31
+ } ;
32
+
33
+ describe ( 'shouldUninstallServerPackages' , function ( ) {
34
+ beforeEach ( function ( ) {
35
+ uiautomator2 = new UiAutomator2Server ( log , {
36
+ adb, ...defaultUIA2ServerOptions
37
+ } ) ;
38
+ } ) ;
39
+ it ( 'with newer servers are installed' , function ( ) {
40
+ uiautomator2 . shouldUninstallServerPackages ( [
41
+ {
42
+ 'installState' : adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ,
43
+ ...serverApk
44
+ } ,
45
+ {
46
+ 'installState' : adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ,
47
+ ...serverTestApk
48
+ }
49
+ ] ) . should . be . true ;
50
+ } ) ,
51
+ it ( 'with newer server is installed but the other could be old one' , function ( ) {
52
+ // Then, enforce to uninstall all apks
53
+ uiautomator2 . shouldUninstallServerPackages ( [
54
+ {
55
+ 'installState' : adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ,
56
+ ...serverApk
57
+ } ,
58
+ {
59
+ 'installState' : adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ,
60
+ ...serverTestApk
61
+ }
62
+ ] ) . should . be . true ;
63
+ } ) ,
64
+ it ( 'with newer server is installed' , function ( ) {
65
+ uiautomator2 . shouldUninstallServerPackages ( [
66
+ {
67
+ 'installState' : adb . APP_INSTALL_STATE . SAME_VERSION_INSTALLED ,
68
+ ...serverApk
69
+ } ,
70
+ {
71
+ 'installState' : adb . APP_INSTALL_STATE . SAME_VERSION_INSTALLED ,
72
+ ...serverTestApk
73
+ }
74
+ ] ) . should . be . false ;
75
+ } ) ,
76
+ it ( 'with older servers are installed' , function ( ) {
77
+ // then, installing newer serves are sufficient.
78
+ uiautomator2 . shouldUninstallServerPackages ( [
79
+ {
80
+ 'installState' : adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ,
81
+ ...serverApk
82
+ } ,
83
+ {
84
+ 'installState' : adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ,
85
+ ...serverTestApk
86
+ }
87
+ ] ) . should . be . false ;
88
+ } ) ,
89
+ it ( 'with no server are installed' , function ( ) {
90
+ uiautomator2 . shouldUninstallServerPackages ( [
91
+ {
92
+ 'installState' : adb . APP_INSTALL_STATE . NOT_INSTALLED ,
93
+ ...serverApk
94
+ } ,
95
+ {
96
+ 'installState' : adb . APP_INSTALL_STATE . NOT_INSTALLED ,
97
+ ...serverTestApk
98
+ }
99
+ ] ) . should . be . false ;
100
+ } ) ;
101
+ } ) ;
102
+
103
+ describe ( 'shouldInstallServerPackages' , function ( ) {
104
+ beforeEach ( function ( ) {
105
+ uiautomator2 = new UiAutomator2Server ( log , {
106
+ adb, ...defaultUIA2ServerOptions
107
+ } ) ;
108
+ } ) ;
109
+ it ( 'with newer servers are installed' , function ( ) {
110
+ uiautomator2 . shouldInstallServerPackages ( [
111
+ {
112
+ 'installState' : adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ,
113
+ ...serverApk
114
+ } ,
115
+ {
116
+ 'installState' : adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ,
117
+ ...serverTestApk
118
+ }
119
+ // since installation may fail
120
+ ] ) . should . be . false ;
121
+ } ) ,
122
+ it ( 'with newer server is installed but the other could be old one' , function ( ) {
123
+ // Then, enforce to uninstall all apks
124
+ uiautomator2 . shouldInstallServerPackages ( [
125
+ {
126
+ 'installState' : adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ,
127
+ ...serverApk
128
+ } ,
129
+ {
130
+ 'installState' : adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ,
131
+ ...serverTestApk
132
+ }
133
+ ] ) . should . be . true ;
134
+ } ) ,
135
+ it ( 'with newer server is installed' , function ( ) {
136
+ uiautomator2 . shouldInstallServerPackages ( [
137
+ {
138
+ 'installState' : adb . APP_INSTALL_STATE . SAME_VERSION_INSTALLED ,
139
+ ...serverApk
140
+ } ,
141
+ {
142
+ 'installState' : adb . APP_INSTALL_STATE . SAME_VERSION_INSTALLED ,
143
+ ...serverTestApk
144
+ }
145
+ ] ) . should . be . false ;
146
+ } ) ,
147
+ it ( 'with older servers are installed' , function ( ) {
148
+ // then, installing newer serves are sufficient.
149
+ uiautomator2 . shouldInstallServerPackages ( [
150
+ {
151
+ 'installState' : adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ,
152
+ ...serverApk
153
+ } ,
154
+ {
155
+ 'installState' : adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ,
156
+ ...serverTestApk
157
+ }
158
+ ] ) . should . be . true ;
159
+ } ) ,
160
+ it ( 'with no server are installed' , function ( ) {
161
+ uiautomator2 . shouldInstallServerPackages ( [
162
+ {
163
+ 'installState' : adb . APP_INSTALL_STATE . NOT_INSTALLED ,
164
+ ...serverApk
165
+ } ,
166
+ {
167
+ 'installState' : adb . APP_INSTALL_STATE . NOT_INSTALLED ,
168
+ ...serverTestApk
169
+ }
170
+ ] ) . should . be . true ;
171
+ } ) ;
172
+ } ) ;
173
+
16
174
describe ( 'installServerApk' , withMocks ( { adb, helpers} , ( mocks ) => {
17
- let uiautomator2 ;
18
175
beforeEach ( function ( ) {
19
176
uiautomator2 = new UiAutomator2Server ( log , {
20
- adb,
21
- tmpDir : 'tmp' ,
22
- systemPort : 4724 ,
23
- host : 'localhost' ,
24
- devicePort : 6790 ,
25
- disableWindowAnimation : false ,
26
- disableSuppressAccessibilityService : false
177
+ adb, ...defaultUIA2ServerOptions
27
178
} ) ;
28
179
} ) ;
29
180
afterEach ( function ( ) {
@@ -35,7 +186,7 @@ describe('UiAutomator2', function () {
35
186
36
187
// SERVER_PACKAGE_ID
37
188
mocks . adb . expects ( 'getApplicationInstallState' ) . once ( )
38
- . returns ( adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ) ;
189
+ . returns ( adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ) ;
39
190
40
191
// SERVER_PACKAGE_ID and SERVER_TEST_PACKAGE_ID
41
192
mocks . adb . expects ( 'checkApkCert' ) . twice ( ) . returns ( true ) ;
@@ -58,7 +209,7 @@ describe('UiAutomator2', function () {
58
209
59
210
// SERVER_PACKAGE_ID
60
211
mocks . adb . expects ( 'getApplicationInstallState' ) . once ( )
61
- . returns ( adb . APP_INSTALL_STATE . NEWER_VERSION_INSTALLED ) ;
212
+ . returns ( adb . APP_INSTALL_STATE . OLDER_VERSION_INSTALLED ) ;
62
213
63
214
// SERVER_PACKAGE_ID and SERVER_TEST_PACKAGE_ID
64
215
mocks . adb . expects ( 'checkApkCert' ) . twice ( ) . returns ( true ) ;
@@ -147,7 +298,6 @@ describe('UiAutomator2', function () {
147
298
await uiautomator2 . installServerApk ( ) ;
148
299
} ) ;
149
300
150
-
151
301
it ( 'a server is installed but server.test is not' , async function ( ) {
152
302
mocks . helpers . expects ( 'isWriteable' ) . never ( ) ;
153
303
0 commit comments