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

Listener errors in console: selenium.webdriver.chrome.webdriver.WebDriver is not JSON serializable #32

Closed
alexandrul opened this issue Aug 18, 2016 · 15 comments
Assignees
Labels

Comments

@alexandrul
Copy link

Using the Add Location Strategy keyword leads to multiple errors in both console and message logs.
Similar issue encountered in RIDE, which is using a similar TestRunnerAgent.py: https://github.com/robotframework/Selenium2Library/issues/542

Console errors:

[ ERROR ] Calling method 'start_keyword' of listener '...\TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.chrome.webdriver.WebDriver (session="...")> is not JSON serializable
[ ERROR ] Calling method 'end_keyword' of listener '...\TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.chrome.webdriver.WebDriver (session="...")> is not JSON serializable

Message log traceback:

20160818 14:40:06.115 : INFO : Traceback (most recent call last):
  File "...\TestRunnerAgent.py", line 441, in _send_socket
    self.streamhandler.dump(packet)
  File "...\TestRunnerAgent.py", line 671, in dump
    s = self._json_encoder(obj)
  File "...\Python27\lib\json\encoder.py", line 209, in encode
    chunks = list(chunks)
  File "...\Python27\lib\json\encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "...\Python27\lib\json\encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "...\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "...\Python27\lib\json\encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "...\Python27\lib\json\encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "...\Python27\lib\json\encoder.py", line 442, in _iterencode
    o = _default(o)
  File "...\Python27\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <selenium.webdriver.chrome.webdriver.WebDriver (session="605922e7d1ae544229972fdbcd5f74ac")> is not JSON serializable
@alexandrul
Copy link
Author

Of course, monkey-patching can be used to avoid this, but the issue may occur in the future for other corner cases.

@adam-wypych
Copy link
Contributor

Few questions about software version, which You are using :)

  1. RED version?
  2. Robot Framework?
  3. Interpreter is python, jython or ironpython and in which version?
  4. selenium library?

@alexandrul
Copy link
Author

RED - Robot Editor version 0.6.5 0.6.5.201607071059
Eclipse Platform 4.6.0.I20160606-1100
robotframework 3.0.1.dev20151231
Python 2.7.12
selenium 2.53.6

@alexandrul
Copy link
Author

However, the issue is in TestRunnerAgent.py, that's why I have skipped the environment details.

My workaround was to use http://stackoverflow.com/questions/18478287/making-object-json-serializable-with-regular-encoder to make selenium.webdriver.chrome.webdriver.WebDriver JSON serializable.

@adam-wypych
Copy link
Contributor

adam-wypych commented Aug 18, 2016

We just think about modify a little bit attrs dictionary send to RED listener to send empty args list inside for start_keyword and end_keyword. As far as I've been tested it works with example provide by You.

The reason is that we do not depends on args when keyword is starting and correction is just one line attrs['args'] = [] before self._send_socket("start_keyword", name, attrs) and self._send_socket("end_keyword", name, attrs)

The correction will be available in new upcome release.

Information about listener API: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id760

@adam-wypych adam-wypych self-assigned this Aug 18, 2016
@alexandrul
Copy link
Author

Thank you for the pointers, it works just fine on my pc.

@adam-wypych
Copy link
Contributor

Just for update, I checked it deeply and this issue is mainly connected to wrapping a call

BuiltIn().run_keyword(self, name, args*)

inside keyword call by user, where args contains complex object as one of parameter. I. e. I made library (KeywordLibrary.py) like this:

class User(object):
    def __init__(self, name, password):
        self.name = name
        self.password = password

kepler = User('A. Kepler', 'secret')

from robot.libraries.BuiltIn import BuiltIn

class KeywordLibrary:
    def keyword(self, name):
        pass

    def call_keyword(self):
        return BuiltIn().run_keyword("keyword", {"name": kepler})

the corresponding test case is very simple:

*** Settings ***
Library    KeywordLibrary.py

*** Test Cases ***
T1
    Call Keyword

The issue is also reproduce even Selenium is not used.

@kootstra
Copy link

kootstra commented Aug 29, 2016

I have encountered the same issue, and the suggested C:\Python27\lib\site-packages\robotide\contrib\testrunner\TestRunnerAgent.py alteration has the desired effect for RIDE, but sadly doesn't work with RED.

It seems to me that RED actually creates the TestRunnerAgent.py file from a different source as it refers to a temp file: C:\Users[user]\AppData\Local\Temp\RobotTempDir2655008392341869025\TestRunnerAgent.py. Does anyone know where to locate the original file?

When altering this temporary version, the errors do disappear, so when I have access to the original file it could be permanent. Otherwise after every RED application restart I have to do this again.

@alexandrul
Copy link
Author

alexandrul commented Aug 29, 2016 via email

@kootstra
Copy link

Thanks. That should help. Will let you know tomorrow if that works for me.

@michalanglart
Copy link
Collaborator

@kootstra RED does not use the agent provided with RIDE. We provide our own version of it (modified version of what RIDE uses) which is located in the jar mentioned by @alexandrul. Upcoming RED release will of course provide the fix in agent code (we expect to release new version within 1-2 weeks).

@kootstra
Copy link

@michalanglart from the logs I already understood that the file is generated from one of the classes and does not use the one in Python directory.

After updating the TestRunnerAgent.py file in the org.robotframework.ide.core-functions-0.0.1-SNAPSHOT.jar class the errors dissapear. However, the debug functionality also no longer works. So, I guess that is one step forward, and two steps back.

@adam-wypych
Copy link
Contributor

adam-wypych commented Aug 30, 2016

@kootstra
Copy link

@adam-wypych Thanks. That indeed works. Looking forward to the new release.

@KrzysztofJozefowicz
Copy link
Contributor

released in 0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants