现在的问题

(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异常的更多相关文章

  1. centos环境搭建

    1.php -v 与phpinfo();    不符,查看centos是否有自带的php:更改centos环境变量 /etc/profile,source /etc/profile生效: 2.pecl ...

  2. Unix/Linux环境C编程入门教程(2) CentOS环境搭建

    Unix/Linux版本众多,我们推荐Unix/Linux初学者选用几款典型的Unix/Linux操作系统进行学习. 本文就带大家来安装CentOS并且配置好C/C++开发环境,这是一款Linux. ...

  3. CentOS环境搭建(JDK安装、mysql安装、hadoop安装等)

    1.1准备权限:让普通用户具备sudo执行权限 切换到root用户,su # vi /etc/sudoers/ 添加  koushengrui    ALL=(ALL)       ALL 这里很容易 ...

  4. centos 环境搭建jenkins服务

    1.下载jenkins war包 https://jenkins.io/download/ 选择Generic Java package (.war)下载2.下载apache tomcat 8 htt ...

  5. .netcore centos环境搭建实战

    步骤 1. 安装VMware Workstation 下载地址:https://my.vmware.com/cn/web/vmware/info/slug/desktop_end_user_compu ...

  6. nodejs Centos环境搭建

    使用二进制文件安装: node 环境下载 https://nodejs.org/en/download/ 下载里面的windows 安装包 和 linux 安装包 1)windows安装 window ...

  7. 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 ...

  8. 如何在linux搭建airtest+chromeweb测试环境--(用命令行运行.air脚本)

    大前堤: 如果你需要airtest提供的可视化测试报告,那你的操作系统,一定要有图形化界面. 否则运行你的airtest脚本 会遇到这样的问题 Xlib.error.DisplayNameError: ...

  9. Ionic2开发环境搭建-VS 2017

    原文:Ionic2开发环境搭建-VS 2017 目前在VS 2017中创建Ionic2版本项目 注:在VS中开发Ionic项目,使用的Ionic(v2.x),Cordova(v6.3.1),Angul ...

随机推荐

  1. fastjson将java list转为json字符串

    1.直接用fastjson的静态方法string JSON.toJSONString(list)方法就行,JSON.toJSONString(list)将java list转为json字符串. 2.t ...

  2. Redhat 6.1安装ArcGIS Server10.1

    http://blog.csdn.net/linghe301/article/details/7762985 操作环境:Redhat 6.1 Linux 安装ArcGIS Server10.1之前,还 ...

  3. Swift版音乐播放器(简化版)

    这几天闲着也是闲着,学习一下Swift的.于是到开源社区Download了个OC版的音乐播放器,练练手,在这里发扬开源精神. 希望对大家有帮助! 这个DEMO里.使用到了 AudioPlayer(对音 ...

  4. 【打CF,学算法——二星级】CF 520B Two Buttons

    [CF简单介绍] 提交链接:Two Buttons 题面: B. Two Buttons time limit per test 2 seconds memory limit per test 256 ...

  5. map, string 强大的STL

    hdu 1247  Hat's Words Input Standard input consists of a number of lowercase words, one per line, in ...

  6. Redis总结(五)缓存雪崩和缓存穿透等问题 Web API系列(三)统一异常处理 C#总结(一)AutoResetEvent的使用介绍(用AutoResetEvent实现同步) C#总结(二)事件Event 介绍总结 C#总结(三)DataGridView增加全选列 Web API系列(二)接口安全和参数校验 RabbitMQ学习系列(六): RabbitMQ 高可用集群

    Redis总结(五)缓存雪崩和缓存穿透等问题   前面讲过一些redis 缓存的使用和数据持久化.感兴趣的朋友可以看看之前的文章,http://www.cnblogs.com/zhangweizhon ...

  7. VC 获取任务栏窗体的句柄

     本文将介绍一个未公开的Win32 API函数:GetTaskmanWindow.利用它对Windows的任务栏进行操作. 这个函数返回拥有任务栏button的窗体句柄. 在微软的MSDN文档中. ...

  8. cocos2d的armature绑定到其它armature骨骼上的bug

    在cocos2dx中,rmature的骨骼上能够绑定另外的armature,在我的项目中使用了该功能来完毕骑乘功能,可是在使用过程发现了例如以下的bug,特写在这里做一下记录. </span&g ...

  9. WCF问题集锦:ReadResponse failed: The server did not return a complete response for this request.

    今日.对代码进行单元測试时.发现方法GetAllSupplyTypes报例如以下错误: [Fiddler] ReadResponse() failed: The server did not retu ...

  10. 为何Google这类巨头会认为敏捷开发原则是废话?

    [编者按]这是一个来自Quora的问题.Rocket程序员Jasmine Adamson在文中表达了敏捷开发原则是废话的观点,他觉得现实生活中没有什么人会推崇这些原则来工作,不过他们仍然在说其所做的是 ...