If your session is crashing or your test is failing because a WEBVIEW is missing then try these debugging steps.
# Summary
We'll use the Appium API to do two things:
1. find ALL contexts including the NATIVE_APP default context
2. check if the target context is available
# Get all contexts
Consult the Appium API for your language: https://appium.io/docs/en/commands/context/get-contexts/
Insert the driver.contexts method and log the results somewhere.
This should return an array of strings that contain a minimum of one Context, the NATIVE_APP context.
If your WEBVIEW is absent you should consider filing a bug with the Developers responsible for the app. The WEBVIEWs may be absent for legitimate reasons.
# Loop through all contexts seeking a target
Here we'll loop over a context looking for our target WEBVIEW. The exact syntax must match.
# Java Example seeking a specific context by name
for (String contextName : contextNames) {
// 10 or 15s wait may be needed here. Sometimes
//the WEBVIEWs take time to appear
if (contextName.contains("WEBVIEW")){
((AppiumDriver) driver).context(contextName);
}
}