- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8
Introduce network mocking to the toolkit #969
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
          
     Merged
      
      
            kaushikrw
  merged 15 commits into
  feature-branches/forms
from
kaushik/forms/network-request-mocking
  
      
      
   
  Oct 16, 2025 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      660009c
              
                init test runners
              
              
                kaushikrw e82a8b3
              
                refactor plugin
              
              
                kaushikrw 11d2fe3
              
                fix config vars
              
              
                kaushikrw 65d49ce
              
                update tests to use mock class
              
              
                kaushikrw 9f1e58a
              
                add log interceptor
              
              
                kaushikrw 64fc1dd
              
                add logs
              
              
                kaushikrw 765d072
              
                Delete buildSrc/.kotlin/errors/errors-1755038697331.log
              
              
                kaushikrw f108f01
              
                remove logging
              
              
                kaushikrw 443d19f
              
                update since tags
              
              
                kaushikrw 8a29f86
              
                Merge branch 'feature-branches/forms' into kaushik/forms/network-requ…
              
              
                kaushikrw 4aaa8b1
              
                Merge branch 'feature-branches/forms' into kaushik/forms/network-requ…
              
              
                kaushikrw c7fe22f
              
                Merge branch 'feature-branches/forms' into kaushik/forms/network-requ…
              
              
                kaushikrw 888de27
              
                update tests
              
              
                kaushikrw ea7ae19
              
                Merge branch 'feature-branches/forms' into kaushik/forms/network-requ…
              
              
                kaushikrw 02595fa
              
                fix group element tests
              
              
                kaushikrw File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright 2025 Esri | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|  | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.provider.ListProperty | ||
| import org.gradle.api.provider.Property | ||
| import org.gradle.kotlin.dsl.create | ||
| import java.io.File | ||
|  | ||
| /** | ||
| * An extension to configure the [GrantTestPermissions] plugin. | ||
| */ | ||
| abstract class PermissionPluginExtension { | ||
|  | ||
| /** | ||
| * The package name of the application for which permissions will be granted. | ||
| */ | ||
| abstract val packageName: Property<String> | ||
|  | ||
| /** | ||
| * The path to the ADB executable. | ||
| */ | ||
| abstract val adbPath: Property<File> | ||
|  | ||
| /** | ||
| * A list of permissions to be granted to the application. | ||
| * Each permission should be specified as a string, e.g., "android.permission.CAMERA". | ||
| */ | ||
| abstract val permissions: ListProperty<String> | ||
| } | ||
|  | ||
| /** | ||
| * A Gradle plugin to grant runtime permissions to a test application. This plugin is useful for | ||
| * Android instrumented tests that require specific permissions to be granted before running tests. | ||
| * It automates the process of granting permissions using ADB. | ||
| * | ||
| * @since 300.0.0 | ||
| */ | ||
| class GrantTestPermissions : Plugin<Project> { | ||
| override fun apply(project: Project) { | ||
| val extension = | ||
| project.extensions.create<PermissionPluginExtension>("grantTestPermissionsConfig") | ||
| val grantPermissionTask = project.tasks.register("grantTestPermissions") { | ||
| doLast { | ||
| val packageName = extension.packageName.get() | ||
| val adb = extension.adbPath.get() | ||
| val permissions = extension.permissions.get() | ||
| println("Granting permissions for package: $packageName") | ||
| permissions.forEach { permission -> | ||
| if (permission.contains("MANAGE_EXTERNAL_STORAGE")) { | ||
| // Special handling for MANAGE_EXTERNAL_STORAGE permission | ||
| project.providers.exec { | ||
| commandLine( | ||
| adb, | ||
| "shell", | ||
| "appops", | ||
| "set", | ||
| "--uid", | ||
| packageName, | ||
| "MANAGE_EXTERNAL_STORAGE", | ||
| "allow" | ||
| ) | ||
| }.result.get().assertNormalExitValue() | ||
| } else { | ||
| // General permission granting | ||
| project.providers.exec { | ||
| commandLine(adb, "shell", "pm", "grant", packageName, permission) | ||
| }.result.get().assertNormalExitValue() | ||
| } | ||
| println("Granted permission: $permission") | ||
| } | ||
| } | ||
| } | ||
|  | ||
| project.afterEvaluate { | ||
| // Configure the task runs right after the install task | ||
| project.tasks.matching { it.name.startsWith("install") && it.name.endsWith("AndroidTest") } | ||
| .forEach { installTask -> | ||
| grantPermissionTask.get().dependsOn(installTask) | ||
| } | ||
| // Configure the task runs before the connectedAndroidTest tasks | ||
| project.tasks.matching { it.name.startsWith("connected") && it.name.endsWith("AndroidTest") } | ||
| .forEach { connectedTask -> | ||
| connectedTask.dependsOn(grantPermissionTask.get()) | ||
| } | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|  | ||
| <!-- Note: this manifest is only applied to instrumented tests --> | ||
|  | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
| <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> | ||
| <uses-permission android:name="android.permission.CAMERA"/> | ||
|  | ||
| </manifest> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am understanding this correctly, then the
GrantTestPermissionsplugin doesn't actually need to grant the camera permission before running the tests, because the test can request it. I have some questions about this though:Could we grant the storage permissions usingI investigated this and it's not possibleGrantPermissionRule? If so, could we add that as aBeforeAfterActiononce we have that available to the toolkit (soon)?GrantPermissionRule, we don't need to worry about the manifest? I'm guessing that is the case because I don't see it in the docs and you are just now adding the permissions to the manifestThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the camera permission can stay within the test. I just moved it out because the having all the permissions granted by the plugin made sense.
I believe so according to the doc. But the manage storage permission definitely need the manifest.