Appium hangs when listing context in iOS
See original GitHub issueThe problem
Appium sporadically hangs when an appium client lists contexts, the application under test has WebViews and is in the background. That can happen when you have a test that combines application and Safari interactions.
Environment
- Appium version (or git revision) that exhibits the issue: 1.16.0 beta 1
- Node.js version (unless using Appium.app|exe): 12.12.0
- Npm or Yarn package manager: npm
- Mobile platform/version under test: iOS
- Real device or emulator/simulator: real
Details
I have debugged the problem and tracked the call flow:
- RemoteDebugger.searchForApp (appium-remote-debugger)
- for each app registered previously:
- RpcClient.selectApp (appium-remote-debugger)
- RpcClient.send(‘connectToApp’, …) (appium-remote-debugger)
- RpcClient.sendToDevice(‘connectToApp’, …) (appium-remote-debugger)
- RpcClientRealDevice.sendMessage(…) (appium-remote-debugger)
- WebInspectorService.sendMessage(…) (appium-ios-device)
The call to RpcClient.sendToDevice is blocked until WebInspectorService receives the response but that response never arrives. If I put the application in the foreground manually while Appium is blocked, the response from WebInspectorService arrives and Appium unblocks. You can see this behaviour in the logs:
- At the time 11:39:03:577 the Appium hangs after the ‘Sending message to Web Inspector:’ log.
- At 11:39:49:560, I sent the application to foreground in the iPhone (by hand) and Appium receives Web Inspector response (log ‘Received message from Web Inspector:’). If I don’t open the App,
getContext
request ends with a timeout and Appium hangs.
It seems that the component that is blocking the flow is the com.apple.webinspector
. I don’t know anything about Web Inspector protocol and if it is normal behaviour or it is a bug in the Apple component.
It could be related with https://github.com/appium/appium/issues/13361
Link to Appium logs
Appium logs: https://gist.github.com/anorimaki/bf3e57aa3dfe20e0e15aed32d28e7849
Code To Reproduce Issue
This kotlin client code can sporadically reproduce the problem (I ommit the creation of the driver). Hangs happens with the last driver.contextHandles
.
@Test
fun testIOSListContextAppInBackGroundSuspended() {
val nContext = driver.contextHandles
driver.runAppInBackground(Duration.ofSeconds(-1))
val state = driver.queryAppState( device.platform.applicationId )
assertEquals( ApplicationState.RUNNING_IN_BACKGROUND_SUSPENDED, state )
assertEquals( nContext, driver.contextHandles )
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I have published, in the latest Appium beta, the results of all of my experimentation. For my tests things are much better, hopefully for others as well.
appium-xcuitest-driver
should be at least v3.6.0appium-ios-device
should be at least v1.2.1appium-remote-debugger
should be at least v6.7.0I have solved my problems by patching some functions of remote-debugger.js (
appium-remote-debugger
).RemoteDebugger.searchForApp
function to skip applications that aren’t active. With this change Appium doesn’t hangs.RemoteDebugger.selectApp
doesn’t returns pages that belongs to applications that aren’t active.RemoteDebugger.searchForPage
skips applications that aren’t activeI have used current beta without the branch
appium-xcuitest-driver.git\#isaac-rd-try
. If I use this branch, Appium (with the above patch) can list context when app is in background, but fails to interact with the application WebView (in foreground). Sometimes it hangs when switching to WebView context and other times it hangs when searching for an element in the WebView.I think it isn’t a general solution because applications that are in background (suspended) have the same behaviuor as not running applications. In my case, it works because I always check pages that are in the foreground but I don’t know in Appium allowed to do thinks with background WebViews.