Skip to content
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

The keyword "Switch Application" #82

Closed
BabauHo opened this issue Dec 17, 2015 · 13 comments
Closed

The keyword "Switch Application" #82

BabauHo opened this issue Dec 17, 2015 · 13 comments

Comments

@BabauHo
Copy link

BabauHo commented Dec 17, 2015

Hi
I use the keyword "Switch Application" and follow the example:

${appium1}= Open Application http://localhost:4723/wd/hub alias=MyApp1 platformName=Android platformVersion=6.0 deviceName='' app=C:/XXXX/app1.apk
${appium2}= Open Application http://localhost:4725/wd/hub alias=MyApp2 platformName=Android platformVersion=6.0 deviceName='' app=C:/XXXX/app2.apk
Capture Page Screenshot Checkit0.jpg
Switch Application ${appium1}
Capture Page Screenshot Checkit1.jpg
Sleep 3s

After execute "Switch Application" and execute "Capture Page Screenshot".

The log return
" Keyword 'Capture Page Screenshot' could not be run on failure: KeyError: 'error' "

What's wrong with my usage?

I'll appreciate any help!

Thanks!

@jollychang
Copy link
Collaborator

Could you provide some appium server log?

@BabauHo
Copy link
Author

BabauHo commented Dec 19, 2015

Hi, @jollychang

Is this server log helpful?

info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"5.0.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"5.0","deviceName":"Sony","platformName":"Android","appActivity":"com.trendmicro.vpn.demo.activity.MWCDemoYamatoActivity","appPackage":"com.trendmicro.vpn.dryamatotest"},"deviceName":"CB5A1YWFWE","platformName":"Android","appActivity":"com.trendmicro.vpn.demo.activity.MWCDemoYamatoActivity","appPackage":"com.trendmicro.vpn.dryamatotest"},"sessionId":"2c433d5f-9afe-4389-bb32-45b22b8f9219"}
info: <-- GET /wd/hub/session/2c433d5f-9afe-4389-bb32-45b22b8f9219 200 3.627 ms - 685 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"5.0.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"5.0","deviceName":"Sony","platformName":"Android","appActivity":"com.trendmicro.vpn.demo.activity.MWCDemoYamatoActivity","appPackage":"com.trendmicro.vpn.dryamatotest"},"deviceName":"CB5A1YWFWE","platformName":"Android","appActivity":"com.trendmicro.vpn.demo.activity.MWCDemoYamatoActivity","appPackage":"com.trendmicro.vpn.dryamatotest"},"sessionId":"2c433d5f-9afe-4389-bb32-45b22b8f9219"}
info: [debug] UiAutomator exited
info: [debug] executing cmd: "C:\Program Files\Android\android-sdk\platform-tools\adb.exe" -s CB5A1YWFWE shell "echo 'ping'"
info: [debug] Attempting to uninstall app
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: --> GET /wd/hub/session/2c433d5f-9afe-4389-bb32-45b22b8f9219/screenshot {}
info: <-- GET /wd/hub/session/2c433d5f-9afe-4389-bb32-45b22b8f9219/screenshot 404 1.200 ms - 40
info: --> GET /wd/hub/session/2c433d5f-9afe-4389-bb32-45b22b8f9219/screenshot {}
info: <-- GET /wd/hub/session/2c433d5f-9afe-4389-bb32-45b22b8f9219/screenshot 404 1.121 ms - 40

@serhatbolsu
Copy link
Owner

@BabauHo does this problem still exist?

@semutmerah
Copy link
Contributor

semutmerah commented Sep 1, 2016

Hi,

Currently, I am having a problem with "Switch Application" keyword too, but I don't know if it is the same problem or not.

My code is same as the example, but it looks like the app isn't really switched, it just stay on the second app, but then the test is marked as PASS.

My env:
appium 1.5.3
robotframework 3.0.0
robotframework-appiumlibrary 1.3.7

I am using a device with android 5.1.1

server log (from first app):

[HTTP] <-- POST /wd/hub/session/ca06f4ee-79a3-40d9-8b3e-04f0d9116293/elements 200 3932 ms - 89 
[UiAutomator] UiAutomator exited unexpectedly with code 0, signal null
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was 'UiAUtomator shut down unexpectedly'
[Appium] Removing session ca06f4ee-79a3-40d9-8b3e-04f0d9116293 from our master session list
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","am","force-stop","com.google.android.youtube"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","am","force-stop","io.appium.unlock"]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","input","keyevent",3]
[debug] [Logcat] Stopping logcat capture
[AndroidBootstrap] Cannot shut down Android bootstrap; it has already shut down

