Robotframework common problem log does not display & garbled

1. After the operation of RobotFramework is interrupted or repeated, it often appears that the control panel does not display log information in ride?
Reason analysis: It may be that the encoding does not support Chinese.
Solution: Go to your local python installation directory and modify "C:\Python27\lib\site-packages\robotide\contrib\testrunner\testrunner.py" in the file method "return result.decode(" 'UTF-8')" is changed to "return result.decode('gbk','ignore')".

PS: If it has not been resolved, add Close Browser to the Suite Teardown field of the test suite containing the execution case

2. When Robot Framework is running, log shows Chinese garbled characters?
Such as: \u3e4d2\u77hhjj
Reason analysis: The garbled characters displayed are actually in Unicode encoding format, which is not a bug, but a display problem.
Solution:
(1) Find the unic.py file in the robotframework installation directory. My directory is /Library/ Python/2.7/site-packages/robotframework-3.0.4-py2.7.egg/robot/utils/unic.py, insert the following code in the unic.py file:

import json
if isinstance(item,(list,dict,tuple)):
	try:
		item = json.dumps(item,ensure_ascii=False,encoding='utf-8')
	except UnicodeError:
		try:
      		 item = json.dumps(item, ensure_ascii=False, encoding='utf-8')
   		except:
       		pass
	except:
           pass

As shown in the figure below
Insert picture description here
(2), then restart the ride editor and run the script to see if the Log Chinese display is normal
2.1 If the display is not normal, check the Python default encoding method
a. cmd open the terminal
b. enter python
c. enter import sys
d. enter sys.getdefaultencoding()
Insert picture description here

Check if the default encoding method of python is utf8, not change it to utf8, the steps are as follows:
Create a new sitecustomize.py file under the Lib and site-packages binder of Python, the content is:
#coding=utf8
import sys
reload(sys )
sys.defaultencoding('utf8')
restart the Python editor, enter the 2.1 command to confirm whether the encoding is set to utf8

Guess you like

Origin blog.csdn.net/weixin_42166361/article/details/104789890