Deployment environment (IX): install python + chrome + Xvfb under linux

In the UI test automation based on selenium conducted, development and debugging environment in general are the windows operating system. The need to deploy a dedicated test environment after completion.

If you want to be deployed to linux server environment (Ali cloud, Tencent cloud) execution, test scripts also need a corresponding browser support in order to be tested properly.

This blog describes how to install linux environment python, chrome, chromium, Xvfb commands and how to approach the next. . .

 

1, install python

linux system comes with python, but these are generally 2.6 or 2.7 version can be ordered by  -V view the current version number python python

If you are using python3.0 + version, you will need to upgrade to the corresponding local development python version, you can enter the following command to upgrade:

From the download link to download the installation package:  wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz 

Decompress packet:  the tar-3.6.2.tgz zxvf the Python 

Enter the command  cd Python-3.6.2, just unzip into the directory, and then execute the following three commands:

 ./configure (not every installation packages are required to execute this command, if it is a binary package you do not need this step)

 make 

 make install 

Explanation:

There is an executable script called configure in the unpacked folder, it is for the system to check whether the information needed to compile the library system, and the need to wait for the repository meets compiled using the  ./configure command carried out.

After the check, the compiler generates a file MakeFile. At this point, you can begin to compile, and use #make command to compile.

After successfully compiled, installed by #make install.

Installed, you should remove temporary files and configuration files generated during compilation produced. Type the following command:

 make clean  

 make distclean 

Then you can just download and unzip the package extract from the folder deleted. After a successful installation, you can enter  whereis python3 view the installation path

Enter python3, can enter the python command line, enter the print test, then that is pip command to install python libraries they need.

 

2, on chrome

Run linux environment UI automated test scripts, not chrome browser is not required, but do not need to display interface, but actually it is operated within the browser.

Use only its headless mode (chrome browser in the official version after version 59 added a headless mode, namely: no interface mode).

My linux version: Centos7.4: 64 Wei

PS: chrome is not supported by Linux 32-bit, does not support Centos, so if your server is Centos, it can only install Chromium (all google products, this is an open-source project).

Centos unfamiliar to shoes, can be found here: Configuration and Use Centos yum source

 

3, install chrome

/Etc/yum.repos.d/ file in the directory under the new google-chrome.repo, command is as follows:

 cd /ect/yum.repos.d/

 vim google-chrome.repo 

Add the following in the file:

1 [google-chrome]
2 name=google-chrome
3 baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
4 enabled=1
5 gpgcheck=1
6 gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

Then save and exit, enter the following command:

 yum -y install google-chrome-stable 

PS : Google official sources may not be available in China, the installation fails or can not be updated in the country, you can add the following parameters to install:

 yum -y install google-chrome-stable --nogpgcheck 

 

4, installation chromium

There are two methods for installing chromium, select own. . .

①, enter the command  cd /etc/yum.repos.d, yum into the source directory and enter the command  wget http://people.centos.org/hughesjr/chromium/6/chromium-el6.repo,

Download chromium installation package:

Enter the command  yum install chromium installation, process a little longer, be patient:

The middle will be prompted, confirm the downloaded installation package, enter "y" to wait for the installation is complete:

②, yum installation source, enter the command  sudo yum install -y epel-release  

安装Chromium: yum install -y chromium  

检查安装结果: ll /usr/bin/ | grep chrom 

 

5、安装chromedriver

浏览器安装成功后,要想运行脚本,浏览器驱动是必不可少的一个文件。

首先查看安装的chrome浏览器版本:输入命令 google-chrome -version 

然后在chromedriver下载网站,查看LATEST REALEASE文件,里面会介绍最新的版本

chromedricer下载链接:http://chromedriver.storage.googleapis.com/index.html

或者这个链接也可以:https://npm.taobao.org/mirrors/chromedriver

下载对应的版本,命令如下:

 wget http://chromedriver.storage.googleapis.com/index.html?path=2.38/chromedriver_linux64.zip 

然后解压缩,输入命令 unzip chromedriver_linux64.zip 

将下载的chromedriver移动当chrome浏览器目录下,输入命令 sudo mv chromedriver /usr/local/bin/chromedriver 

然后改变用户执行的权限,输入命令 sudo chmod u+x,o+x /usr/local/bin/chromedriver 

最后查看版本,确认是否可用?输入命令 chromedriver --version 

 

6、安装Xvfb

Xvfb是一个实现了X11显示服务协议的显示服务器。 不同于其他显示服务器,Xvfb在内存中执行所有的图形操作,不需要借助任何显示设备。

安装Xvfb的方法也有两种,请自行选择。。。

①、输入如下命令行安装:

cd /tmp

wget http://vault.centos.org/6.5/os/x86_64/Packages/xorg-x11-server-Xvfb-1.13.0-23.el6.centos.x86_64.rpm

yum install xorg-x11-server-Xvfb-1.13.0-23.el6.centos.x86_64.rpm 

解释:使用了“-extension RANDR -nolisten inet6”是因为Xvfb默认使用 ipv6,如果不添加就会报错。。。

出现如下界面,则表示安装成功:

②、输入如下命令行安装

yum install Xvfb -y

yum install xorg-x11-fonts* -y 

同样,安装完成后别忘记检查是否安装成功。。。

 

以上方法为linux系统Centos下的安装命令和方法,仅供参考。。。

 

在基于selenium进行的UI自动化测试中,开发调试环境一般都是windows操作系统。完成后需要部署到专门的测试环境。

