Closed pawankums closed 7 years ago
You can pass such parameters as arguments for instrumentation runner https://github.com/stanfy/spoon-gradle-plugin#custom-instrumentation-arguments
@artem-zinnatullin Thanks for your reply. I had looked it in the past but could not figure out how to use it. Could you please guide me how to use it in my case, i need to pass userId and password through command line. correct me if i am wrong in the steps to implement it
Need to put in build.gradle spoon { instrumentationArgs = ["userId=qaa", "password=pass123"] }
in the test script - onView(withId(R.id.username)).perform(typeText(System.getProperty("userId")))
in the command line to execute the test ./gradlew spoon -PuserId="qaa" -Ppassword="pass123"
I tried with above steps but it did not work out.
Instrumentation arguments will be accessible by test runner, you can override AndroidJUnitRunner
and specify it as testInstrumentationRunner
in android
section of build.gradle
see example.
To access arguments you'll need to override onCreate(Bundle)
method of AndroidJUnitRunner
and get them from Bundle
.
Hi @artem-zinnatullin Thanks for your reply. I tried above steps and passing the params through command line as ./gradlew spoon -e userId 'qaa_user1' -e password 'pass123' but i am getting java.lang.IllegalArgumentException.
I am getting the params using Bundle testBundle = InstrumentationRegistry.getArguments(); userId = testBundle.getString("userId"); password = testBundle.getString("password");
Could you please let me know how to pass params in command line or if my syntax is wrong.
Can you show exception message?
On Mon, Aug 28, 2017, 8:06 AM pawankums notifications@github.com wrote:
Hi @artem-zinnatullin https://github.com/artem-zinnatullin Thanks for your reply. I tried above steps and passing the params through command line as ./gradlew spoon -e userId 'qaa_user1' -e password 'pass123' but i am getting java.lang.IllegalArgumentException.
I am getting the params using Bundle testBundle = InstrumentationRegistry.getArguments(); userId = testBundle.getString("userId"); password = testBundle.getString("password");
Could you please let me know how to pass params in command line or if my syntax is wrong.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/stanfy/spoon-gradle-plugin/issues/160#issuecomment-325380195, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7B3LN7ZLATAKxPzkLFlKZ1McnGivzvks5sctdvgaJpZM4PDEU7 .
@artem-zinnatullin Below is the error when i try to use the params using the above steps:
Exception occurred while dumping: java.lang.IllegalArgumentException: Unknown package: com.ecarlist.android.truetarget at com.android.server.pm.Settings.isOrphaned(Settings.java:4134) at com.android.server.pm.PackageManagerService.isOrphaned(PackageManagerService.java:18091) at com.android.server.pm.PackageManagerService.deletePackage(PackageManagerService.java:15508) at com.android.server.pm.PackageInstallerService.uninstall(PackageInstallerService.java:888) at com.android.server.pm.PackageManagerShellCommand.runUninstall(PackageManagerShellCommand.java:792) at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:118) at android.os.ShellCommand.exec(ShellCommand.java:94) at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:18349) at android.os.Binder.shellCommand(Binder.java:468) at android.os.Binder.onTransact(Binder.java:367) at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:2387) at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3031) at android.os.Binder.execTransact(Binder.java:565) ‘Tests failed’
Unknown package: com.ecarlist.android.truetarget
This error comes when i pass parameters to already working command ./gradlew spoon as ./gradlew spoon -e userId 'qaa_user1' -e password 'pass123'
I know that we can specify args in spoon task as spoon { instrumentationArgs = ["userId=qaa", "password=pass123"] }
but not sure how to pass these params through command line and how to access them in the program.
@artem-zinnatullin i tried your suggestions and added spoon { instrumentationArgs = ["userId=qaa", "password=pass123"] } and accessed these args in onCreate(Bundle ..). But this is like hardcoding the values in build.gradle whereas i want to pass the values through command line with ./gradlew spoon command.
The below code snippet should be able to solve the hardcoding problem.
if (project.hasProperty('userId') && project.hasProperty('password')) {
instrumentationArgs = ["userId=${project.userId}", "password=${project.password}"]
}
and from command line pass arguments like this ./gradlew spoon -PuserId=qaa_user1 -Ppassword=pass123
Hey @jainsahab thanks for your reply.. if (project.hasProperty('userId') && project.hasProperty('password')) { instrumentationArgs = ["userId=${project.userId}".toString(), "password=${project.password}".toString()] } Worked for me
Hi, I have an android automation framework using Espresso, Cucumber and Spoon. I run the tests using ./gradlew spoon command. I need to pass some argument to tests as userid & password. Not sure how to pass it. Tried to do so using ./gradlew spoon -DuserId="QAA_User1" -Dpassword="Pass123" in test referred these arguments using System.getProperty("userId") but it did not work. Test don't move further after System.getProperty("userId") statement. If anyone has worked on this scenario, plz help me out.
Thanks