MarketSquare / robotframework-browser

Robot Framework Browser library powered by Playwright.
Apache License 2.0
513 stars 104 forks source link

Grpc issue [TypeError: Cannot convert object to primitive value] #2829

Closed Mezohren closed 1 year ago

Mezohren commented 1 year ago

When running the Get classes keyword I am getting the following error

TypeError: Cannot convert object to primitive value

This is what my code looks like. Browser.Get Classes li:has([id="tabbeddata:${TabItem}Label"])

On this dom element (where leefsituatie = ${TabItem}) image

This is the full stack trace I'm getting

15:27:03.225    DEBUG   Traceback (most recent call last):
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\playwright.py", line 149, in grpc_channel
    yield playwright_pb2_grpc.PlaywrightStub(self._channel)
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\keywords\getters.py", line 266, in get_property
    response = stub.GetDomProperty(
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\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 = "TypeError: Cannot convert object to primitive value"
    debug_error_string = "UNKNOWN:Error received from peer ipv4:127.0.0.1:55375 {grpc_message:"TypeError: Cannot convert object to primitive value", grpc_status:8, created_time:"2023-05-25T13:27:02.842786343+00:00"}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\browser.py", line 1099, in run_keyword
    raise e
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\browser.py", line 1088, in run_keyword
    return DynamicCore.run_keyword(self, name, args, kwargs)
  File "C:\Users\mezohren\AppData\Roaming\Python\Python310\site-packages\robotlibcore.py", line 105, in run_keyword
    return self.keywords[name](*args, **(kwargs or {}))
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\assertion_engine.py", line 63, in with_assertion_polling
    raise e
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\assertion_engine.py", line 56, in with_assertion_polling
    return wrapped(*args, **kwargs)
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\keywords\getters.py", line 433, in get_classes
    class_dict = self.get_property(selector, "classList")
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\assertion_engine.py", line 63, in with_assertion_polling
    raise e
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\assertion_engine.py", line 56, in with_assertion_polling
    return wrapped(*args, **kwargs)
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\keywords\getters.py", line 265, in get_property
    with self.playwright.grpc_channel() as stub:
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\mezohren\AppData\Local\Programs\Python\Python310\lib\site-packages\Browser\playwright.py", line 153, in grpc_channel
    raise AssertionError(error.details())
AssertionError: TypeError: Cannot convert object to primitive value

Using the following versions:

aaltat commented 1 year ago

@allcontributors please add @Mezohren for bugs

allcontributors[bot] commented 1 year ago

@aaltat

I've put up a pull request to add @Mezohren! :tada:

aaltat commented 1 year ago

I tried to reproduce the error but could not make it happen. I created this

    <ul class="align">
        <li class="detail-tab1 other-1">
            <a herf="#tab1">
                <span id="prefix:other1">other1</span>
            </a>
        </li>
        <li class="detail-tab3 other-3">
            <a herf="#tab3">
                <span id="prefix:other3">other3</span>
            </a>
        </li>
        <li class="detail-tab2 other-2">
            <a herf="#tab2">
                <span id="prefix:other2">other2</span>
            </a>
        </li>
    </ul>

On static html file. Then I used this in test: Get Classes li:has([id="prefix:other3"]) but the keyword does not fail. Also tried with assertion operator, but does not fail in that case either. Get Classes li:has([id="prefix:other3"]) == detail-tab3 other-3

I guess there is something else triggering the error. Would you have more details to share, are you using assertion operator, or something else which might be relevant? Can you enable enable_playwright_debug from library import and show us the the relevant parts from the debug logs. My, successful case looks like:

{"level":30,"time":"2023-05-30T18:59:42.870Z","pid":63038,"hostname":"Tatu","msg":"Start of node method getDomProperty"}
{"level":30,"time":"2023-05-30T18:59:42.870Z","pid":63038,"hostname":"Tatu","msg":"Strict mode is enabled, find Locator with li:has([id=\"prefix:other3\"]) in page."}
2023-05-30T18:59:42.870Z pw:api => locator.elementHandle started
2023-05-30T18:59:42.870Z pw:api waiting for locator('li:has([id="prefix:other3"])')
2023-05-30T18:59:42.871Z pw:api   "domcontentloaded" event fired
2023-05-30T18:59:42.877Z pw:api   locator resolved to visible <li class="detail-tab3 other-3">…</li>
2023-05-30T18:59:42.879Z pw:api <= locator.elementHandle succeeded
2023-05-30T18:59:42.879Z pw:api => elementHandle.getProperty started
2023-05-30T18:59:42.882Z pw:api <= elementHandle.getProperty succeeded
2023-05-30T18:59:42.883Z pw:api => jsHandle.jsonValue started
2023-05-30T18:59:42.883Z pw:api <= jsHandle.jsonValue succeeded
{"level":30,"time":"2023-05-30T18:59:42.883Z","pid":63038,"hostname":"Tatu","msg":"Retrieved dom property for element li:has([id=\"prefix:other3\"]) containing [object Object]"}
{"level":30,"time":"2023-05-30T18:59:42.883Z","pid":63038,"hostname":"Tatu","msg":"End of node method getDomProperty"}

Yours can look different, but start of the logging should be similar, but selector is unique for you.

Mezohren commented 1 year ago

Hi,

the 'enable_playwirhgt_debug" argument is deprecated. And when I use it my browser keywords are note recognized debugLib

debugLib

aaltat commented 1 year ago

The enable_playwright_debug is not deprecated, it is not anymore positional argument. I have no idea why you IDE stops working, but that is separate issue. Just add the argument in the import and run the test.

Snooz82 commented 1 year ago

@Mezohren

can you give us any reproducible sequence?

otherwise i would close this issue.

aaltat commented 1 year ago

Closing, if you r problem persist, please comment and we will consider reopening the issue.