Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
7bc1b7e9
Verified
Commit
7bc1b7e9
authored
3 years ago
by
Sebastian
Committed by
Mikolai Gütschow
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Experiment with testing API to take screenshots
parent
7ee4177a
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/Test.kt
+69
-0
69 additions, 0 deletions
...op/src/test/kotlin/org/briarproject/briar/desktop/Test.kt
with
69 additions
and
0 deletions
briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/Test.kt
0 → 100644
+
69
−
0
View file @
7bc1b7e9
/*
* Briar Desktop
* Copyright (C) 2021-2022 The Briar Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
org.briarproject.briar.desktop
import
android.graphics.Bitmap
import
androidx.compose.ui.graphics.asAndroidBitmap
import
androidx.compose.ui.test.InternalTestApi
import
androidx.compose.ui.test.captureToImage
import
androidx.compose.ui.test.junit4.ComposeContentTestRule
import
androidx.compose.ui.test.junit4.DesktopScreenshotTestRule
import
androidx.compose.ui.test.junit4.createComposeRule
import
androidx.compose.ui.test.onNodeWithText
import
androidx.compose.ui.test.onRoot
import
androidx.compose.ui.test.performClick
import
androidx.test.platform.app.InstrumentationRegistry
import
org.junit.Rule
import
org.junit.Test
import
java.io.FileOutputStream
// From https://dev.to/pchmielowski/automate-taking-screenshots-of-android-app-with-jetpack-compose-2950
@OptIn
(
InternalTestApi
::
class
)
class
ScreenshotTest
{
@
get
:
Rule
val
rule
=
createComposeRule
()
// Found this in compose/frameworks/support/compose/ui/ui-graphics/src/desktopTest/kotlin/androidx/compose/ui/graphics/DesktopGraphicsTest.kt
@
get
:
Rule
val
screenshotRule
=
DesktopScreenshotTestRule
(
"compose/ui/ui-desktop/graphics"
)
@Test
fun
makeScreenshot
()
{
rule
.
takeScreenshot
(
"before-click.png"
)
rule
.
onNodeWithText
(
"Show greeting"
)
.
performClick
()
rule
.
takeScreenshot
(
"after-click.png"
)
}
}
private
fun
ComposeContentTestRule
.
takeScreenshot
(
file
:
String
)
{
onRoot
()
.
captureToImage
()
.
asAndroidBitmap
()
.
save
(
file
)
}
private
fun
Bitmap
.
save
(
file
:
String
)
{
val
path
=
InstrumentationRegistry
.
getInstrumentation
().
targetContext
.
filesDir
.
canonicalPath
FileOutputStream
(
"$path/$file"
).
use
{
out
->
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
out
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment