Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with downloadsPath variable #3286

Closed
alpip1997 opened this issue Nov 28, 2023 · 21 comments
Closed

Issues with downloadsPath variable #3286

alpip1997 opened this issue Nov 28, 2023 · 21 comments
Assignees
Labels
bug Something isn't working priority: high
Milestone

Comments

@alpip1997
Copy link

Describe the bug
It seems that when I try to solve a download promise (set with promise_to_wait_for_download, and resolve with wait_for(promise)) I get a TypeError because of the variable downloadsPath. This error doesn't happen if I use the version of Robotframework_broser 17.5.2 just with the new version 18.0.0. And also the system must be Linux, in Windows I didn't have the issue.

Expected behavior
The expected behaviu¡our is to solve the promise without any error

@aaltat
Copy link
Member

aaltat commented Nov 28, 2023

I don’t quite see what causes the problem. Would it be possible for you to create an example which also we can run?

@alpip1997
Copy link
Author

Hello, I cannot give you a version that runs as our code because it is a company website.
I can give you the lines of code that we use to download. Basically we select the filename, create the promise of downloading and click de button for download it. I dont know if this can be useful.
`filename = name
if name == "":
test_case_name = self.get_test_case_name()
self.stdoutDownloaded += 1
filename = test_case_name.lower()
filename= filename.replace(' ', '')
filename = f"{filename}
{self.stdoutDownloaded}.stdout"

    folderPath=self.getEvidenceFolder(self.cmpMode)
    time.sleep(2)
    download_promise = self.playwright.promise_to_wait_for_download(f"{folderPath}/{filename}")
    time.sleep(2)
    self.do_click(xp.download_button)
    self.playwright.wait_for(download_promise)`

I also want to say that the installation was perform in a computer without internet connection (the website is accesible because the server is set inside a private network). So for the installation I have to donwload de whl files from pypi, manually install the node packages (for the steps rfbrowser init) and give the correct permissions. But this method was perform in the same way for installing the version 17.5 and it works fine, it is just the version 18 and its dependencies which give me this error.

Thanks you for your help.

@aaltat
Copy link
Member

aaltat commented Nov 29, 2023

Can you also send the full stack trace from the error?

@aaltat aaltat added bug Something isn't working priority: high labels Nov 29, 2023
@aaltat
Copy link
Member

aaltat commented Nov 29, 2023

@allcontributors please add @alpip1997 for bugs

Copy link
Contributor

@aaltat

I've put up a pull request to add @alpip1997! 🎉

@alpip1997
Copy link
Author

Hello, sorry for the delay. We have been having issues with our machines. Recently I reinstaled the version 18 and I got the same error. For the error, the trace that I got in the debug file is:

================= Original suppressed error ================= TypeError: Cannot read properties of undefined (reading 'downloadsPath') at _waitForDownload (/usr/local/lib/python3.10/site-packages/Browser/wrapper/index.js:8835:63) at runNextTicks (node:internal/process/task_queues:60:5) at process.processImmediate (node:internal/timers:442:9) at async waitForDownload (/usr/local/lib/python3.10/site-packages/Browser/wrapper/index.js:8831:10) at async PlaywrightServer.waitForDownload (/usr/local/lib/python3.10/site-packages/Browser/wrapper/index.js:10648:28) =============================================================

@aaltat
Copy link
Member

aaltat commented Dec 1, 2023

Can you also show stack trace from Python side too?

@alpip1997
Copy link
Author

I execute it from robotframework interface (using the command robot -t "TestName" File.robot). The only message that I receive is:
TypeError: Cannot read properties of undefined (reading 'downloadsPath')
I dont see any other error messages in html files or output.xml

@aaltat
Copy link
Member

aaltat commented Dec 1, 2023

Can you add —loglevel trace in the command?

@alpip1997
Copy link
Author

alpip1997 commented Dec 1, 2023