server log (from second app):

[HTTP] <-- POST /wd/hub/session/7e80e6a8-87e5-4253-8463-3d0dc7a2c112/elements 200 112 ms - 89 
[HTTP] --> DELETE /wd/hub/session/7e80e6a8-87e5-4253-8463-3d0dc7a2c112 {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: ["7e80e6a8-87e5-4253-8463-3...
[debug] [AndroidDriver] Shutting down Android driver
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","am","force-stop","com.bbm"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","am","force-stop","io.appium.unlock"]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","input","keyevent",3]
[debug] [Logcat] Stopping logcat capture
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /home/woi/android-sdk-linux/platform-tools/adb with args: ["-P",5037,"-s","AG840422AE286GC","shell","ps","uiautomator"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'
[Appium] Removing session 7e80e6a8-87e5-4253-8463-3d0dc7a2c112 from our master session list
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning

@yahman72
Copy link
Contributor

yahman72 commented Nov 3, 2016

Looks like that both of your apps are running on the same device, this is not supported.

I think that KW is a bit misleading (the name and the documentation), it's not really switching between applications but actually switching between appium sessions.
If you have both sessions pointing to the same device, the switching doesn't really do anything on the device itself, after the switch you just talk to the device using different appium server.
I could also imagine that this will cause problems with appium itself because those 2 appium servers try to talk to the same appium bootstrap on the device...

In short: the Apps must run on different devices.

  • Supported: Device-A running App-1 and Device-B running App-2
  • Supported: Device-A running App-1 and Device-B running App-1
  • Not Supported: Device-A running App-1 and Device-A running App-2

For Example: you could test WhatsApp message sending from one device to another device.

However it would be a cool feature to switch between applications on the same device. This should be possible using appium but would need a completely different implementation approach where the switching just brings the started app to the foreground.

@BabauHo
Copy link
Author

BabauHo commented Nov 4, 2016

Hi yahman72,

Got it.
Thanks for your response.

Best regards,
BaBau Ho

@BabauHo BabauHo closed this as completed Nov 4, 2016
@jerem0808
Copy link

jerem0808 commented Jan 3, 2018

Hi everyone,
I am using also Switch Application for a OTP message to connect to a wifi network. I am using only one Android device and my setup is as follow:

  1. go to the website enter the mobile number OK
  2. go to the SMS app (with Start Activity) and read the OTP OK
  3. Switch Application ${chrome} OK but chrome is not displayed (SMS app is still on front) but the OTP worked because i am connected to wifi. I also tried to hardcode a dummy OTP and the wifi didn't connect.
  4. go to any website to check if i have internet working OK.
    So from what @yahman72 said it shouldn't work. Why Switch Application works but doesn't show the chrome and does everything in background ? Is it possible to display the application with Switch Application ?
    Thank you

@yahman72
Copy link
Contributor

yahman72 commented Jan 3, 2018

No, it's not possible to switch the application as mentioned "Switch Application" should actually be called "Switch Session" because it just switches between appium sessions, not between applications = it just automates the application that's on front.

You could try to bring the other app to front by using "start activity"

@jerem0808
Copy link

Thank you for your answer. Ok I see but i'm not sure to understand why it does work then ?

@yahman72
Copy link
Contributor

yahman72 commented Jan 3, 2018

what do you mean by "it works"?

@jerem0808
Copy link

jerem0808 commented Jan 3, 2018

i mean that i was able to launch chrome with switch application and to enter the correct password in the corresponding field. I know it has worked because the mobile was connected to the wifi.
the splash page sends a password by SMS and then i am able to enter this password back to Chrome with Switch Application. But this process is "hidden" I don't see the password being entered because Chrome is not displayed
EDIT:
The problem with Start Activity is that i need to switch the context back to webview (namely: Switch To Context CHROMIUM) but this doesn't work and generates an error
ChromeDriver is not associated with a window
and then it resets chrome

@yahman72
Copy link
Contributor

yahman72 commented Jan 3, 2018

oh? - I don't think it should work at all, but appium behaves a bit oddly with the "start activity".
Maybe the chrome still has somehow the focus...

Did you try also without the "switch application"? in this case it does nothing (i.e. it should also work without it).

If you really want to see the chrome then do it like this

  1. go to the website enter the mobile number
  2. go to the SMS app (with Start Activity) and read the OTP
  3. send BACK keyevents until you see chrome again

@jerem0808
Copy link

You're absolutely right it works also without Switch application.
Thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants