appium / appium-espresso-driver

Espresso integration for Appium
Apache License 2.0
194 stars 75 forks source link

ClassCastException android.support.v4.view.ViewPager #331

Open saikrishna321 opened 5 years ago

saikrishna321 commented 5 years ago

@dpgraham @mykola-mokhnach

Picked the latest espresso from master v 1.3.0 to test new mobile: commands.

Code to replicate

MobileElement elementById = driver.findElementById("com.demotxt.droidsrce.slide:id/viewpager");
        Map<String, Object> args = new HashMap<>();
        args.put("element", elementById);
        args.put("scrollToPage", 2);
       driver.executeScript("mobile: scrollToPage", args);

Error Log:

[debug] [W3C (c0351d77)] Calling AppiumDriver.execute() with args: ["mobile: scrollToPage",[{"scrollToPage":2,"element":{"ELEMENT":"8ee35f9b-c443-421e-96ad-732836a52490","element-6066-11e4-a52e-4f735466cecf":"8ee35f9b-c443-421e-96ad-732836a52490"}}],"c0351d77-cac9-4a50-92ae-a9d7e45f7c98"]
[debug] [JSONWP Proxy] Proxying [POST /appium/execute_mobile/8ee35f9b-c443-421e-96ad-732836a52490/scroll_to_page] to [POST http://localhost:8300/session/c7facaae-82e2-4ad1-b254-47fdf751caaf/appium/execute_mobile/8ee35f9b-c443-421e-96ad-732836a52490/scroll_to_page] with body: {"scrollToPage":2}
[JSONWP Proxy] Got an unexpected response: {"id":"14fc51f4-5da0-4d53-8e48-8b0e5f86a64f","sessionId":null,"status":13,"value":"io.appium.espressoserver.lib.handlers.exceptions.AppiumException: Could not perform scroll to on element 8ee35f9b-c443-421e-96ad-732836a52490. Reason: java.lang.ClassCastException: android.support.v4.view.ViewPager...
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[debug] [W3C (c0351d77)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: io.appium.espressoserver.lib.handlers.exceptions.AppiumException: Could not perform scroll to on element 8ee35f9b-c443-421e-96ad-732836a52490. Reason: java.lang.ClassCastException: android.support.v4.view.ViewPager cannot be cast to androidx.viewpager.widget.ViewPager
[debug] [W3C (c0351d77)]     at io.appium.espressoserver.lib.handlers.ScrollToPage.handle(ScrollToPage.java:61)
[debug] [W3C (c0351d77)]     at io.appium.espressoserver.lib.handlers.ScrollToPage.handle(ScrollToPage.java:28)
[debug] [W3C (c0351d77)]     at io.appium.espressoserver.lib.http.Router.route(Router.java:293)
[debug] [W3C (c0351d77)]     at io.appium.espressoserver.lib.http.Server.serve(Server.java:65)
[debug] [W3C (c0351d77)]     at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
[debug] [W3C (c0351d77)]     at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
[debug] [W3C (c0351d77)]     at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
[debug] [W3C (c0351d77)]     at java.lang.Thread.run(Thread.java:764)

Sample App:

app-debug.apk.zip

More debugging:

As @mykola-mokhnach suggested I Migrated the project to AndroidX and gave a try. Manually i was able to install the app and everything works fine. When the same app was used with appum i bumped at below error

[debug] [JSONWP Proxy] Matched '/status' to command name 'getStatus'
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8300/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"id\":\"3f81b3d8-6764-467b-a6bf-3260d48ffafe\",\"sessionId\":null,\"status\":0,\"value\":null}"
[debug] [JSONWP Proxy] Matched '/session' to command name 'createSession'
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8300/session] with body: {"desiredCapabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"android","allowTestPackages":true,"app":"/Users/saikrisv/git/Slider/app/build/outputs/apk/debug/app-debug.apk","appActivity":"com.demotxt.droidsrce.slide.MainActivity","appPackage":"com.demotxt.droidsrce.slide","automationName":"Espresso","deviceName":"Android Emulator","launchTimeout":900000},"platformName":"android","allowTestPackages":true,"app":"/Users/saikrisv/git/Slider/app/build/outputs/apk/debug/app-debug.apk","appActivity":"com.demotxt.droidsrce.slide.MainActivity","appPackage":"com.demotxt.droidsrce.slide","automationName":"Espresso","deviceName":"emulator-5554","launchTimeout":900000,"deviceUDID":"emulator-5554"}}
[debug] [Espresso] [Instrumentation][STDOUT] io.appium.espressoserver.EspressoServerRunnerTest:
[debug] [Espresso] [Instrumentation][STDOUT] Process crashed while executing startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest):
[debug] [Espresso] [Instrumentation][STDOUT] android.content.res.Resources$NotFoundException: Drawable com.demotxt.droidsrce.slide:id/jumpToEnd with resource ID #0x7f070059
[debug] [Espresso] [Instrumentation][STDOUT] Caused by: android.content.res.Resources$NotFoundException: Resource "com.demotxt.droidsrce.slide:id/jumpToEnd" (7f070059) is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f070059}
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:739)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:609)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.Resources.getDrawable(Resources.java:818)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.Context.getDrawable(Context.java:605)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:753)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:196)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.demotxt.droidsrce.slide.MainActivity.onCreate(MainActivity.java:14)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.Activity.performCreate(Activity.java:6975)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.-wrap11(Unknown Source:0)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.os.Handler.dispatchMessage(Handler.java:105)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.os.Looper.loop(Looper.java:164)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.main(ActivityThread.java:6541)
[debug] [Espresso] [Instrumentation][STDOUT]    at java.lang.reflect.Method.invoke(Native Method)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
[debug] [Espresso] [Instrumentation][STDOUT]
[debug] [Espresso] [Instrumentation][STDOUT] Process crashed while executing startEspressoServer(io.appium.espressoserver.EspressoServerRunnerTest):
[debug] [Espresso] [Instrumentation][STDOUT] java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demotxt.droidsrce.slide/com.demotxt.droidsrce.slide.MainActivity}: android.content.res.Resources$NotFoundException: Drawable com.demotxt.droidsrce.slide:id/jumpToEnd with resource ID #0x7f070059
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.-wrap11(Unknown Source:0)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.os.Handler.dispatchMessage(Handler.java:105)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.os.Looper.loop(Looper.java:164)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.main(ActivityThread.java:6541)
[debug] [Espresso] [Instrumentation][STDOUT]    at java.lang.reflect.Method.invoke(Native Method)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
[debug] [Espresso] [Instrumentation][STDOUT] Caused by: android.content.res.Resources$NotFoundException: Drawable com.demotxt.droidsrce.slide:id/jumpToEnd with resource ID #0x7f070059
[debug] [Espresso] [Instrumentation][STDOUT] Caused by: android.content.res.Resources$NotFoundException: Resource "com.demotxt.droidsrce.slide:id/jumpToEnd" (7f070059) is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f070059}
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:739)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:609)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.res.Resources.getDrawable(Resources.java:818)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.content.Context.getDrawable(Context.java:605)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:753)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:196)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.demotxt.droidsrce.slide.MainActivity.onCreate(MainActivity.java:14)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.Activity.performCreate(Activity.java:6975)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
[debug] [Espresso] [Instrumentation][STDOUT]    at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:674)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.-wrap11(Unknown Source:0)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.os.Handler.dispatchMessage(Handler.java:105)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.os.Looper.loop(Looper.java:164)
[debug] [Espresso] [Instrumentation][STDOUT]    at android.app.ActivityThread.main(ActivityThread.java:6541)
[debug] [Espresso] [Instrumentation][STDOUT]    at java.lang.reflect.Method.invoke(Native Method)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
[debug] [Espresso] [Instrumentation][STDOUT]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
[JSONWP Proxy] Got an unexpected response: {"code":"ECONNRESET"}
[debug] [Espresso] Deleting espresso session
[debug] [ADB] Running '/Users/saikrisv/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am broadcast -a io.appium.settings.animation -n io.appium.settings/.receivers.AnimationSettingReceiver --es setstatus enable'
[debug] [Espresso] [Instrumentation][STDOUT] INSTRUMENTATION_RESULT: shortMsg=Process crashed.
[debug] [Espresso] [Instrumentation][STDOUT] INSTRUMENTATION_CODE: 0
[Espresso] Instrumentation process exited with code 0 from signal null
[debug] [ADB] Running '/Users/saikrisv/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.demotxt.droidsrce.slide'
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Device API level: 26
[debug] [ADB] Removing forwarded port socket connection: 8300
[debug] [ADB] Running '/Users/saikrisv/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp\:8300'
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1543706318035 (23:18:38 GMT+0000 (GMT))
[debug] [W3C] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up
[debug] [W3C]     at JWProxy.command (/usr/local/lib/node_modules/appium/node_modules/appium-espresso-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:236:13)
[debug] [W3C]     at <anonymous>
[HTTP] <-- POST /wd/hub/session 500 6889 ms - 586

Android X App:

_androidxapp-debug.apk.zip

dpgraham commented 5 years ago

It probably just needs better logging. These new contrib commands only work with specific view types. We should probably be checking the View Type before executing and throwing helpful errors.

saikrishna321 commented 5 years ago

@dpgraham Agree. In this case the ViewType for scrollToPage works only on ViewPager type and the application has ViewPager type.

dpgraham commented 5 years ago

Sounds like this is a known issue: https://issuetracker.google.com/issues/110573930

Probably best to hold off on this and let Google fix it.