如要要部署到linux环境的服务器(阿里云、腾讯云)执行,那么测试脚本也需要对应的浏览器支持, 才能正常进行测试。

這篇博客,介绍下如何在如何在linux环境安装python、chrome、chromium、Xvfb的命令和方法。。。

 

1、安装python

linux系统自带python,不过一般都是2.6或者2.7版本,可以通过命令 python -V 查看当前的python版本号

如果你用的python3.0+的版本,那么就需要升级为本地开发对应的python版本,可以输入下面的命令来升级:

从下载链接下载安装包: wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz 

解压缩包: tar zxvf Python-3.6.2.tgz 

输入命令 cd Python-3.6.2 ,进入刚刚解压的目录,然后执行下列3个命令:

 ./configure (不是每一个安装包都需要执行这个命令,如果是二进制包则不需要这一步)

 make 

 make install 

解释:

在解压出的文件夹中有一个名为configure的可执行脚本程序,它用于检查系统是否有编译时所需的库,以及库的版本是否满足编译的需要等系统信息,使用 ./configure 命令执行。

检查通过后,将生成用于编译的MakeFile文件。此时,可以开始进行编译了,使用#make命令编译。

成功编译后,通过#make install安装。

安装完毕,应清除编译过程中产生的临时文件和配置过程中产生的文件。键入如下命令:

 make clean  

 make distclean 

然后可以将刚刚下载的解压包和解压出来的文件夹删掉。安装成功后,可以输入 whereis python3 查看安装路径

输入python3,可以进入python命令行,输入print测试,然后就是pip命令安装自己需要的python库。

 

2、关于chrome

linux环境下运行UI自动化测试脚本,并不是不需要chrome浏览器,只是不需要显示界面,但实际它还是在浏览器内操作的。

利用的只是它的headless模式(chrome浏览器在59版本之后的正式版里加入了headless模式 ,即:无界面模式)。

我的linux版本:Centos7.4:64位

PS:chrome已不支持Linux 32位,也不支持Centos,所以如果你的服务器是Centos的话,只能安装Chromium(都是google的产品,这个是开源项目)。

对Centos不熟悉的童鞋,可以参考这里:Centos yum源的配置与使用

 

3、安装chrome

在目录/etc/yum.repos.d/下新建文件google-chrome.repo,命令如下:

 cd /ect/yum.repos.d/

 vim google-chrome.repo 

在该文件中添加如下内容:

1 [google-chrome]
2 name=google-chrome
3 baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
4 enabled=1
5 gpgcheck=1
6 gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

然后保存退出,输入如下命令:

 yum -y install google-chrome-stable 

PS: Google官方源可能在中国无法使用,导致安装失败或者在国内无法更新,可以添加以下参数来安装:

 yum -y install google-chrome-stable --nogpgcheck 

 

4、安装chromium

安装chromium的方法有两种,请自行选择。。。

①、输入命令 cd /etc/yum.repos.d ,进入yum源目录,然后输入命令 wget http://people.centos.org/hughesjr/chromium/6/chromium-el6.repo ,

下载chromium安装包:

输入命令 yum install chromium 进行安装,过程稍长,耐心等待:

中间会遇到提示,确认下载的安装包,输入"y"即可,等待安装完成:

②、安装yum源,输入命令 sudo yum install -y epel-release  

安装Chromium: yum install -y chromium  

检查安装结果: ll /usr/bin/ | grep chrom 

 

5、安装chromedriver

浏览器安装成功后,要想运行脚本,浏览器驱动是必不可少的一个文件。

首先查看安装的chrome浏览器版本:输入命令 google-chrome -version 

然后在chromedriver下载网站,查看LATEST REALEASE文件,里面会介绍最新的版本

chromedricer下载链接:http://chromedriver.storage.googleapis.com/index.html

或者这个链接也可以:https://npm.taobao.org/mirrors/chromedriver

下载对应的版本,命令如下:

 wget http://chromedriver.storage.googleapis.com/index.html?path=2.38/chromedriver_linux64.zip 

然后解压缩,输入命令 unzip chromedriver_linux64.zip 

将下载的chromedriver移动当chrome浏览器目录下,输入命令 sudo mv chromedriver /usr/local/bin/chromedriver 

然后改变用户执行的权限,输入命令 sudo chmod u+x,o+x /usr/local/bin/chromedriver 

最后查看版本,确认是否可用?输入命令 chromedriver --version 

 

6、安装Xvfb

Xvfb是一个实现了X11显示服务协议的显示服务器。 不同于其他显示服务器,Xvfb在内存中执行所有的图形操作,不需要借助任何显示设备。

安装Xvfb的方法也有两种,请自行选择。。。

①、输入如下命令行安装:

cd /tmp

wget http://vault.centos.org/6.5/os/x86_64/Packages/xorg-x11-server-Xvfb-1.13.0-23.el6.centos.x86_64.rpm

yum install xorg-x11-server-Xvfb-1.13.0-23.el6.centos.x86_64.rpm 

解释:使用了“-extension RANDR -nolisten inet6”是因为Xvfb默认使用 ipv6,如果不添加就会报错。。。

出现如下界面,则表示安装成功:

②、输入如下命令行安装

yum install Xvfb -y

yum install xorg-x11-fonts* -y 

同样,安装完成后别忘记检查是否安装成功。。。

 

以上方法为linux系统Centos下的安装命令和方法,仅供参考。。。

 

Guess you like

Origin www.cnblogs.com/zhengyao9236/p/11584076.html