在centOS环境搭建airtest时遇到 Xlib.error.DisplayNameError: Bad display name "" 和Xlib.error.XauthError异常
现在的问题
(airtestVenv) [root@67 airtest_selenium]# python3 proxy.py
Traceback (most recent call last):
File "proxy.py", line 10, in <module>
from airtest_selenium.utils.airtest_api import loop_find
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/airtest_selenium/__init__.py", line 1, in <module>
from .proxy import WebChrome, Element
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/airtest_selenium/proxy.py", line 13, in <module>
from pynput.mouse import Controller, Button
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/pynput/__init__.py", line 40, in <module>
from . import keyboard
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/pynput/keyboard/__init__.py", line 49, in <module>
from ._xorg import KeyCode, Key, Controller, Listener
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/pynput/keyboard/_xorg.py", line 39, in <module>
from pynput._util.xorg import (
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/pynput/_util/xorg.py", line 40, in <module>
_check()
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/pynput/_util/xorg.py", line 38, in _check
display = Xlib.display.Display()
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/Xlib/protocol/display.py", line 84, in __init__
name, protocol, host, displayno, screenno = connect.get_display(display)
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/Xlib/support/connect.py", line 73, in get_display
return mod.get_display(display)
File "/root/.virtualenvs/airtestVenv/lib/python3.6/site-packages/Xlib/support/unix_connect.py", line 76, in get_display
raise error.DisplayNameError(display)
Xlib.error.DisplayNameError: Bad display name ""
我以为是我改的proxy.py脚本在centos系统中运行有问题,早上来了直接python3 proxy.py (未修改的脚本)也是报这个错,说明不是我改的问题,而是环境有问题
无意中在虚拟环境中看到了xlib这个文件夹,反应过来,这是一个包
查了一下xlib是干什么的
https://cloud.tencent.com/developer/ask/202120


非常椿的博客!
https://www.cnblogs.com/js1314/p/10373332.html
xhost + 是什么
(airtestVenv) [root@67 demoAir.air]# xhost +
xhost: unable to open display ""
(airtestVenv) [root@67 demoAir.air]# xdpyinfo
xdpyinfo: unable to open display "".
(airtestVenv) [root@67 demoAir.air]# xhost +
xhost: unable to open display ""
(airtestVenv) [root@67 demoAir.air]# export DISPLAY=:0
(airtestVenv) [root@67 demoAir.air]# xhost +
access control disabled, clients can connect from any host
错误变了

把错误信息扒下来,发现问题的源在airtest_selenium包下的proxy.py这个文件,圈红的这一行
既然运行这行代码会报错(我有单独放一个PY文件来验证想法,只放这一句代码,在本地跑不错,在centOS中跑就会出来上图一模一样的错误 )
那我注销掉是不是就不会报错了呢,注销会有什么影响吗?先来试试的

oh no 结果是不能在公司的centOS服务器中运行airtest QAQ
为什么呢(因为公司的centOS服务器没有操作界面呀 )
因为 在proxy.py文件中有一行这样的代码
from pynput.mouse import Controller, Button
这行代码是用来干什么的呢
不知道哦
那我们先来看看注销掉这行代码会有什么效果
注销掉相关代码后再运行demoAir.py
运行脚本并生成log文件
wangju@wangju-HP-348-G4:~/Airtest/demoAir.air$ airtest run demoAir.py --log log/
生成log.html文件
wangju@wangju-HP-348-G4:~/Airtest$ airtest report demoAir.air --log_root demoAir.air/log/ --outfile demoAir.air/log/log.html --
lang zh
打开日志文件夹,咦,奇怪,没有截图呢
再来看一看 不注释这行代码生成的日志文件内容 是啥样的

再来打开log.html文件看一看
是酱婶儿的

由此我们可以知道 pynput是和屏幕操作相关的,记录鼠标呀,键盘呀这些设备的操作
而如果我们把这样的代码注释掉,脚本是可以跑通的,因为我们可以配置浏览器的 --headleses 属性 使脚本 无界面 运行.
决策点就是,是否需要这份可视化的报告,
需要:给服务器安装图形化界面 或 直接放到有图形化界面的系统中去运行
这也说明了为啥程序在我本地能跑通(ubuntu)
而放到centOS中去跑的时候就会报错,因为我ubuntu有操作界面啊
在centOS环境搭建airtest时遇到 Xlib.error.DisplayNameError: Bad display name "" 和Xlib.error.XauthError异常的更多相关文章
- centos环境搭建
1.php -v 与phpinfo(); 不符,查看centos是否有自带的php:更改centos环境变量 /etc/profile,source /etc/profile生效: 2.pecl ...
- Unix/Linux环境C编程入门教程(2) CentOS环境搭建
Unix/Linux版本众多,我们推荐Unix/Linux初学者选用几款典型的Unix/Linux操作系统进行学习. 本文就带大家来安装CentOS并且配置好C/C++开发环境,这是一款Linux. ...
- CentOS环境搭建(JDK安装、mysql安装、hadoop安装等)
1.1准备权限:让普通用户具备sudo执行权限 切换到root用户,su # vi /etc/sudoers/ 添加 koushengrui ALL=(ALL) ALL 这里很容易 ...
- centos 环境搭建jenkins服务
1.下载jenkins war包 https://jenkins.io/download/ 选择Generic Java package (.war)下载2.下载apache tomcat 8 htt ...
- .netcore centos环境搭建实战
步骤 1. 安装VMware Workstation 下载地址:https://my.vmware.com/cn/web/vmware/info/slug/desktop_end_user_compu ...
- nodejs Centos环境搭建
使用二进制文件安装: node 环境下载 https://nodejs.org/en/download/ 下载里面的windows 安装包 和 linux 安装包 1)windows安装 window ...
- Kafka:ZK+Kafka+Spark Streaming集群环境搭建(二十六)Structured Streaming:WARN clients.NetworkClient: Error while fetching metadata with correlation id 1 : {my-topic=LEADER_NOT_AVAILABLE}
问题描述: 我之前使用kafka的命令删除了改topic: ./kafka-topics.sh --delete --zookeeper [zookeeper server] --topic [to ...
- 如何在linux搭建airtest+chromeweb测试环境--(用命令行运行.air脚本)
大前堤: 如果你需要airtest提供的可视化测试报告,那你的操作系统,一定要有图形化界面. 否则运行你的airtest脚本 会遇到这样的问题 Xlib.error.DisplayNameError: ...
- Ionic2开发环境搭建-VS 2017
原文:Ionic2开发环境搭建-VS 2017 目前在VS 2017中创建Ionic2版本项目 注:在VS中开发Ionic项目,使用的Ionic(v2.x),Cordova(v6.3.1),Angul ...
随机推荐
- jq页面提示或者页面牵引浏览--页面的指引向导插件
1.看看插件效果吧 2. html 文件 :index.html <!DOCTYPE html> <html lang="en"> <head> ...
- delphi不同版本字符串类型的演化
string,DELPHI2009以前的版本string=ansistring,一个字符占一个字节,DELPHI2009及以上版本string=unicodestring,一个字符占二个字节. cha ...
- gradle: 修改gradle-xx-bin.zip下载地址
进入gradle/wrapper/目录,修改gradle-wrapper.properties文件, 将distributionUrl修改为自己的下载地址即可. 另外修改gradle reposito ...
- priority_queue实现
#include <algorithm> using namespace std; /* priority_queue只允许在底端加入元素,并从顶端取出元素, 其内部元素不是依照被推入的次 ...
- 1.5 - 动态路由协议ISIS
IS-IS 特征: 1:协议操作起来,比OSPF要简单 2:扩展性比OSPF要好,易于扩展 3:对IPv6有很好的支持 4:能够同时支持IP网络,和CLNS网络(OSI网络)(集成的IS-IS) 5: ...
- UIView加入手势 然后UITableView 加入进这个View 导致UITableView 的单元格点击事件无效
#import "ViewController.h" @interface ViewController ()<UITableViewDataSource,UITableVi ...
- POJ 2485 Highways && HDU1102(20/200)
题目链接:Highways 没看题,看了输入输出.就有种似曾相识的感觉,果然和HDU1102 题相似度99%,可是也遇到一坑 cin输入居然TLE,cin的缓存不至于这么狠吧,题目非常水.矩阵已经告诉 ...
- BZOJ 3007 解救小云公主 二分答案+对偶图
题目大意:给定一个矩形和矩形内的一些点.求一条左下角到右上角的路径.使全部点到这条路径的最小距离最大 最小距离最大.果断二分答案 如今问题转化成了给定矩形中的一些圆形障碍物求左下角和右上角是否连通 然 ...
- Ubuntu中取消秘钥环
1.打开应用程序->附件->password和加密密钥(或者在终端中输入 seahorse) 2.切换到password选项卡,会看到一个password密钥环 3.右击->更改pa ...
- LeetCode 7. Reverse Integer (倒转数字)
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...