python-client icon indicating copy to clipboard operation
python-client copied to clipboard

Not printing web view context through "print(driver.context)" command

Open SantJen opened this issue 2 years ago • 13 comments

The problem

Not printing context through "print(driver.context)" statement

Environment

Package Version


Appium-Python-Client 2.1.4 async-generator 1.10 attrs 22.1.0 certifi 2022.9.24 cffi 1.15.1 charset-normalizer 2.0.12 cryptography 38.0.1 cx-Oracle 8.3.0 cycler 0.11.0 fonttools 4.37.3 h11 0.14.0 idna 3.4 kiwisolver 1.4.4 matplotlib 3.5.3 natsort 8.3.0 numpy 1.21.6 outcome 1.2.0 packaging 21.3 Pillow 9.2.0 pip 21.3.1 pycparser 2.21 pyOpenSSL 22.1.0 pyparsing 3.0.9 PySocks 1.7.1 python-dateutil 2.8.2 PyYAML 6.0 requests 2.26.0 robotframework 4.1.2 robotframework-pabot 2.13.0 robotframework-stacktrace 0.4.1 selenium 4.0.0 setuptools 60.2.0 six 1.16.0 sniffio 1.3.0 sortedcontainers 2.4.0 trio 0.21.0 trio-websocket 0.9.2 typing_extensions 4.3.0 urllib3 1.26.12 urllib3-secure-extra 0.1.0 wheel 0.37.1 wsproto 1.2.0 Python 3.11

Details

Link to Appium Logs

Code To reproduce issue

def web_view_loc(driver, locator, value): webview_context = None print(driver.contexts) time.sleep(180)

SantJen avatar Dec 11 '23 13:12 SantJen

Please attache the appium server log as well

KazuCocoa avatar Dec 12 '23 02:12 KazuCocoa

i am checking same with bs team,once get update i will share same

SantJen avatar Dec 12 '23 13:12 SantJen

Appium logs.txt Pls find the appium log attached here. Thanks

SantJen avatar Dec 14 '23 05:12 SantJen

For below one?

2023-12-01 08:54:03:370 - [debug] [XCUITestDriver@97d6 (de487725)] [XCUITestDriver@97d6 (de487725)] No web frames found.
2023-12-01 08:54:03:370 - [debug] [XCUITestDriver@97d6 (de487725)] [XCUITestDriver@97d6 (de487725)] Responding to client with driver.getContexts() result: ["NATIVE_APP"]
2023-12-01 08:54:03:375 - [HTTP] [HTTP] <-- GET /wd/hub/session/de487725-3108-4ac9-a0fc-35adaf21ad7b/contexts 200 156 ms - 24
2023-12-01 08:55:39:670 - [debug] [RemoteDebugger] [RemoteDebugger] Selected app after 13ms
2023-12-01 08:55:39:671 - [debug] [XCUITestDriver@97d6 (de487725)] [XCUITestDriver@97d6 (de487725)] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_2487.7"]
2023-12-01 08:55:39:671 - [HTTP] [HTTP] <-- GET /wd/hub/session/de487725-3108-4ac9-a0fc-35adaf21ad7b/contexts 200 15 ms - 41

In the XCUITest driver, appium gets these info via WebInspecor on the host machine. It could take a few seconds to get full contexts. So retrying a couple of times, of using https://appium.github.io/appium-xcuitest-driver/5.12/execute-methods/#mobile-getcontexts to get the context with waitForWebviewMs might help.

Or setting appium:webviewConnectTimeout in the capability also might help. https://appium.github.io/appium-xcuitest-driver/5.12/capabilities/

KazuCocoa avatar Dec 14 '23 07:12 KazuCocoa

image Hi, can you tell me how to use "waitForWebviewMs" ,not getting from above info, Thanks

SantJen avatar Jan 02 '24 12:01 SantJen

As the example below in the already attached documentation https://appium.github.io/appium-xcuitest-driver/5.12/execute-methods/, you could send it as driver.execute_script{'mobile: getContexts', {'waitForWebviewMs': 1000}}

# Python
result = driver.execute_script('mobile: <methodName>', {
    'arg1': 'value1',
    'arg2': 'value2',
})

KazuCocoa avatar Jan 02 '24 17:01 KazuCocoa

Hi, I used following code "print(driver.execute_script('mobile: getContexts', {'waitForWebviewMs': 1000}))" showing out put like bleow "[{'id': 'NATIVE_APP'}]" Pls have a look for same. Thanks

SantJen avatar Jan 03 '24 06:01 SantJen

It indicates no webview found in 1000ms. Some cases it could need more longer time to wait (this is not controllable area by Appium). If it keeps showing no webview, it perhaps indicate no webview info available via WebInspector

KazuCocoa avatar Jan 03 '24 06:01 KazuCocoa

but web view there, if i check manually, pls suggest how to get web view through script

SantJen avatar Jan 03 '24 07:01 SantJen

even I configured 5000ms , same issue like webview context not showing through script

SantJen avatar Jan 03 '24 08:01 SantJen

web view there

Do you mean the web view was WebInspector inspectable and could be found by the host OS's Web inspector? I'm not sure what communication occurred between Appium and macOS's Web Inspector (which appium gets WebView related data from), but basically the result depends on how macOS's Web Inspector respond to Appium.

https://appium.github.io/appium-xcuitest-driver/5.12/setup/ https://github.com/appium/appium-xcuitest-driver/blob/d2175c14304e88c6caee46d7e3f0793f03953abe/lib/commands/context.js#L187

The full appium log related to the request may help to see what occurred.

KazuCocoa avatar Jan 03 '24 08:01 KazuCocoa

Downloads.zip Hi, Please find both logs attached here. Thanks

SantJen avatar Jan 05 '24 14:01 SantJen

Did the webview accessible via WebInspector? https://appium.github.io/appium-xcuitest-driver/5.14/setup/ https://appium.github.io/appium-xcuitest-driver/5.14/device-preparation/

It looks like the script execution and manual setup log used different devices. Please compare the same environment to reduce diffs on the device level. I guess the script execution hasn't configured Web Inspector.

KazuCocoa avatar Jan 14 '24 08:01 KazuCocoa