appium-espresso-driver 2.13.10 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -0
- package/espresso-server/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk +0 -0
- package/espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/ElementScreenshot.kt +8 -7
- package/espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/ScreenshotHandler.kt +2 -7
- package/espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/handlers/exceptions/ScreenCaptureException.kt +5 -1
- package/espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/ScreenshotHelpers.kt +59 -0
- package/npm-shrinkwrap.json +90 -28
- package/package.json +2 -2
- package/espresso-server/app/src/androidTest/java/io/appium/espressoserver/lib/helpers/ScreenshotsHelper.kt +0 -59
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.14.0](https://github.com/appium/appium-espresso-driver/compare/v2.13.11...v2.14.0) (2023-01-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add compose element screenshot ([#847](https://github.com/appium/appium-espresso-driver/issues/847)) ([95bded7](https://github.com/appium/appium-espresso-driver/commit/95bded7e1816eb42ded501efcbca24b07b283f35))
|
|
7
|
+
|
|
8
|
+
## [2.13.11](https://github.com/appium/appium-espresso-driver/compare/v2.13.10...v2.13.11) (2023-01-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Miscellaneous Chores
|
|
12
|
+
|
|
13
|
+
* **deps-dev:** bump rimraf from 3.0.2 to 4.0.4 ([#848](https://github.com/appium/appium-espresso-driver/issues/848)) ([cf06466](https://github.com/appium/appium-espresso-driver/commit/cf064663eea2b3ffd7a02e2ba5dec3bffb4f9e53))
|
|
14
|
+
|
|
1
15
|
## [2.13.10](https://github.com/appium/appium-espresso-driver/compare/v2.13.9...v2.13.10) (2023-01-12)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -202,6 +202,7 @@ In order to change between subdrivers use the [driver](#settings-api) setting. S
|
|
|
202
202
|
- getPageSource: The returned page source is retrieved from Compose and all elements there contain [Compose-specific](#compose-element-attributes) attributes.
|
|
203
203
|
- click, isDisplayed, isEnabled, clear, getText, sendKeys, getElementRect, getValue, isSelected: These commands should properly support compose elements.
|
|
204
204
|
- getAttribute: Accepts and returns Compose-specific element attributes. See [Compose Element Attributes](#compose-element-attributes) for the full list of supported Compose element attributes.
|
|
205
|
+
- getElementScreenshot: Fetches a screenshot of the given Compose element. Available since driver version *2.14.0*
|
|
205
206
|
|
|
206
207
|
Calling other driver element-specific APIs not listed above would most likely throw an exception as Compose and Espresso elements are being stored in completely separated internal caches and must not be mixed.
|
|
207
208
|
|
|
Binary file
|
|
@@ -16,16 +16,17 @@
|
|
|
16
16
|
|
|
17
17
|
package io.appium.espressoserver.lib.handlers
|
|
18
18
|
|
|
19
|
-
import io.appium.espressoserver.lib.
|
|
20
|
-
import io.appium.espressoserver.lib.helpers.
|
|
19
|
+
import io.appium.espressoserver.lib.helpers.getNodeInteractionById
|
|
20
|
+
import io.appium.espressoserver.lib.helpers.takeComposeNodeScreenshot
|
|
21
|
+
import io.appium.espressoserver.lib.helpers.takeEspressoViewScreenshot
|
|
21
22
|
import io.appium.espressoserver.lib.model.AppiumParams
|
|
22
23
|
import io.appium.espressoserver.lib.model.EspressoElement
|
|
23
24
|
|
|
24
25
|
class ElementScreenshot : RequestHandler<AppiumParams, String> {
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
override fun handleEspresso(params: AppiumParams): String =
|
|
28
|
+
takeEspressoViewScreenshot(EspressoElement.getCachedViewStateById(params.elementId).view)
|
|
29
|
+
|
|
30
|
+
override fun handleCompose(params: AppiumParams): String =
|
|
31
|
+
takeComposeNodeScreenshot(getNodeInteractionById(params.elementId!!))
|
|
31
32
|
}
|
|
@@ -16,14 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
package io.appium.espressoserver.lib.handlers
|
|
18
18
|
|
|
19
|
-
import io.appium.espressoserver.lib.
|
|
20
|
-
import io.appium.espressoserver.lib.helpers.ScreenshotsHelper
|
|
19
|
+
import io.appium.espressoserver.lib.helpers.takeScreenshot
|
|
21
20
|
import io.appium.espressoserver.lib.model.AppiumParams
|
|
22
21
|
|
|
23
22
|
class ScreenshotHandler : RequestHandler<AppiumParams, String> {
|
|
24
|
-
|
|
25
|
-
@Throws(AppiumException::class)
|
|
26
|
-
override fun handleInternal(params: AppiumParams): String {
|
|
27
|
-
return ScreenshotsHelper().screenshot
|
|
28
|
-
}
|
|
23
|
+
override fun handleInternal(params: AppiumParams): String = takeScreenshot()
|
|
29
24
|
}
|
|
@@ -19,7 +19,11 @@ package io.appium.espressoserver.lib.handlers.exceptions
|
|
|
19
19
|
import fi.iki.elonen.NanoHTTPD
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
class ScreenCaptureException
|
|
22
|
+
class ScreenCaptureException : AppiumException {
|
|
23
|
+
constructor(reason: String) : super(reason)
|
|
24
|
+
|
|
25
|
+
constructor(reason: String, e: Throwable) : super(reason, e)
|
|
26
|
+
|
|
23
27
|
override fun error(): String {
|
|
24
28
|
return "unable to capture screen"
|
|
25
29
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
* you may not use this file except in compliance with the License.
|
|
4
|
+
* See the NOTICE file distributed with this work for additional
|
|
5
|
+
* information regarding copyright ownership.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
package io.appium.espressoserver.lib.helpers
|
|
18
|
+
|
|
19
|
+
import android.graphics.Bitmap
|
|
20
|
+
import android.util.Base64
|
|
21
|
+
import android.view.View
|
|
22
|
+
import androidx.compose.ui.graphics.asAndroidBitmap
|
|
23
|
+
import androidx.compose.ui.test.SemanticsNodeInteraction
|
|
24
|
+
import androidx.compose.ui.test.captureToImage
|
|
25
|
+
|
|
26
|
+
import java.io.ByteArrayOutputStream
|
|
27
|
+
import androidx.test.runner.screenshot.Screenshot
|
|
28
|
+
import io.appium.espressoserver.lib.handlers.exceptions.ScreenCaptureException
|
|
29
|
+
|
|
30
|
+
private fun encodeBitmap(bitmap: Bitmap?, targetNameSupplier: () -> String): String {
|
|
31
|
+
if (bitmap == null || bitmap.height == 0 || bitmap.width == 0) {
|
|
32
|
+
throw ScreenCaptureException("Cannot capture a shot of the ${targetNameSupplier()}. " +
|
|
33
|
+
"Make sure none of the currently visible " +
|
|
34
|
+
"views have FLAG_SECURE set and that it is possible to take a screenshot manually")
|
|
35
|
+
}
|
|
36
|
+
val outputStream = ByteArrayOutputStream()
|
|
37
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
|
|
38
|
+
return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fun takeScreenshot(): String {
|
|
42
|
+
return encodeBitmap(Screenshot.capture().bitmap) { "current screen" }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fun takeEspressoViewScreenshot(view: View): String =
|
|
46
|
+
try {
|
|
47
|
+
encodeBitmap(Screenshot.capture(view).bitmap) { view.javaClass.name }
|
|
48
|
+
} catch (e: RuntimeException) {
|
|
49
|
+
throw ScreenCaptureException("Cannot take a screenshot of a view", e)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun takeComposeNodeScreenshot(nodeInteraction: SemanticsNodeInteraction): String =
|
|
53
|
+
try {
|
|
54
|
+
encodeBitmap(
|
|
55
|
+
nodeInteraction.captureToImage().asAndroidBitmap()
|
|
56
|
+
) { nodeInteraction.fetchSemanticsNode().toString() }
|
|
57
|
+
} catch (e: RuntimeException) {
|
|
58
|
+
throw ScreenCaptureException("Cannot take a screenshot of a node", e)
|
|
59
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-espresso-driver",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "appium-espresso-driver",
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.14.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/runtime": "^7.4.3",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lint-staged": "^13.0.3",
|
|
47
47
|
"mocha": "^10.0.0",
|
|
48
48
|
"pre-commit": "^1.2.2",
|
|
49
|
-
"rimraf": "^
|
|
49
|
+
"rimraf": "^4.0.4",
|
|
50
50
|
"semantic-release": "^19.0.2",
|
|
51
51
|
"sinon": "^15.0.0",
|
|
52
52
|
"webdriverio": "^8.0.2",
|
|
@@ -250,6 +250,55 @@
|
|
|
250
250
|
"node": ">=10"
|
|
251
251
|
}
|
|
252
252
|
},
|
|
253
|
+
"node_modules/@appium/support/node_modules/rimraf": {
|
|
254
|
+
"version": "3.0.2",
|
|
255
|
+
"license": "ISC",
|
|
256
|
+
"dependencies": {
|
|
257
|
+
"glob": "^7.1.3"
|
|
258
|
+
},
|
|
259
|
+
"bin": {
|
|
260
|
+
"rimraf": "bin.js"
|
|
261
|
+
},
|
|
262
|
+
"funding": {
|
|
263
|
+
"url": "https://github.com/sponsors/isaacs"
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
"node_modules/@appium/support/node_modules/rimraf/node_modules/brace-expansion": {
|
|
267
|
+
"version": "1.1.11",
|
|
268
|
+
"license": "MIT",
|
|
269
|
+
"dependencies": {
|
|
270
|
+
"balanced-match": "^1.0.0",
|
|
271
|
+
"concat-map": "0.0.1"
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
"node_modules/@appium/support/node_modules/rimraf/node_modules/glob": {
|
|
275
|
+
"version": "7.2.3",
|
|
276
|
+
"license": "ISC",
|
|
277
|
+
"dependencies": {
|
|
278
|
+
"fs.realpath": "^1.0.0",
|
|
279
|
+
"inflight": "^1.0.4",
|
|
280
|
+
"inherits": "2",
|
|
281
|
+
"minimatch": "^3.1.1",
|
|
282
|
+
"once": "^1.3.0",
|
|
283
|
+
"path-is-absolute": "^1.0.0"
|
|
284
|
+
},
|
|
285
|
+
"engines": {
|
|
286
|
+
"node": "*"
|
|
287
|
+
},
|
|
288
|
+
"funding": {
|
|
289
|
+
"url": "https://github.com/sponsors/isaacs"
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
"node_modules/@appium/support/node_modules/rimraf/node_modules/minimatch": {
|
|
293
|
+
"version": "3.1.2",
|
|
294
|
+
"license": "ISC",
|
|
295
|
+
"dependencies": {
|
|
296
|
+
"brace-expansion": "^1.1.7"
|
|
297
|
+
},
|
|
298
|
+
"engines": {
|
|
299
|
+
"node": "*"
|
|
300
|
+
}
|
|
301
|
+
},
|
|
253
302
|
"node_modules/@appium/support/node_modules/semver": {
|
|
254
303
|
"version": "7.3.8",
|
|
255
304
|
"license": "ISC",
|
|
@@ -1189,7 +1238,7 @@
|
|
|
1189
1238
|
"license": "MIT"
|
|
1190
1239
|
},
|
|
1191
1240
|
"node_modules/appium-adb": {
|
|
1192
|
-
"version": "9.10.
|
|
1241
|
+
"version": "9.10.22",
|
|
1193
1242
|
"license": "Apache-2.0",
|
|
1194
1243
|
"dependencies": {
|
|
1195
1244
|
"@appium/support": "^3.0.0",
|
|
@@ -1246,7 +1295,7 @@
|
|
|
1246
1295
|
"license": "ISC"
|
|
1247
1296
|
},
|
|
1248
1297
|
"node_modules/appium-android-driver": {
|
|
1249
|
-
"version": "5.8.
|
|
1298
|
+
"version": "5.8.8",
|
|
1250
1299
|
"license": "Apache-2.0",
|
|
1251
1300
|
"dependencies": {
|
|
1252
1301
|
"@babel/runtime": "^7.0.0",
|
|
@@ -1312,7 +1361,7 @@
|
|
|
1312
1361
|
"license": "ISC"
|
|
1313
1362
|
},
|
|
1314
1363
|
"node_modules/appium-chromedriver": {
|
|
1315
|
-
"version": "5.2.
|
|
1364
|
+
"version": "5.2.14",
|
|
1316
1365
|
"hasInstallScript": true,
|
|
1317
1366
|
"license": "Apache-2.0",
|
|
1318
1367
|
"dependencies": {
|
|
@@ -3795,19 +3844,6 @@
|
|
|
3795
3844
|
"node": ">=8"
|
|
3796
3845
|
}
|
|
3797
3846
|
},
|
|
3798
|
-
"node_modules/rimraf": {
|
|
3799
|
-
"version": "3.0.2",
|
|
3800
|
-
"license": "ISC",
|
|
3801
|
-
"dependencies": {
|
|
3802
|
-
"glob": "^7.1.3"
|
|
3803
|
-
},
|
|
3804
|
-
"bin": {
|
|
3805
|
-
"rimraf": "bin.js"
|
|
3806
|
-
},
|
|
3807
|
-
"funding": {
|
|
3808
|
-
"url": "https://github.com/sponsors/isaacs"
|
|
3809
|
-
}
|
|
3810
|
-
},
|
|
3811
3847
|
"node_modules/safe-buffer": {
|
|
3812
3848
|
"version": "5.2.1",
|
|
3813
3849
|
"funding": [
|
|
@@ -4725,6 +4761,38 @@
|
|
|
4725
4761
|
"brace-expansion": "^2.0.1"
|
|
4726
4762
|
}
|
|
4727
4763
|
},
|
|
4764
|
+
"rimraf": {
|
|
4765
|
+
"version": "3.0.2",
|
|
4766
|
+
"requires": {
|
|
4767
|
+
"glob": "^7.1.3"
|
|
4768
|
+
},
|
|
4769
|
+
"dependencies": {
|
|
4770
|
+
"brace-expansion": {
|
|
4771
|
+
"version": "1.1.11",
|
|
4772
|
+
"requires": {
|
|
4773
|
+
"balanced-match": "^1.0.0",
|
|
4774
|
+
"concat-map": "0.0.1"
|
|
4775
|
+
}
|
|
4776
|
+
},
|
|
4777
|
+
"glob": {
|
|
4778
|
+
"version": "7.2.3",
|
|
4779
|
+
"requires": {
|
|
4780
|
+
"fs.realpath": "^1.0.0",
|
|
4781
|
+
"inflight": "^1.0.4",
|
|
4782
|
+
"inherits": "2",
|
|
4783
|
+
"minimatch": "^3.1.1",
|
|
4784
|
+
"once": "^1.3.0",
|
|
4785
|
+
"path-is-absolute": "^1.0.0"
|
|
4786
|
+
}
|
|
4787
|
+
},
|
|
4788
|
+
"minimatch": {
|
|
4789
|
+
"version": "3.1.2",
|
|
4790
|
+
"requires": {
|
|
4791
|
+
"brace-expansion": "^1.1.7"
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
},
|
|
4728
4796
|
"semver": {
|
|
4729
4797
|
"version": "7.3.8",
|
|
4730
4798
|
"requires": {
|
|
@@ -5368,7 +5436,7 @@
|
|
|
5368
5436
|
"version": "1.1.0"
|
|
5369
5437
|
},
|
|
5370
5438
|
"appium-adb": {
|
|
5371
|
-
"version": "9.10.
|
|
5439
|
+
"version": "9.10.22",
|
|
5372
5440
|
"requires": {
|
|
5373
5441
|
"@appium/support": "^3.0.0",
|
|
5374
5442
|
"@babel/runtime": "^7.0.0",
|
|
@@ -5408,7 +5476,7 @@
|
|
|
5408
5476
|
}
|
|
5409
5477
|
},
|
|
5410
5478
|
"appium-android-driver": {
|
|
5411
|
-
"version": "5.8.
|
|
5479
|
+
"version": "5.8.8",
|
|
5412
5480
|
"requires": {
|
|
5413
5481
|
"@babel/runtime": "^7.0.0",
|
|
5414
5482
|
"appium-adb": "^9.10.9",
|
|
@@ -5454,7 +5522,7 @@
|
|
|
5454
5522
|
}
|
|
5455
5523
|
},
|
|
5456
5524
|
"appium-chromedriver": {
|
|
5457
|
-
"version": "5.2.
|
|
5525
|
+
"version": "5.2.14",
|
|
5458
5526
|
"requires": {
|
|
5459
5527
|
"@appium/base-driver": "^9.1.0",
|
|
5460
5528
|
"@appium/support": "^3.0.0",
|
|
@@ -7058,12 +7126,6 @@
|
|
|
7058
7126
|
"signal-exit": "^3.0.2"
|
|
7059
7127
|
}
|
|
7060
7128
|
},
|
|
7061
|
-
"rimraf": {
|
|
7062
|
-
"version": "3.0.2",
|
|
7063
|
-
"requires": {
|
|
7064
|
-
"glob": "^7.1.3"
|
|
7065
|
-
}
|
|
7066
|
-
},
|
|
7067
7129
|
"safe-buffer": {
|
|
7068
7130
|
"version": "5.2.1"
|
|
7069
7131
|
},
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"automated testing",
|
|
8
8
|
"android"
|
|
9
9
|
],
|
|
10
|
-
"version": "2.
|
|
10
|
+
"version": "2.14.0",
|
|
11
11
|
"author": "Appium Contributors",
|
|
12
12
|
"license": "Apache-2.0",
|
|
13
13
|
"repository": {
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"lint-staged": "^13.0.3",
|
|
122
122
|
"mocha": "^10.0.0",
|
|
123
123
|
"pre-commit": "^1.2.2",
|
|
124
|
-
"rimraf": "^
|
|
124
|
+
"rimraf": "^4.0.4",
|
|
125
125
|
"semantic-release": "^19.0.2",
|
|
126
126
|
"sinon": "^15.0.0",
|
|
127
127
|
"webdriverio": "^8.0.2",
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
* you may not use this file except in compliance with the License.
|
|
4
|
-
* See the NOTICE file distributed with this work for additional
|
|
5
|
-
* information regarding copyright ownership.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
package io.appium.espressoserver.lib.helpers
|
|
18
|
-
|
|
19
|
-
import android.graphics.Bitmap
|
|
20
|
-
import android.util.Base64
|
|
21
|
-
import android.view.View
|
|
22
|
-
|
|
23
|
-
import java.io.ByteArrayOutputStream
|
|
24
|
-
import androidx.test.runner.screenshot.Screenshot
|
|
25
|
-
import io.appium.espressoserver.lib.handlers.exceptions.AppiumException
|
|
26
|
-
import io.appium.espressoserver.lib.handlers.exceptions.ElementNotVisibleException
|
|
27
|
-
import io.appium.espressoserver.lib.handlers.exceptions.ScreenCaptureException
|
|
28
|
-
import io.appium.espressoserver.lib.model.ViewElement
|
|
29
|
-
|
|
30
|
-
class ScreenshotsHelper @JvmOverloads constructor(private val view: View? = null) {
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Makes a screenshot of the particular view.
|
|
34
|
-
*
|
|
35
|
-
* @return the screenshot of the view as base-64 encoded string.
|
|
36
|
-
* @throws ElementNotVisibleException if the view has no visible area.
|
|
37
|
-
* @throws ScreenCaptureException if it is impossible to take a screenshot.
|
|
38
|
-
*/
|
|
39
|
-
val screenshot: String
|
|
40
|
-
@Throws(AppiumException::class)
|
|
41
|
-
get() {
|
|
42
|
-
if (view != null && ViewElement(view).bounds.isEmpty) {
|
|
43
|
-
throw ElementNotVisibleException(
|
|
44
|
-
String.format("Cannot get a screenshot of the invisible %s", view.javaClass.name))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
val screenCap = if (view == null) Screenshot.capture() else Screenshot.capture(view)
|
|
48
|
-
val bitmapScreenCap = screenCap.bitmap
|
|
49
|
-
if (bitmapScreenCap == null || bitmapScreenCap.height == 0 || bitmapScreenCap.width == 0) {
|
|
50
|
-
throw ScreenCaptureException("Cannot capture a shot of the " +
|
|
51
|
-
"${if (view == null) "current screen" else view.javaClass.name}. " +
|
|
52
|
-
"Make sure none of the currently visible " +
|
|
53
|
-
"views have FLAG_SECURE set and that it is possible to take a screenshot manually")
|
|
54
|
-
}
|
|
55
|
-
val outputStream = ByteArrayOutputStream()
|
|
56
|
-
bitmapScreenCap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
|
|
57
|
-
return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP)
|
|
58
|
-
}
|
|
59
|
-
}
|