gpt4 book ai didi

python - 为什么在 selenium 测试中使用 'easyprocess' 时会得到 'pyvirtualdisplay' 输出?

转载 作者:太空宇宙 更新时间:2023-11-03 14:29:23 24 4
gpt4 key购买 nike

我正在尝试在 selenium 测试中使用 pyvirtualdisplay 来创建屏幕截图。以下是我在 TestSuite python 类中的测试中执行此操作的方法:

self.display = Display(visible=0, size=(1366, 768))
self.display.start()

在创建驱动程序之前,并截取我使用的屏幕截图

self.driver.save_screenshot('example.png')

但是,当使用 nosetests 运行测试时,我得到一些奇怪的输出,如下所示:

easyprocess: DEBUG: version=0.2.3
pyvirtualdisplay: DEBUG: version=0.2.1
easyprocess: DEBUG: param: "['Xvfb', '-help']"
easyprocess: DEBUG: command: ['Xvfb', '-help']
easyprocess: DEBUG: joined command: Xvfb -help
easyprocess: DEBUG: process was started (pid=21)
easyprocess: DEBUG: process has ended
easyprocess: DEBUG: return code=0
easyprocess: DEBUG: stdout=
easyprocess: DEBUG: stderr=use: X [:<display>] [option]
-a # default pointer acceleration (factor)
-ac disable access control restrictions
-audit int set audit trail level
-auth file select authorization file
-br create root window with black background
+bs enable any backing store support
-bs disable any backing store support
-c turns off key-click
c # key-click volume (0-100)
-cc int default color visual class
-nocursor disable the cursor
-core generate core dump on fatal error
-displayfd fd file descriptor to write display number to when ready to connect
-dpi int screen resolution in dots per inch
-dpms disables VESA DPMS monitor control
-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs
-f # bell base (0-100)
-fc string cursor font
-fn string default font name
...

这个输出是什么?为什么我会得到它以及如何“避免”它?

最佳答案

此输出的原因:在 pyvirtualdisplay 包中,xauth.py 文件中包含以下代码,用于检查 easyprocess 是否已安装。

def is_installed():
'''
Return whether or not xauth is installed.
'''
try:
easyprocess.EasyProcess(['xauth', '-h']).check_installed()
except easyprocess.EasyProcessCheckInstalledError:
return False
else:
return True

这里 -h 由包中的 debug 使用,它显示 easyprocess 的帮助选项,并且在输出中显示相同的选项。因此,您的代码不会出现问题。

调试记录器中存在帮助。因此,如果您想抑制这种情况,只需在代码中使用以下行将记录器设置为 INFO 级别即可。

logging.getLogger("easyprocess").setLevel(logging.INFO)

在初始化显示之前放置上面的代码(如下所述):

logging.getLogger("easyprocess").setLevel(logging.INFO)

self.display = Display(visible=0, size=(1366, 768))

self.display.start()

希望能解决您的问题!

关于python - 为什么在 selenium 测试中使用 'easyprocess' 时会得到 'pyvirtualdisplay' 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47411156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com