android / android/testing-samples

Grant Permissions Rule errors out while connecting to UiAutomation

Open
#332 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
9.3k
Forks
3.6k
PR merge metrics
No merged PRs in 30d

Description

I keep getting these errors for few of my automation tests. Most of the times, on re-running the tests, it works fine again

```
java.lang.RuntimeException: Error while connecting UiAutomation
at android.app.UiAutomation.connect(UiAutomation.java:239)
at android.app.Instrumentation.getUiAutomation(Instrumentation.java:2045)
at android.app.Instrumentation.getUiAutomation(Instrumentation.java:2002)
at androidx.test.runner.permission.UiAutomationShellCommand.(UiAutomationShellCommand.java:65)
at androidx.test.runner.permission.PermissionRequester.addPermissions(PermissionRequester.java:92)
at androidx.test.rule.GrantPermissionRule.grantPermissions(GrantPermissionRule.java:100)
at androidx.test.rule.GrantPermissionRule.grant(GrantPermissionRule.java:94)
at com.example.package.tests.BaseTest.(BaseTest.java:40)
at com.example.package.tests.ReportFragmentTest.(ReportFragmentTest.java:22)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:104)
```

I am granting permissions in the following manner

```
public GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE);
```

Any help in this regards will be appreciated.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the intermittent failure around GrantPermissionRule.grantPermissions and the UiAutomation.connect stack trace, using the permission declaration shown in the issue. Trace the call from BaseTest.java:40 through PermissionRequester and UiAutomationShellCommand, then determine why rerunning sometimes succeeds. Done means the cause is established and the permission setup no longer intermittently fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev, testing
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.