Ok, thanks for the information. Here is the information from the trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/Browser/playwright.py", line 165, in grpc_channel
    yield playwright_pb2_grpc.PlaywrightStub(self._channel)
  File "/usr/local/lib/python3.10/site-packages/Browser/keywords/promises.py", line 214, in _wait_for_download
    response = stub.WaitForDownload(
  File "/usr/local/lib64/python3.10/site-packages/grpc/_channel.py", line 1161, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib64/python3.10/site-packages/grpc/_channel.py", line 1004, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.RESOURCE_EXHAUSTED
	details = "TypeError: Cannot read properties of undefined (reading 'downloadsPath')"
	debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2023-12-01T10:12:44.361890498+00:00", grpc_status:8, grpc_message:"TypeError: Cannot read properties of undefined (reading \'downloadsPath\')"}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/fdfcore/ci_test/03-Tools/robotFocus/functions/_Program.py", line 122, in download_stdout
    self.playwright.wait_for(download_promise)
  File "/usr/local/lib/python3.10/site-packages/Browser/keywords/promises.py", line 247, in wait_for
    return promises[0].result()
  File "/usr/lib64/python3.10/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib64/python3.10/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/usr/lib64/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/Browser/keywords/promises.py", line 203, in _wait_for_download
    with self.playwright.grpc_channel() as stub:
  File "/usr/lib64/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/Browser/playwright.py", line 169, in grpc_channel
    raise AssertionError(error.details())
AssertionError: TypeError: Cannot read properties of undefined (reading 'downloadsPath')`

@lasselindqvist
Copy link
Contributor

I have this as well and the usage is something like:

    ${dl_promise}        Promise To Wait For Download    ${file}    
    # Keyword that returns xpath
    ${address}    Get download address
    Click       ${address}

    ${file_obj}=           Wait For  ${dl_promise}
    File Should Exist    ${file_obj}[saveAs]

file parameter is something like ${CURDIR}/../test_file.txt

Browser is initialized with
New Browser ${BROWSER} headless=False
so no parameter for download path has been given.

I'll see if it works with downloadsPath=${OUTPUT DIR} or similar, but would be nice to work out-of-box of course.

@lasselindqvist
Copy link
Contributor

Defining the downloadsPath variable made no difference for me with this, so currently I am not aware of any workaround for this.

@lasselindqvist
Copy link
Contributor

18.2.0 seemed to have something related to this (3754c50) but when testing with it, still got
TypeError: Cannot read property 'downloadsPath' of undefined

lasselindqvist added a commit to lasselindqvist/robotframework-browser that referenced this issue Oct 4, 2024
Snooz82 added a commit that referenced this issue Oct 6, 2024
…3819)

Co-authored-by: René <41592183+Snooz82@users.noreply.github.com>
@Snooz82
Copy link
Member

Snooz82 commented Oct 6, 2024

@lasselindqvist i can still not reproduce.

Can you please give us a complete test case incl. import how to reproduce that?

@Snooz82 Snooz82 self-assigned this Oct 6, 2024
@Snooz82 Snooz82 added this to the v18.9.0 milestone Oct 6, 2024
@Snooz82
Copy link
Member

Snooz82 commented Oct 7, 2024

I would close that issue to have it in Release Notes.
I am still not sure how a browser can have undefined options, so please help reproducing, but the actual exception should be gone now.

@Snooz82 Snooz82 closed this as completed Oct 7, 2024
@lasselindqvist
Copy link
Contributor

@Snooz82 I think it is the browser that is undefined, but it is called with "?." so it makes it seem like it is options that are undefined.

@Snooz82
Copy link
Member

Snooz82 commented Oct 7, 2024

state.activeBrowser.browser?._options.downloadsPath

@lasselindqvist No. If the browser is undefined the whole expression is not evaluated further, _options is not called and undefined is returned.
If it is not undefined the next function/attribute is called, which is _options which then is undefined therefore the error:

TypeError: Cannot read property 'downloadsPath' of undefined

@lasselindqvist
Copy link
Contributor

True. It short-circuits.

It might be

public async getOrCreateActiveContext(defaultTimeout: number | undefined): Promise<IIndexedContext> {
that calls _newBrowserContext without passing anything for _options.

So could it be a situation where we have a browser, no context and for some reason try to make a new browser. I'll have to check if I can figure out how this state would become to existence.

@alpip1997
Copy link
Author

Hello, recently I updated to the version 18.5.1 and it seems it works fine now. I am referring to the original issue

@aaltat
Copy link
Member

aaltat commented Oct 8, 2024

Have you tried the latest release?

@lasselindqvist
Copy link
Contributor

I tested with 18.9.0 and it seems to work now. I didn't yet test if giving download path in options works or not, as we do not do that and just give filenames directly, but in any case solves the crash at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: high
Projects
None yet
Development

No branches or pull requests

4 participants