GithubHelp home page GithubHelp logo

Comments (5)

pedrovgs avatar pedrovgs commented on July 17, 2024

Hi, @juanscigliano I'll try to answer your question but I'm also going to close this issue. We aim to use GitHub issues for bug reporting or feature request, sorry for that.

When trying to use screenshot testing every animated component has to be disabled. But just during the test execution. You need to disable the progress bar animation and the edit text cursor blinking because if you don't do that the screenshot test to become indeterminate. You'd need to wrap your components using a flavor and disable the animations, or in some point in your code detect if you are running a test or not and disable the animations.

As you might be thinking, this is a smell. Your production code should not change the behavior implemented based on if the execution context is a test runner or the production environment. But this is the only way you have to use this testing strategy. When using Espresso or screenshot testing you'll face similar issues with animations.

TLDR: You need to update your code to disable animations and the cursor just during the tests execution.

I hope this is the answer to your question. If you have any other doubt please, drop a question at stack overflow or send me an email at [email protected] and I'll try to answer 😃

from shot.

juanscigliano avatar juanscigliano commented on July 17, 2024

@pedrovgs Thanks for the answer, your approach make total sense.

from shot.

SUPERCILEX avatar SUPERCILEX commented on July 17, 2024

You can also recursively kill the cursors. Here's a full example for anyone wanting to copypasta stuff:

fun <T : Activity> ActivityScenario<T>.takeScreenshot() {
    lateinit var activity: Activity
    onActivity {
        activity = it
    }

    activity.hideCursors()
    Thread.sleep(500) // Wait for animations to finish

    // The automated screenshot naming is based off of stack trace analysis. We can't put this in
    // the onActivity lambda because that gets posted to the main thread.
    Screenshot.snapActivity(activity).record()
}

private fun Activity.hideCursors() {
    runOnUiThread { findViewById<ViewGroup>(android.R.id.content).hideCursors() }
}

private fun ViewGroup.hideCursors() {
    for (child in children) {
        if (child is ViewGroup) child.hideCursors()
        if (child is TextView) child.isCursorVisible = false
    }
}

from shot.

mecoFarid avatar mecoFarid commented on July 17, 2024

@SUPERCILEX Assumptions like wait 500 ms then you should be good to go are the reason most tests fail and we stay like a stickman thinking about what the hell caused the issue

from shot.

mecoFarid avatar mecoFarid commented on July 17, 2024

TLDR: You need to update your code to disable animations and the cursor just during the tests execution.

Rewriting the app :)

from shot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.