Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BaristaCaptureInteractions #542

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ closeKeyboard()
pressImeActionButton()
```

#### Capturing screenshots or images of views
```java
captureView(R.id.view, "bitmap-filename");
captureView("Text", "bitmap-filename");
captureActivity("bitmap-filename");
captureScreenshot("bitmap-filename");
```

#### And another tricky feature, but try not to use it
```java
sleep(2000);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.adevinta.android.barista.interaction

import androidx.test.core.app.takeScreenshot
import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.captureToBitmap
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import com.adevinta.android.barista.internal.performAction
import com.adevinta.android.barista.internal.util.resourceMatcher
import com.adevinta.android.barista.internal.matcher.withCompatText

object BaristaCaptureInteractions {
@JvmStatic
fun captureView(resId: Int, fileName: String) {
resId.resourceMatcher().performAction(captureToBitmap { it.writeToTestStorage(fileName) })
}

@JvmStatic
fun captureView(text: String, fileName: String) {
withCompatText(text).performAction(captureToBitmap { it.writeToTestStorage(fileName) })
}

@JvmStatic
fun captureActivity(fileName: String) {
onView(isRoot()).perform(captureToBitmap { it.writeToTestStorage(fileName) })
}

@JvmStatic
fun captureScreenshot(fileName: String) {
takeScreenshot().writeToTestStorage(fileName)
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ composeCompiler = "1.3.2"
androidXAppCompat = "1.0.2"
androidXAnnotation = "1.0.2"
androidXCore = "1.0.1"
androidXEspresso = "3.4.0"
androidXEspresso = "3.6.1"
androidXJUnit = "1.1.3"
androidXLegacy = "1.0.0"
androidXLifecycle = "2.3.1"
Expand Down