appium / python-client

Python language bindings for Appium
Apache License 2.0
1.68k stars 562 forks source link

How to use "mobile: startActivity" to start activity like before? #1015

Closed xieyixing639 closed 2 months ago

xieyixing639 commented 2 months ago

The problem

I complete the jump of page a ->b ->c by clicking the button in app, where page a and b belong to same activity. At this time, I invoke start_activity in page c, and I will return to page a : self.driver.startActivity(appPackage, appActivity) , and the version of appium-python-client is 2.10.1.

But when I updata the version of appium-python-client to 4.0.1, I can not use startActivity. So I use

self.driver.execute_script(
            'mobile: startActivity',
            {
                'component': f'com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity',
            },
        )

, however, it will return to page b instead of a. How can I return to page a like before?

Environment

KazuCocoa commented 2 months ago

What is the activity names on each activity, a, b and c?

https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-startactivity is the full available ones. I wondered you needed intent.

xieyixing639 commented 2 months ago

What is the activity names on each activity, a, b and c?

https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-startactivity is the full available ones. I wondered you needed intent.

a: com.ss.android.ugc.aweme/.splash.SplashActivity b: com.ss.android.ugc.aweme/.splash.SplashActivity c: com.ss.android.ugc.aweme/.setting.ui.DouYinSettingNewVersionActivity

how should I set intent?

KazuCocoa commented 2 months ago

Like you already did for component,

{'intent': 'com.ss.android.ugc.aweme/.splash.SplashActivity'}

I'd recommend checking what adb command is issued by Appium by reading the Appium server log to make sure issued adb command is intended for you

xieyixing639 commented 2 months ago

Like you already did for component,

{'intent': 'com.ss.android.ugc.aweme/.splash.SplashActivity'}

I'd recommend checking what adb command is issued by Appium by reading the Appium server log to make sure issued adb command is intended for you

when I use 'intent', nothing happen, I am still in page c

[c2519caf][AndroidUiautomator2Driver@10a9] Cached the protocol value 'W3C' for the new session c2519caf-c887-48c3-a131-c01aba28a03a
[c2519caf][AndroidUiautomator2Driver@10a9] Responding to client with driver.createSession() result: {"capabilities":{"platformName":"Android","automationName":"uiautomator2","platformVersion":"13","deviceName":"23e90ab3","appPackage":"com.ss.android.ugc.aweme","appActivity":"com.ss.android.ugc.aweme.splash.SplashActivity","noReset":true,"newCommandTimeout":14400,"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","automationName":"uiautomator2","platformVersion":"13","deviceName":"2312DRA50C","appPackage":"com.ss.android.ugc.aweme","appActivity":"com.ss.android.ugc.aweme.splash.SplashActivity","noReset":true,"newCommandTimeout":14400},"deviceUDID":"23e90ab3","pixelRatio":"3","statBarHeight":104,"viewportRect":{"left":0,"top":104,"width":1220,"height":2608},"deviceApiLevel":33,"deviceManufacturer":"Xiaomi","deviceModel":"2312DRA50C","deviceScreenSize":"1220x2712","deviceScreenDensity":480}}
[c2519caf][HTTP] <-- POST /session 200 6029 ms - 1041
[c2519caf][HTTP] --> POST /session/c2519caf-c887-48c3-a131-c01aba28a03a/timeouts {"implicit":20000}
[c2519caf][AndroidUiautomator2Driver@10a9] Calling AppiumDriver.timeouts() with args: [null,null,null,null,20000,"c2519caf-c887-48c3-a131-c01aba28a03a"]
[c2519caf][AndroidUiautomator2Driver@10a9] W3C timeout argument: {"implicit":20000}}
[c2519caf][AndroidUiautomator2Driver@10a9] Set implicit wait to 20000ms
[c2519caf][AndroidUiautomator2Driver@10a9] Responding to client with driver.timeouts() result: null
[c2519caf][HTTP] <-- POST /session/c2519caf-c887-48c3-a131-c01aba28a03a/timeouts 200 3 ms - 14
[c2519caf][HTTP] --> POST /session/c2519caf-c887-48c3-a131-c01aba28a03a/execute/sync {"script":"mobile: startActivity","args":[{"intent":"com.ss.android.ugc.aweme/.splash.SplashActivity"}]}
[c2519caf][AndroidUiautomator2Driver@10a9] Calling AppiumDriver.execute() with args: ["mobile: startActivity",[{"intent":"com.ss.android.ugc.aweme/.splash.SplashActivity"}],"c2519caf-c887-48c3-a131-c01aba28a03a"]
[c2519caf][AndroidUiautomator2Driver@10a9] Executing native command 'mobile: startActivity'
[c2519caf][ADB] Running 'C:\Space\environment\android-sdk-windows\platform-tools\adb.exe -P 5037 -s 23e90ab3 shell am start-activity com.ss.android.ugc.aweme/.splash.SplashActivity'
[c2519caf][AndroidUiautomator2Driver@10a9] Responding to client with driver.execute() result: "Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ss.android.ugc.aweme/.splash.SplashActivity }"
[c2519caf][HTTP] <-- POST /session/c2519caf-c887-48c3-a131-c01aba28a03a/execute/sync 200 126 ms - 154

