Giter Club home page Giter Club logo

Comments (19)

scottyab avatar scottyab commented on May 26, 2024 3

Thanks @malachid 👍 I'd forgotten the need for companion object. The below allows me to run Espresso tests from Android Studio.

companion object {
        @ClassRule
        @JvmField
        val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
    }

from okreplay.

cbuche avatar cbuche commented on May 26, 2024 1

After going in circles for the better part of a day, I've found that I need the following tools value in order for the GrantPermissionRule to work (in addition to the @ClassRule annotation)

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>

from okreplay.

felipecsl avatar felipecsl commented on May 26, 2024

Are you running from the command line or Android Studio?

from okreplay.

christopherperry avatar christopherperry commented on May 26, 2024

Android Studio, from the test class.

from okreplay.

felipecsl avatar felipecsl commented on May 26, 2024

Hmm that may be why. Does it work if you run from the command line with ./gradlew connectedAndroidCheck?

from okreplay.

christopherperry avatar christopherperry commented on May 26, 2024

./gradlew connectedAndroidTest is able to run the tests; however, the tests fail. Perhaps the IdlingResource isn't working correctly?

from okreplay.

felipecsl avatar felipecsl commented on May 26, 2024

Well that's gonna depend on why it's failing, but that's out of the scope of this issue, it seems.
Regarding the original problem, I think it's expected that running from Android Studio doesn't respect adbOptions unfortunately

from okreplay.

athkalia avatar athkalia commented on May 26, 2024

It seems to respect the adbOptions for me, as long as you have the permission defined in the AndroidManifest

from okreplay.

niranjani23 avatar niranjani23 commented on May 26, 2024

@athkalia I still see the same issue. Were you able to get the test running from Android Studio?

from okreplay.

niranjani23 avatar niranjani23 commented on May 26, 2024

@felipecsl I too noticed the error: We need WRITE_EXTERNAL_STORAGE permission for OkReplay.
Do you mind updating the readme if the test can be invoked only via command line and not via Android Studio?

from okreplay.

athkalia avatar athkalia commented on May 26, 2024

I'll give it another bash over the weekend and update here

from okreplay.

athkalia avatar athkalia commented on May 26, 2024

indeed I've tried it once more and it doesn't seem to work, sorry

from okreplay.

athkalia avatar athkalia commented on May 26, 2024

Setup is here btw if you want to experiment a bit
https://github.com/athkalia/Just-Another-Android-App

from okreplay.

felipecsl avatar felipecsl commented on May 26, 2024

I've been running usually on API25 emulators with no problems. Are you running on physical devices?

from okreplay.

malachid avatar malachid commented on May 26, 2024

Confirmed that I ran into the same problem trying to run a test against the LG v20 from A.S.

from okreplay.

malachid avatar malachid commented on May 26, 2024

I was able to get past the permission problem by using the GrantPermissionRule.

    @ClassRule
    public static GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant(
        Manifest.permission.WRITE_EXTERNAL_STORAGE
    );

from okreplay.

scottyab avatar scottyab commented on May 26, 2024

I'm unable to get past the permissions issue with the GrantPermissionRule. I couldn't use the @ClassRule as the compiler complained about it not being static 😞

@Rule
@JvmField
    public val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)

from okreplay.

malachid avatar malachid commented on May 26, 2024

@scottyab did you put that in a companion object?

from okreplay.

ddudek avatar ddudek commented on May 26, 2024

After going in circles despite above suggestions, using ClassRule in companion object worked, but this gave me a hint that it's an rules ordering issue so also this approach below works using just RuleChain and regular @Rule annotation:

    var permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
    var activityTestRule = ActivityTestRule(ExampleActivity::class.java, false, false)
    val okReplayRule: TestRule = OkReplayRuleChain(configuration, activityTestRule).get()

    @Rule
    @JvmField
    val ruleChain: RuleChain = RuleChain.outerRule(activityTestRule).around(permissionRule).around(okReplayRule)

from okreplay.

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.