appium-espresso-driver icon indicating copy to clipboard operation
appium-espresso-driver copied to clipboard

Not able to launch app when using Espresso with Appium v1.15.1

Open Plingingo opened this issue 5 years ago • 5 comments

I have a very simple test app that just launches my Android app - if I set the "automationName" to "UiAutomator2" then my app is launched fine but if I change this to "Espresso" then nothing is launched.

In the Console, it mentions 1 test has ran and 1 test has passed but the app is not launched at all - this means that I am not given any errors so I don't know why my app isn't launching when using Espresso.

This is my code:

    private String APP = "https://github.com/cloudgrey-io/the-app/releases/download/v1.8.1/TheApp-v1.8.1.apk";
static AppiumDriver driver;

@BeforeTest
public void setup() {
	try {
		DesiredCapabilities caps = new DesiredCapabilities();

		 caps.setCapability("platformName", "Android");
		 caps.setCapability("deviceName", "Android Emulator");
		 caps.setCapability("automationName", "Espresso");
		 caps.setCapability("app", APP);
		 driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), caps);
 	
	}catch(Exception e) {
		System.out.println("Exception is :"+e.getCause());
		System.out.println("Message is :"+e.getMessage());
		e.printStackTrace();
	}
}

I'm not exactly sure of the app being downloaded here, this was just the example used in the online tutorial I was following in the hope of fixing my issue.

The app is launched if I use "UiAutomator2" but fails to launch when using "Espresso".

Is this a bug, or I am just missing something obvious?

Plingingo avatar Dec 09 '19 12:12 Plingingo

Please attach the full log. Espresso strongly depends on the test under app rather than UIA2, so dependency issues such as https://github.com/appium/appium-espresso-driver/issues/449 could happen, for example.

KazuCocoa avatar Dec 09 '19 12:12 KazuCocoa

After investigating the logs, it looks like I might have a couple of issues. I believe the reason I can't run the .apk mentioned above is because for some reason my test script seems to be referencing the app package for my own app (even though I can't find a reference to this anywhere in the code) - I will have to speak to my companies Test Department (as they original wrote the script I'm testing) to see if they know why it is referencing a different app.

When updating the "DesiredCapabilities" to my own app, I still get the same problem (ie. the app launches when using "UiAutomator2" but fails when using "Espresso").

Here is the log:

[RemoteTestNG] detected TestNG version 7.0.0 Exception is :java.lang.reflect.InvocationTargetException Message is :Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1959) at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093) at com.android.commands.am.Instrument.run(Instrument.java:419) at com.android.commands.am.Am.runInstrument(Am.java:187) at com.android.commands.am.Am.onRun(Am.java:80) at com.android.internal.os.BaseCommand.run(BaseCommand.java:54) at com.android.commands.am.Am.main(Am.java:50) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '51IDLT84AB17', ip: '10.210.104.47', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112' Driver info: driver.version: AppiumDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1959) at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093) at com.android.commands.am.Instrument.run(Instrument.java:419) at com.android.commands.am.Am.runInstrument(Am.java:187) at com.android.commands.am.Am.onRun(Am.java:80) at com.android.internal.os.BaseCommand.run(BaseCommand.java:54) at com.android.commands.am.Am.main(Am.java:50) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) at getResponseForW3CError (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9) at asyncHandler (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37) at process._tickCallback (internal/process/next_tick.js:68:7) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '51IDLT84AB17', ip: '10.210.104.47', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112' Driver info: driver.version: AppiumDriver org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1959) at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093) at com.android.commands.am.Instrument.run(Instrument.java:419) at com.android.commands.am.Am.runInstrument(Am.java:187) at com.android.commands.am.Am.onRun(Am.java:80) at com.android.internal.os.BaseCommand.run(BaseCommand.java:54) at com.android.commands.am.Am.main(Am.java:50) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '51IDLT84AB17', ip: '10.210.104.47', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112' Driver info: driver.version: AppiumDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1959) at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093) at com.android.commands.am.Instrument.run(Instrument.java:419) at com.android.commands.am.Am.runInstrument(Am.java:187) at com.android.commands.am.Am.onRun(Am.java:80) at com.android.internal.os.BaseCommand.run(BaseCommand.java:54) at com.android.commands.am.Am.main(Am.java:50) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) at getResponseForW3CError (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9) at asyncHandler (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37) at process._tickCallback (internal/process/next_tick.js:68:7) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '51IDLT84AB17', ip: '10.210.104.47', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112' Driver info: driver.version: AppiumDriver at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208) at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:323) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:86) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:96) at tests.BaseClass.setup(BaseClass.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62) at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:340) at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:294) at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:623) at org.testng.TestRunner.beforeRun(TestRunner.java:613) at org.testng.TestRunner.run(TestRunner.java:584) at org.testng.SuiteRunner.runTest(SuiteRunner.java:402) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355) at org.testng.SuiteRunner.run(SuiteRunner.java:304) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180) at org.testng.TestNG.runSuitesLocally(TestNG.java:1102) at org.testng.TestNG.runSuites(TestNG.java:1032) at org.testng.TestNG.run(TestNG.java:1000) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186) ... 36 more Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1959) at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093) at com.android.commands.am.Instrument.run(Instrument.java:419) at com.android.commands.am.Am.runInstrument(Am.java:187) at com.android.commands.am.Am.onRun(Am.java:80) at com.android.internal.os.BaseCommand.run(BaseCommand.java:54) at com.android.commands.am.Am.main(Am.java:50) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '51IDLT84AB17', ip: '10.210.104.47', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112' Driver info: driver.version: AppiumDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive at android.os.Parcel.readException(Parcel.java:2013) at android.os.Parcel.readException(Parcel.java:1959) at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093) at com.android.commands.am.Instrument.run(Instrument.java:419) at com.android.commands.am.Am.runInstrument(Am.java:187) at com.android.commands.am.Am.onRun(Am.java:80) at com.android.internal.os.BaseCommand.run(BaseCommand.java:54) at com.android.commands.am.Am.main(Am.java:50) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285) at getResponseForW3CError (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9) at asyncHandler (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37) at process._tickCallback (internal/process/next_tick.js:68:7) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62) at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126) at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source) at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source) at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source) at java.util.stream.AbstractPipeline.copyInto(Unknown Source) at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source) at java.util.stream.AbstractPipeline.evaluate(Unknown Source) at java.util.stream.ReferencePipeline.findFirst(Unknown Source) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128) ... 41 more PASSED: loginApp

