MarketSquare / robotframework-browser

Robot Framework Browser library powered by Playwright.
Apache License 2.0
530 stars 106 forks source link

Wait for response keyword fails when it get a list #3912

Closed ecare-joost closed 1 day ago

ecare-joost commented 5 days ago

Describe the bug After I updated to version 19.0.0 the Wait for response keyword fails when it get a list back in the response. This did not happen in version 18.9.1

To Reproduce Link to slack conversation https://robotframework.slack.com/archives/C015KB1QSDN/p1732620419276269

Stacktrace:

Traceback (most recent call last):
  File "C:\Python 3.9.10\lib\site-packages\Browser\playwright.py", line 170, in grpc_channel
    yield playwright_pb2_grpc.PlaywrightStub(self._channel)
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\network.py", line 140, in _wait_for_http_response
    return _format_response(response_json)
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\network.py", line 35, in _format_response
    _jsonize_content(response, "body")
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\network.py", line 54, in _jsonize_content
    data[bodykey] = json.loads(data[bodykey])
  File "C:\Python 3.9.10\lib\json\__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python 3.9.10\lib\site-packages\Browser\browser.py", line 1241, in run_keyword
    raise e
  File "C:\Python 3.9.10\lib\site-packages\Browser\browser.py", line 1230, in run_keyword
    return DynamicCore.run_keyword(self, name, args, kwargs)
  File "C:\Python 3.9.10\lib\site-packages\robotlibcore.py", line 173, in run_keyword
    return self.keywords[name](*args, **(kwargs or {}))
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\promises.py", line 265, in wait_for_all_promises
    self.wait_for(*self.unresolved_promises)
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\promises.py", line 250, in wait_for
    return [promise.result() for promise in promises]
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\promises.py", line 250, in <listcomp>
    return [promise.result() for promise in promises]
  File "C:\Python 3.9.10\lib\concurrent\futures\_base.py", line 439, in result
    return self.__get_result()
  File "C:\Python 3.9.10\lib\concurrent\futures\_base.py", line 391, in __get_result
    raise self._exception
  File "C:\Python 3.9.10\lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\network.py", line 247, in wait_for_response
    response = self._wait_for_http_response(matcher, timeout)
  File "C:\Python 3.9.10\lib\site-packages\Browser\keywords\network.py", line 140, in _wait_for_http_response
    return _format_response(response_json)
  File "C:\Python 3.9.10\lib\contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Python 3.9.10\lib\site-packages\Browser\playwright.py", line 177, in grpc_channel
    raise AssertionError(str(error))
AssertionError: the JSON object must be str, bytes or bytearray, not list

Expected behavior Wait for response keyword can handle lists.

aaltat commented 5 days ago

If the previous version, can you tell how you response body looks like? Is it list, dictionary or something else? Or is a string which might look like list or dictionary?

Also if possible could you run with 19.0 and add new line before this line this line: https://github.com/MarketSquare/robotframework-browser/blob/main/Browser/keywords/network.py#L35 and add logger.info(response). Then send the relevant line from log.

aaltat commented 5 days ago

I think I found the bug, at least I can reproduce the problem with unit tests.

aaltat commented 5 days ago

@allcontributors please add @ecare-joost for bugs

allcontributors[bot] commented 5 days ago

@aaltat

I've put up a pull request to add @ecare-joost! :tada:

tomppa65 commented 3 days ago

Unfortunately, this fix, speedy as it was, is incomplete. Enabling Wait For Response to handle a list is good and necessary but I have lots of responses where the body is a single boolean value. True or False. Please enhance this fix to be able to deal with a boolean, too! Or do you need a new issue for this?

aaltat commented 3 days ago

This one is fine

aaltat commented 1 day ago

Is fixed as part of #3922