playwright: [BUG] Unable to download file on grid
Context:
- Playwright Version: 1.23.0
- Operating System: Mac
- Node.js version: v12.22.3
- Browser: Chromium
- Extra: Selenium Grid 4.3.0
Bug Description
We have testcases to test the download functionality from the application. We have used promise to wait for the download to verify if the file is getting downloaded.
When we run testcase locally it works fine. However when we try to run testcase on selenium grid its failing with following error:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Browser/playwright.py", line 149, in grpc_channel yield playwright_pb2_grpc.PlaywrightStub(self._channel) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Browser/keywords/promises.py", line 143, in _wait_for_download response = stub.WaitForDownload(Request().FilePath(path=str(file_path))) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/grpc/_channel.py", line 946, in __call__ return _end_unary_response_blocking(state, call, False, None) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.RESOURCE_EXHAUSTED details = "Error: download.saveAs: canceled" debug_error_string = "{"created":"@1658769026.465787000","description":"Error received from peer ipv6:[::1]:54106","file":"src/core/lib/surface/call.cc","file_line":967,"grpc_message":"Error: download.saveAs: canceled","grpc_statu... [ Message content over the limit has been removed. ] return promises[0].result() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 428, in result return self.__get_result() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result raise self._exception File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Browser/keywords/promises.py", line 143, in _wait_for_download response = stub.WaitForDownload(Request().FilePath(path=str(file_path))) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__ self.gen.throw(type, value, traceback) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Browser/playwright.py", line 153, in grpc_channel raise AssertionError(error.details()) AssertionError: Error: download.saveAs: canceled
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 7
- Comments: 22 (1 by maintainers)
Yeah, facing similar issues. Tried to play around and it looks like something gets messed up after PW connection.
Tried to directly create a grid session - the results are the same.
Thanks a ton for the idea @jwroberts . I was able to get initial success by your idea. Early code I have aded on my repo is very very raw . It needs some polishing. It’s not production ready but can be a reference if someone wants to improve it. Please share the code if you already have better version with you. I have added a sample code at my github repo. https://github.com/amardeep2006/selenium-grid-experiments/blob/main/playwright/tests
I will keep adding examples there as I polish this functionality. PS : File upload was positive anticlimax and worked out of box with Playwright.
@amardeep2006 While this is out of scope for playwright and not exactly what you are looking for I have had luck intercepting downloads while using playwright and a remote chromium browser (not selenium grid).
If you grab a CDP session you can use the Fetch domain to intercept the download and read it to your local playwright client. I don’t have the code readily handy but in case it helps anyway the gist of the approach is:
Use CDP Fetch.enable to setup request interception for your download.
On the Fetch.requestPaused event for your download you can issue a Fetch.takeResponseBodyAsStream to get a virtual handle to the download stream and
use IO.read CDP method to read it a chunk at a time down to your playwright client.
It’s not ideal but is the best I’ve been able to do with this problem. YMMV with Selenium grid.