我正在尝试使用 pyautogui 和 pyvirtualdisplay 进行 UI 测试。
import os
import pyautogui
import Xlib.display
from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay
import cv2
import sys
python = sys.executable
window_width = 1200
window_height = 800
# PyVirtualDisplay
display = SmartDisplay(visible=False, size=(window_width, window_height))
display.start()
# PyAutoGUI
pyautogui._pyautogui_x11._display = Xlib.display.Display(os.environ['DISPLAY'])
# Do your thing
pyautogui_window_width, pyautogui_window_height = pyautogui.size()
print("Screen size: {}x{}".format(pyautogui_window_width, pyautogui_window_height))
p = EasyProcess([python, 'script.py'])
p.start()
p.sleep(1)
x, y = pyautogui.locateCenterOnScreen(image='g.png', confidence=0.9)
print(x, y)
pyautogui.moveTo(x, y)
pyautogui.click()
p.stop()
display.stop()
print('>>> All done.')
运行此代码时,我收到此错误,
raise error.XauthError('~/.Xauthority: %s' % err)
Xlib.error.XauthError: ~/.Xauthority: [Errno 2] No such file or directory: '/home/gitlab-runner/.Xauthority'
如何在远程服务器中测试带有或最好不带显示的 UI。
帖子很旧了..但无论如何我都会回答。
我刚刚成功地使用 X-Server 部署了 Tkinter GUI
我花了好长时间...
长话短说:
只需在存储库中为主机和客户端创建一个 .Xauthority 目录即可。
详细说明:
你可以看看这里的 Dockerfile:
https://github.com/DorinBe/PySurfs/tree/dockerize
对于主持人:
您不会在存储库中看到 .Xauthority 目录,因为它包含在 .gitignore 中,而只需创建一个名为 .Xauthority 的目录。
对于客户:
我用了'touch CMD /bin/bash -c“touch /root/.Xauthority && python main.py”'
为了调试,我在 Dockerfile 中使用了一些“ls -la”命令。
示例:
CMD /bin/bash -c "ls -la"
请注意,使用 CMD 命令后,Dockerfile 中的其他所有内容都会被忽略。
为了增强调试,您可以跳过requierments.txt文件的安装。它帮助我打印一些“pwd”和“ls -la”命令来了解路径以及操作(如创建目录)是否真的按照我的假设发生,或者存在问题并且这些功能被跳过(有时,有问题,这就是我禁用容器控制台交互性的原因)。
头部之前: 注意 Dockerfile 中所需的安装,并禁用在安装过程中要求用户输入的选项(Dockerfile 中提到了所有内容,只需阅读它,您就会找到如何操作)
它与 git-lab 没有直接关联,但我确信它们是完全相同的。
我很乐意回答更多问题:) 祝你好运!