=============================================== Default test Tests run: 1, Failures: 0, Skips: 0

=============================================== Default suite Total tests run: 1, Passes: 1, Failures: 0, Skips: 0

I've tried googling the errors in the log, and I found a link that mentions Espresso dependencies are needed to be built in the .apk for automated testing to be allowed. The following page was suggested as a means of setting this up: https://developer.android.com/training/testing/espresso/setup

Now my problem with this, is that my app is not written in native Android - my app is written in Xamarin Forms. The article mentions updating the build.gradle file, but as my app is written in Xamarin Forms I do not have a build.gradle file to update.

Does this sound like this could be my problem, and if so, do you know how I can add the Espresso dependencies to my Xamarin Forms app?

Plingingo avatar Dec 09 '19 15:12 Plingingo

I guess the test app failed to re-sign with Appium's developer sign. Espresso and the app under test should have the same signature. espresso-driver tries to re-sing the app under test with Appium's one, but it fails by some reason, such security exception happens.

I assume you can find a waring/error log about apksigner in your log if the re-sign action failed

remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: java.lang.SecurityException: Permission Denial: starting instrumentation ComponentInfo{io.appium.espressoserver.test/androidx.test.runner.AndroidJUnitRunner} from pid=22513, uid=22513 not allowed because package io.appium.espressoserver.test does not have a signature matching the target com.dhlparcel.mydrive
	at android.os.Parcel.readException(Parcel.java:2013)
	at android.os.Parcel.readException(Parcel.java:1959)
	at android.app.IActivityManager$Stub$Proxy.startInstrumentation(IActivityManager.java:5093)
	at com.android.commands.am.Instrument.run(Instrument.java:419)
	at com.android.commands.am.Am.runInstrument(Am.java:187)
	at com.android.commands.am.Am.onRun(Am.java:80)
	at com.android.internal.os.BaseCommand.run(BaseCommand.java:54)
	at com.android.commands.am.Am.main(Am.java:50)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285)
    at getResponseForW3CError (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
    at asyncHandler (C:\Users\kevinroughton\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: '51IDLT84AB17', ip: '10.210.104.47', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112'
Driver info: driver.version: AppiumDriver

KazuCocoa avatar Dec 10 '19 05:12 KazuCocoa

Hi, i want to ask about how to use this appium with espresso driver. Do we have to add espresso dependencies in the android application?

claraSpark avatar Aug 23 '20 21:08 claraSpark

Basically http://appium.io/docs/en/drivers/android-espresso/ is to start with the espresso driver. For other general questions, please ask in https://discuss.appium.io/ first

KazuCocoa avatar Aug 24 '20 03:08 KazuCocoa