But when I use 'component', I can go back to page b

[05409100][AndroidUiautomator2Driver@6981] Cached the protocol value 'W3C' for the new session 05409100-c072-4df2-90b5-51df5f9aa76c
[05409100][AndroidUiautomator2Driver@6981] Responding to client with driver.createSession() result: {"capabilities":{"platformName":"Android","automationName":"uiautomator2","platformVersion":"13","deviceName":"23e90ab3","appPac
kage":"com.ss.android.ugc.aweme","appActivity":"com.ss.android.ugc.aweme.splash.SplashActivity","noReset":true,"newCommandTimeout":14400,"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":tru
e,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","automationName":"uiautomator2","platformVersion":"13","deviceName":"2312DRA50C","appPack
age":"com.ss.android.ugc.aweme","appActivity":"com.ss.android.ugc.aweme.splash.SplashActivity","noReset":true,"newCommandTimeout":14400},"deviceUDID":"23e90ab3","pixelRatio":"3","statBarHeight":104,"viewportRect":{"left":0,"top":104,"width":1220,"height":2608},"deviceApiLevel":33,"deviceManufacturer":"Xiaomi","deviceModel":"2312DRA50C","deviceScreenSize":"1220x2712","deviceScreenDensity":480}}
[05409100][HTTP] <-- POST /session 200 5843 ms - 1041
[05409100][HTTP] --> POST /session/05409100-c072-4df2-90b5-51df5f9aa76c/timeouts {"implicit":20000}
[05409100][AndroidUiautomator2Driver@6981] Calling AppiumDriver.timeouts() with args: [null,null,null,null,20000,"05409100-c072-4df2-90b5-51df5f9aa76c"]
[05409100][AndroidUiautomator2Driver@6981] W3C timeout argument: {"implicit":20000}}
[05409100][AndroidUiautomator2Driver@6981] Set implicit wait to 20000ms
[05409100][AndroidUiautomator2Driver@6981] Responding to client with driver.timeouts() result: null
[05409100][HTTP] <-- POST /session/05409100-c072-4df2-90b5-51df5f9aa76c/timeouts 200 2 ms - 14
[05409100][HTTP] --> POST /session/05409100-c072-4df2-90b5-51df5f9aa76c/execute/sync {"script":"mobile: startActivity","args":[{"component":"com.ss.android.ugc.aweme/.splash.SplashActivity"}]}
[05409100][AndroidUiautomator2Driver@6981] Calling AppiumDriver.execute() with args: ["mobile: startActivity",[{"component":"com.ss.android.ugc.aweme/.splash.SplashActivity"}],"05409100-c072-4df2-90b5-51df5f9aa76c"]
[05409100][AndroidUiautomator2Driver@6981] Executing native command 'mobile: startActivity'
[05409100][ADB] Running 'C:\Space\environment\android-sdk-windows\platform-tools\adb.exe -P 5037 -s 23e90ab3 shell am start-activity -n com.ss.android.ugc.aweme/.splash.SplashActivity'
[05409100][AndroidUiautomator2Driver@6981] Responding to client with driver.execute() result: "Starting: Intent { cmp=com.ss.android.ugc.aweme/.splash.SplashActivity }"
[05409100][HTTP] <-- POST /session/05409100-c072-4df2-90b5-51df5f9aa76c/execute/sync 200 81 ms - 84

It seems that this requires setting the flags parameter?

KazuCocoa commented 2 months ago

Could you share your previous worked shell am start-activity command log? I checked the https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-startactivity again. Maybe the component is -n so your original one was correct. I guess you may need to give stop for example.

driver.execute_script "mobile:startActivity", {stop: true, wait: true, component: "com.ss.android.ugc.aweme/.splash.SplashActivity"}

What adb command was issued behind startActivity and give desired flags would be the alternative. Some might not be required for you usage.

xieyixing639 commented 2 months ago

Thanks for the reply, I have solved the issue.