getContexts
The WebdriverIO getContexts
method is an improved version of the default Appium contexts
(and the previous WebdriverIO getContexts
) command. It provides detailed and actionable information
about available contexts in a mobile app session, addressing the limitations of the default Appium methods.
How Webviews Work and Why This Method Helps
For more details, refer to the Hybrid Apps documentation. Below is a summary of the challenges addressed by the getContexts
command:
Android Challenges
- A single webview (e.g.,
WEBVIEW_{packageName}
) may contain multiple pages (similar to browser tabs). - The default Appium methods do not include details about these pages, such as their
title
,url
, or visibility, making it hard to identify the correct page and leading to potential flakiness.
iOS Challenges
- The default Appium method only returns generic webview IDs (e.g.,
WEBVIEW_{id}
) without any additional metadata. - This makes it difficult to determine which webview corresponds to the target app screen.
The enhanced getContexts
method solves these issues by returning detailed context objects, which include:
- For Android:
title
,url
,packageName
,webviewPageId
, and layout details (screenX
,screenY
,width
, andheight
). - For iOS:
bundleId
,title
, andurl
.
These enhancements make debugging and interacting with hybrid apps more reliable.