有没有办法在GitHub动作上模拟基本硬件(鼠标,显示)的存在?
我目前正在从事一个python项目,该项目依赖于 pyautogui 控制鼠标。在将任何新更改推向GitHub之前,我设置了一系列测试,以便在我的计算机上运行,但是我也想在GitHub操作上设置一个工作流程,以按下构建和测试我的应用程序。
但是,正如您可以想象的那样,我的问题是在GitHub操作上进行测试的环境没有屏幕和鼠标。我的脚本只需要访问屏幕分辨率(width,height = pyautogui.size()
)并执行简单的操作( eg pyautogui.click('左')
,pyautogui.scroll(...)
)。我的测试实际上并不需要任何窗口弹出窗口才能在它们上执行操作,只是为了能够运行这些简单的功能。
目前,问题似乎是缺乏显示:
[...]
import pyautogui
File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/os.py", line 681, in __getitem__
raise KeyError(key) from None
KeyError: 'DISPLAY'
因为display
环境变量不存在(或者也许等于:0
由于缺乏显示) 。我不确定鼠标是否是一个问题,因为它不会超出显示步骤,但我希望它也会有问题。
有人知道一种模拟屏幕和鼠标在GitHub Actions Runner上的存在的方法吗?还是有解决方法?
I'm currently working on a Python project that relies on PyAutoGUI to take control of the mouse. I set up an ensemble of tests to run on my machine before pushing any new change to GitHub, but I would also like to set up a workflow on GitHub Actions to build and test my application on push.
But, as you can imagine, my problem is that the environment in which the tests are run on GitHub Actions has no screen nor mouse. My scripts only need to access the screen resolution (width, height = pyautogui.size()
) and to perform simple actions (e.g. pyautogui.click('left')
, pyautogui.scroll(...)
). My tests don't actually require any window to pop-up to perform actions on them, just to be able to run these simple functions.
Currently, it seems that the issue is the lack of display:
[...]
import pyautogui
File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/os.py", line 681, in __getitem__
raise KeyError(key) from None
KeyError: 'DISPLAY'
as the DISPLAY
environment variable does not exist (or perhaps is equal to :0
due to the lack of display). I am not sure that the mouse is an issue yet, since it does not go beyond the display step, but I expect it to be problematic as well.
Does anyone know a way to simulate the presence of a screen and mouse on a GitHub Actions runner? Or any workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过多次尝试,我终于设法使它起作用。我对X服务器一无所知,所以这几乎像是一个奇迹。
对于有兴趣的人来说,它只是归结为使用 python安装和运行
xvfb
。这是我工作流程的关键部分:Python只需要在与
xvfb-run
的同一命令上运行,仅此而已。这将设置display
适当的变量,并求解依赖于此的Pyautogui导入。然后,来自Pyautogui的鼠标相关操作执行,没有任何问题,鼠标是否没有。感谢您让我走上正确的曲目。
干杯。
After many attempts, I finally managed to get it working. I don't know anything about X servers, so it pretty much feels like a miracle.
To anyone interested, it simply comes down to installing and running
xvfb
with Python. Here's the critical part of my workflow:Python simply needs to be run on the same command as
xvfb-run
, and that's it. This sets theDISPLAY
variable appropriately and solves the PyAutoGUI import that relies on it. Then, the mouse-related actions from PyAutoGUI execute without any problem, mouse or not.Thanks for putting me on the right tracks.
Cheers.
谢谢救生@Johoward !!!为我提供了一些添加的功能:
我的完整的github动作.yml:
thanks life-saver @JoHoward!!! worked for me with some additions:
my full github action .yml: