Comments (19)
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.
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.
Are you running from the command line or Android Studio?
from okreplay.
Android Studio, from the test class.
from okreplay.
Hmm that may be why. Does it work if you run from the command line with ./gradlew connectedAndroidCheck
?
from okreplay.
./gradlew connectedAndroidTest
is able to run the tests; however, the tests fail. Perhaps the IdlingResource
isn't working correctly?
from okreplay.
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.
It seems to respect the adbOptions for me, as long as you have the permission defined in the AndroidManifest
from okreplay.
@athkalia I still see the same issue. Were you able to get the test running from Android Studio?
from okreplay.
@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.
I'll give it another bash over the weekend and update here
from okreplay.
indeed I've tried it once more and it doesn't seem to work, sorry
from okreplay.
Setup is here btw if you want to experiment a bit
https://github.com/athkalia/Just-Another-Android-App
from okreplay.
I've been running usually on API25 emulators with no problems. Are you running on physical devices?
from okreplay.
Confirmed that I ran into the same problem trying to run a test against the LG v20 from A.S.
from okreplay.
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.
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.
@scottyab did you put that in a companion object?
from okreplay.
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)
- To make OkReplayInterceptor open again. HOT 2
- ConnectedDeviceProvider should be closed after use
- Update to latest espresso? HOT 3
- Tasks fail in a project using version 4.0.0 of the Android Gradle Plugin HOT 8
- Cannot build project HOT 2
- Requests indexation
- Cannot query the value of property 'applicationId' HOT 2
- Transitive dependency on vulnerable `org.yaml:snakeyaml`
- Sequential request matching with rules HOT 2
- Replace data in yaml file with fake data in @Before setUp() method
- Work together with RoboElectric HOT 2
- Make Optional public HOT 4
- Can OkReplay works with Protocol Buffer? HOT 1
- Make it work with androidx
- Build issue with customized okreplay HOT 1
- Possible to get a new release cut? HOT 6
- Multiple flavours wrong pull directory HOT 2
- NoSuchMethodError (GlobalScope.getAndroidBuilder) with android gradle plugin 3.5.0-beta01 HOT 6
- Gradle plugin checks for connected devices at configuration time HOT 2
- Cannot use plugin 1.5.0 with AGP 3.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okreplay.